# VHDL nested generate statements: how to refer to label?

I have this code that attaches a label to components instantiated inside a for...generate statement. So far everything works fine:

outer: for index in 17 downto 0 generate
attribute RLOC of EX_do1: label is "X0Y" & integer'image(index / 4);
begin
EX_do1: FDC port map( ... );
end generate;


However, I want the attribute only on instances 0..15. So I tried this:

outer: for index in 17 downto 0 generate
begin

inner: if index < 16 generate
attribute RLOC of EX_do1: label is "X0Y" & integer'image(index / 4);
begin end generate;

EX_do1: FDC port map( ... );
end generate;


Now I'm getting the error message <EX_do1> is not declared. I tried moving inner before the begin of the outer statement, but same result. How can I refer to the flipflop?

I assume it would be possible by pulling the component initialization into the if-block and repeating it again in an if-not-block, but I am trying to avoid redundant code.

• I think it would be clearer if you just had two generate loops, one for 17..16, and one for 15..0. – Dave Tweed Feb 6 at 14:52
• Dave: that is my work-around for the moment. But it requires me to repeat everything that is declared in the outer block twice. This bloats the code and makes it hard to maintain. – travelboy Feb 6 at 15:06
• Yeah, VHDL is like that. I sometimes write scripts to generate my code for me. The m4 macro preprocessor can help quite a bit, too. I'm not a VHDL expert by any means -- there may be a way to do what you want within the language. – Dave Tweed Feb 6 at 15:35

## 1 Answer

I found an old comp.lang.vhdl post that led me to the FAQ.

Section 4.2.3 seems to suggest that you can use one or more additional for loops to assign your attributes, by referring to the instances of your FDCs using the syntax outer(index).EX_do1.

I'm not set up to verify this myself — let me know whether or not it's helpful.

• This does not work :-( although it would make a lot of sense if it did. Illegal name in specification. I think the FAQ article refers to configuring components but the same syntax cannot be used for attaching attributes. – travelboy Feb 6 at 19:33