I am writing a macro to be used by others, and I would like it to require as little input as possible. As such, I would like to be able to pass in a variable as an argument, extract the type, use the type to declare a new variable, and do some other things.
However this doesn’t work. It seems the “$typename(var)” is not compiled when the macro is expanded, since I get the syntax error “(expanding macro): token is ‘$typename’” when I try to run this.
However this runs fine:
`define PRINT_TYPE(var) \
initial begin \
$display("Got type: %s", $typename(var)); \
end \
Is there any way to do this? It doesn’t necessarily need to use $typename, but any way to get the type of a variable without explicitly passing it in would be great.
Parsing design file 'experiment.sv'
Error-[SE] Syntax error
Following verilog source has syntax error :
"experiment.sv", 9 (expanding macro): token is 'type'
`DO_STUFF(a)
^
System verilog keyword 'type' is not expected to be used in this context.
#0, DO_STUFF(var=a) : "experiment.sv":3
full expansion of macro (DO_STUFF), error at line 1
=>type(a) a_new;
1 error
CPU time: .052 seconds to compile
Thanks for pointing me to the correct section of the LRM, and for correcting my syntax issues.
Unfortunately my simulator still doesn’t seem to be able to handle the type operator. I have tried both of these pieces of code:
Parsing design file 'experiment2.sv'
Error-[NYI] Not Yet Implemented
experiment2.sv, 7
Feature is not yet supported: Type operator not supported
"experiment2.sv", 7: token is '('
var type(tp1) tp3;
^
1 error
Is it possible my version of vcs doesn’t have ‘type()’ for some reason? In the forum question I point to above, it seems that the poster’s simulator also cannot handle the type operator. I have a fairly recent version of vcs, so it seems surprising that type() is not there. I will ask my coworkers if they have any idea. Maybe our simulator is different in some way.
Thank you so much for help and patience with this. I really appreciate it.