generation-scheme : FOR parameter-specification |
IF condition
generate-statement :
[ label ":" ] generation-scheme GENERATE
concurrent-statement-list
END GENERATE [ label ] ";"
If the FOR scheme is used, the generate is much like a loop. Once for every value in the specified range, the specified constant name is set to that value and the concurrent statement list is compiled. This is very useful for generic designs. The following is a good example of how this might be used.
entity adder is
generic (width : natural);
port (a,b : in bit_vector (width-1 downto 0);
s : out bit_vector (width-1 downto 0);
carry : out bit);
end adder;
architecture structure of adder is
component fa
port (x1,x2,c_in : in bit;
out,c_out : out bit);
end component;
for all:fa use entity full_adder(rtl)
port map (x1,x2,c_in,out,c_out);
signal c : bit_vector (width downto 0);
begin
c(0)<='0';
bits: for n in 0 to width-1 generate
bit_n: fa
port map (a(n),b(n),c(n),s(n),c(n+1));
end generate;
carry<=c(width);
end structure;