define myreg(name) \
logic b_``name``_int;
generate
for (genvar i=0; i<8; i++) begin
modulexyz xyz ( .a(a),
.b(`myreg(i))
);
end
endgenerate
To the submodule xyz , the input b is to be passed with b_0_int , b_1_int ,… b_7_int . What is the best way of using the `define macro for this usage ?
The above , during the compilation gives b_i_int instead of b_0_int, b_1_int , etc.,.
I understand that `define are compiled earlier than the generate blocks. Then how should be above usage be coded ? I donot want to use an array as it adds a lot of code lines.
In reply to dave_59:
Hi dave,
Thanks for your quick response.
Each b_int is of say 256 bits, and say i have variables from b_0_int to b_127_int , I will have to do an assign such as :
assign b_int[0] = b_0_int ;
.
.
.
.
.
assign b_int[127] = b_127_int;
This adds about 128 buffers just for the usage of the modulexyz 128 times. In the above example, I have the b_int mentioned as 8 bits, but how about when the width of it increases. I want to have variability on fly. This is how i meant more code (as a result more buffers).
Thankyou for the alternatives suggested!
Although , Option 1) is not feasible when the variable used is of higher width. and Option 2) woudn’t be right as i want “b” of modulexyz to receive just b_0_int and not the concatenated value.
Hence I see the need to use define macros. Is the usage of define not possible ?
You still did not explain why you need individually named signals instead of using an array in the first place.
As you are already aware, `define macros get expanded before any parsing any SystemVerilog code. There is no way to have a macro loop. Your only other option is using an external macro processor. That can make debugging much more difficult.
Well, i have my signal named as b_*_int . That is why i want to have individually named signals. The only solution i see is FORM AN ARRAY from those individual signals like :