The generic clause looks much like a port clause except that generics represent constants instead of dynamic signals. These constants are powerful because they can be given a different value every time the entity is used in a component instantiation.
Let's look at an example of a generic clause. The following declaration might be used for modeling an adder:
entity generic_adder is
generic (width : natural;
delay : time:=0ns);
port (d1,d2 : in bit_vector (width-1 downto 0);
sum : in bit_vector (width-1 downto 0));
end generic_adder;
This example also illustrates three new types of objects. They are natural, time, and bit_vector. An object of the natural type may take on a value between 0 and 2147483647. The time type is used to specify time values that are written with a number followed by any of the standard abbreviations fs,ps,ns,us,ms, and sec. The :=0ns following the type name is called a default value. If the value is not specified when the entity is used for an instantiation then the default value is assumed. Since width does not have a default value, it must be given one when the design is used. Finally, the ports of this entity declaration use the bit_vector type. This is a one dimensional array of the bit type used in the last section. The (width-1 downto 0) part following the type name specifies the range of the array. The fact that we have used a constant generic has allowed us to delay supplying the actual range until we use the part, so that we can use it for more than one purpose. The range contains the downto keyword because the range is descending. The first bit in the vector is bit width-1 and the last bit is bit 0.
The following is a formal specification of how the port clause and generic clause may appear:
name-list : simple-name { "," simple-name }
mode : IN | INOUT | OUT
interface-signal :
[SIGNAL] name-list ":" [mode] subtype [BUS] [":=" expression]
port-clause :
PORT "(" interface-signal {";" interface-signal} ")" ";"
interface-constant :
[CONSTANT] name-list ":" [IN] subtype [":=" expression]
generic-clause :
GENERIC "(" interface-constant {";" interface-constant} ")" ";"
The entity declaration follows the rule:
entity-item_declarations : subprogram-declaration |
subprogram-prototype | type-declaration | subtype-declaration |
constant-declaration | signal-declaration | file-declaration |
alias-declaration | attribute-declaration | use-clause |
attribute-specificiation | disconnection-specification
entity-statements : concurrent-assertion-statement |
concurrent-procedure-call | process-statement
entity-declaration :
ENTITY simple-name IS
[generic-clause]
[port-clause]
{entity-item-declarations}
[BEGIN entity-statements]
END [simple-name] ";"