svstuff / systemverilog

SystemVerilog stuff and stuff.
http://svstuff.github.io/systemverilog
MIT License
11 stars 4 forks source link

token concatenation is buggy #11

Open eriklovlie opened 8 years ago

eriklovlie commented 8 years ago

The following test fails:

`define SIZE 42
`define D(a) `SIZE``a
`D('d0)

It fails during macro expansion because SIZE'd0 is used as the full macro target, and not just SIZE. The reason is the logic that deals with the following (i.e. concatenation which leads to a recursive macro call):

`define FOO(TYPE,ARG,FLAG) `M_UVM_``TYPE(ARG,FLAG)
`define M_UVM_ARRAY(arg1, arg2) yo
`FOO(ARRAY, byte_valid, UVM_NOPACK)

So the former currently fails and the latter works. Obviously SIZE'd0 cannot be a legal macro name, but that's irrelevant here. When the macro text in D is scanned we can't know whether it will expand to a new macro call SIZE_rest_of_macro_name or 42'd0.

The LRM doesn't appear to be very clear on the rules here and there is not much available example code except for the latter example above (from the uvm reference implementation).

eriklovlie commented 8 years ago

Let's say you have this case:

`define SIZE 1
`define SIZE23 hello
`define D(a) `SIZE``a
`D(23)

It's not clear to me whether the result should be 123 or hello.