Functions and procedures can be declared either globally, so they are usable throughout a design description, or they can be declared locally within the declarative region of an architecture, block, process, or even within another subprogram. If you are writing a subprogram that will be used throughout your design, you will write the subprogram declaration in an external package, as shown in the following example:

 

package my_package is

    function my_global_function(...)

        return bit;

end my_package;

 

package body my_package is

    function my_global_function(...)

        return bit is

    begin

        . . .

    end my_global_function;

end my_package;

. . .

use work.my_package.my_global_function;

entity my_design is

begin

    . . .

end my_design;

 

In this example, the function my_global_function() has been declared within the package my_package. The actual body of the function—the sequence of statements that define its operation—is placed into a package body. (The reasons why a subprogram requires a package body in addition to a package are somewhat obscure, but they have to do with the fact that the statements in a subprogram must be executed when the design description is simulated, while other declarations appearing in a package can be completely resolved at the time the VHDL description is first analyzed by the VHDL compiler.) To use the global function in subsequent architectures (such as the architecture associated with entity my_design in this example), a use statement (and library statement, if the package has been compiled into a named library) must precede the declaration for that architecture or its parent entity.

 

See also

image\diamond.gif  Declaring a Local Subprogram