Another way of using subprograms is to declare them locally, such as within an architecture or block declaration. In the following example, my_local_function() has been declared entirely within the architecture my_architecture.

 

architecture my_architecture of my_design is

begin

    my_process: process(...)

        function my_local_function(...)

            return bit is

        begin

            . . .

        end my_local_function;

    begin

        . . .

    end process my_process;

end my_architecture;

 

This example demonstrates the concept of local scoping. VHDL objects (such as signals, variables and constants) can be declared at many points in a design, and that the visibility, or scoping, of those objects depends on where they have been declared. Subprograms (functions and procedures) also have scoping. In this example, the function my_local_function can only be referenced within the architecture in which it has been declared and defined.

 

Consistent scoping of objects and subprograms is an important part of modular VHDL coding and of structured programming in general. If you will only be using an object or subprogram in one section of your overall design, then you should keep the declaration of that object or subprogram local to that section of the design. This will make it possible to re-use that section of the design elsewhere with a minimum of fuss (since you won’t have to remember to declare the object or subprogram globally in the new design).

 

See also

image\diamond.gif  Declaring a Global Subprogram