Suppose I had some code like below:
`ifndef MY_LIST
`define MY_LIST 'd0, 'd1, 'd2, 'd3
`endif
always_comb begin
foo = 1'b0;
if (some_condition) begin
case (some_input)
`MY_LIST,
`SOME_OTHER_LIST: foo = 1'b1;
default: foo = 'b0;
endcase
end
endfunction
MY_LIST is actually an autogenerated list by a script. It’s possible this list could be empty. If so, I’d be left with:
`ifndef MY_LIST
`define MY_LIST
`endif
This unfortunately causes a compile syntax error. I noticed that if I guard the usage like below, the compile succeeds.
case (some_input)
`ifdef SOME_FLAG_THAT_IS_NOT_DEFINED
`MY_LIST,
`endif
`SOME_OTHER_LIST: foo = 1'b1;
default: foo = 'b0;
endcase
This would require me to know ahead of time that the list is empty and create some sort of special `define to indicate this particular list is empty. I’d also have to have these guards all over the place for every list that is potentially empty.
Is there a more elegant way to solve this problem? I don’t have to use an `ifdef list if that helps.