A
Andreas Ehliar
Guest
Is the macro expansion of the following code defined in SystemVerilog and
if so, what is the expected macro expansion?
`define TEST(x,y) \
`ifdef TEST_STUFF \
x <= y + 42; \
`else \
x <= y * 53; \
`define TEST_STUFF \
`endif
module grmbl(input wire clk,
input wire [31:0] test,test2,
output reg [31:0] o1, o2);
always @(posedge clk) begin
`TEST(o1,test);
`TEST(o2,test2);
end
endmodule
ModelSim expands this as follows, which looks fairly reasonable to me:
module grmbl(input wire clk,
input wire [31:0] test,test2,
output reg [31:0] o1, o2);
always @(posedge clk) begin
o1 <= test * 53; ;
o2 <= test2 + 42; ;
end
endmodule
Precision Synthesis seems to expand it in the same manner as well, but it
gives the following warnings:
Warning: [42044]: Compiler directive `ifdef is present inside macro definition.
Warning: [42044]: Compiler directive `else is present inside macro definition.
Warning: [42044]: Compiler directive `endif is present inside macro definition.
So, I'm beginning to wonder whether the behavior of this situation is actually
defined.
/Andreas
if so, what is the expected macro expansion?
`define TEST(x,y) \
`ifdef TEST_STUFF \
x <= y + 42; \
`else \
x <= y * 53; \
`define TEST_STUFF \
`endif
module grmbl(input wire clk,
input wire [31:0] test,test2,
output reg [31:0] o1, o2);
always @(posedge clk) begin
`TEST(o1,test);
`TEST(o2,test2);
end
endmodule
ModelSim expands this as follows, which looks fairly reasonable to me:
module grmbl(input wire clk,
input wire [31:0] test,test2,
output reg [31:0] o1, o2);
always @(posedge clk) begin
o1 <= test * 53; ;
o2 <= test2 + 42; ;
end
endmodule
Precision Synthesis seems to expand it in the same manner as well, but it
gives the following warnings:
Warning: [42044]: Compiler directive `ifdef is present inside macro definition.
Warning: [42044]: Compiler directive `else is present inside macro definition.
Warning: [42044]: Compiler directive `endif is present inside macro definition.
So, I'm beginning to wonder whether the behavior of this situation is actually
defined.
/Andreas