If you have du``I_clk_x;, then the compiler would only see the tokens du and I_clk_x, and not just I.
So this means if i just use ``I , the expansion of macro `abc(1,a) would be :
assign abc[1] == R.duI_clk_x . Since its not defined as a separate token ??
Both R and I are arguments to the macro so why you say that no R is needed where as I is needed. Is it because the left hand side has no dependency on R or is it because R is not breaking the lexical variable ?
Also i also see some defines as :
define DUNIT_IOSFSB_ME(I) IF_DUNITCTE.ME_if[``I]
So here I is not used, why ?
Sorry for asking so many questions the LRM just has insufficient info on this.
So this means if i just use ``I , the expansion of macro `abc(1,a) would be :
assign abc[1] == R.duI_clk_x . Since its not defined as a separate token ??
Yes, that would be the result.
Both R and I are arguments to the macro so why you say that no R is needed where as I is needed. Is it because the left hand side has no dependency on R or is it because R is not breaking the lexical variable ?
Correct again. What you call a lexical variable is what the compiler calls a token identifier. The compiler grabs text in chunks called tokens, before it knows what the identifier is (variable, typedef, module name). An identifier starts with a letter, followed by any number of alpha-numeric characters, as well as _(underscore). Any other character ends the token.
So here I is not used, why ?
Only [I] is needed because I is surrounded by characters that are not part of token identifiers.
Hi i am trying to concatenate a macro with a string variable. Below is the code:
define VAR_LANE0 8'h0000; //MEMORY is kind of storage memory, defined outside and being included in this file. I am not showing that part class my_class; reg [8*8:0] str_var = "LANE0"; // a string variable which can store max 8 characters. // here it is storing "LANE0" string. bit [7:0] local_var1 = MEMORY[VAR_LANE0];
bit [7:0] local_var2 = MEMORY[`VAR_str_var]; // trying to concatenate the macro with the
// string. But error is coming.
Any solution please. I want to achieve the VAR_LANE0 by using VAR_str_var, if any other way is there please tell.
I don’t think you will be able to do mix compiler time defines with run-time variables. There is no space/tab to distinguish between 2 lexical tokens(VAR ,str_var). When you put space the expression will become illegal.
Not sure about your intent in creating a macro so if you can give some info on what you are trying to do then it will help us in providing proper solution.
You can use parameterized macro but you cannot use a variable while calling it.
`define VAR_LANE(x) 8'h``x
bit [7:0] local_var1 = MEMORY[`VAR_LANE(0)];
or
`define VAR_LANE0 8'h07
`define VAR(x) `VAR_``x
bit [7:0] local_var1 = `VAR(LANE0);
In reply to saurabh_vlsi:
Macros are preprocessor directives. There are expanded before parsing any Verilog/SystemVerilog syntax.
Hi Dave Rich,
so do you mean we cant access macros inside generate ?
Below is my requirement
`define dev_(n) top.n.XXX
generate
genvar i;
for (i=0; i<=31; i=i+1) begin: gen_force
initial
force `dev_(i).zzz = 1’b1;
end
endgenerate
Finally i need to have : when i=0 , top.0.XXX.zzz=1’b1
Here always “i” value is not substituted into dev_(n) , we could see instead of value of i directly variable “i” got replaced into macro . Is this approach is correct ? could you please let me know is there any other approach to achieve my requirement .
Thanks
generate
genvar i;
for (i=0; i<=31; i=i+1) begin: gen_force
initial
force `dev_(i).zzz = 1’b1;
end
endgenerate
Finally i need to have : when i=0 , top.0.XXX.zzz=1’b1
Here always “i” value is not substituted into dev_(n) , we could see instead of value of i directly variable “i” got replaced into macro . Is this approach is correct ? could you please let me know is there any other approach to achieve my requirement .
Thanks
In reply to kvssrohit: As I said before, macros get expanded as text for any generate processing. `dev_(i) gets expanded as top.i.XXX
The only way to achieve what you want withing SystemVerilog is to restructure your instance names into an array and access them with proper indexing. top[i].
Otherwise there are other macro processing tools that you can use to generate the identifier names you are looking for. But that becomes quite a maintenance headache.