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
|
|
0
|
|
|
|
Reply
|
Andreas
|
3/18/2011 11:47:20 AM |
|
hi Andreas,
On Mar 18, 11:36=A0am, Andreas Ehliar wrote:
> Is the macro expansion of the following code defined in SystemVerilog and
> if so, what is the expected macro expansion?
>
> `define TEST(x,y) \
> =A0 =A0`ifdef TEST_STUFF \
> =A0 =A0 =A0 =A0 x <=3D y + 42; \
> =A0 =A0`else \
> =A0 =A0 =A0 =A0 x <=3D y * 53; \
> =A0 =A0 `define TEST_STUFF \
> =A0 =A0`endif
The 1800-2009 LRM clearly says that macros can be used inside
`defines, and that they will be substituted AFTER the `define is
expanded - NOT at the point at which it's defined. However, I
couldn't find anything about the behaviour of directives inside
`define.
It might be safer to turn the whole thing inside-out, with two
different definitions of TEST, even though it's likely to be more
verbose:
`ifdef TEST_STUFF
`define TEST(x,y) x <=3D y + 42;
`else
`define TEST(x,y) x <=3D y * 53;
`define TEST_STUFF
`endif
Anyone else know more precisely what's intended by the LRM?
--
Jonathan Bromley
|
|
0
|
|
|
|
Reply
|
Jonathan
|
3/18/2011 11:51:14 AM
|
|
|
1 Replies
883 Views
(page loaded in 0.061 seconds)
Similiar Articles: `ifdef inside a macro - comp.lang.verilogIs 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 ... Using Verilog Macros with Arguments - comp.arch.fpga`ifdef inside a macro - comp.lang.verilog Using Verilog Macros with Arguments - comp.arch.fpga Hi all, I want to used parameterized Verilog macros in my code. Please Fix My Macro - comp.cad.solidworks`ifdef inside a macro - comp.lang.verilog Please Fix My Macro - comp.cad.solidworks `ifdef inside a macro - comp.lang.verilog Please Fix My Macro - comp.cad.solidworks ... access2007 ribbon refresh within a macro - comp.databases.ms ...access2007 ribbon refresh within a macro - comp.databases.ms ... I have a function ... `ifdef inside a macro - comp.lang.verilog access2007 ribbon refresh within a macro - comp ... Macros in putty... - comp.unix.solaris`ifdef inside a macro - comp.lang.verilog Is the macro expansion of the following code defined in SystemVerilog and if so ... Macros in putty... - comp.unix.solaris Putty ... ifdef not working (GNU make) - comp.unix.programmer`ifdef inside a macro - comp.lang.verilog ifdef not working (GNU make) - comp.unix.programmer `ifdef inside a macro - comp.lang.verilog ifdef not working (GNU make) - comp ... macros for path,names, concat, and output export - comp.soft-sys ...`ifdef inside a macro - comp.lang.verilog macros for path,names, concat, and output export - comp.soft-sys ... `ifdef inside a macro - comp.lang.verilog When I generate ... Makefile: set macro once (Solaris make, GNU make) - comp.unix ...`ifdef inside a macro - comp.lang.verilog Makefile: set macro once (Solaris make, GNU make) - comp.unix ... ifdef not working (GNU make) - comp.unix.programmer `ifdef ... Refresh Linked SharePoint tables - comp.databases.ms-access ...Refresh Linked SharePoint tables - comp.databases.ms-access ... `ifdef inside a macro - comp.lang.verilog Refresh Linked SharePoint tables - comp.databases.ms-access ... stopping the timer object - comp.soft-sys.matlab`ifdef inside a macro - comp.lang.verilog stopping the timer object - comp.soft-sys.matlab Please Fix My Macro - comp.cad.solidworks `ifdef inside a macro - comp.lang ... Ifdef - The C Preprocessor - GCC, the GNU Compiler Collection ...4.2.1 Ifdef. The simplest sort of conditional is #ifdef MACRO controlled text #endif /* MACRO*/ ... The controlled text inside of a conditional can include ... Re: #ifdef inside macro expansion - Tech-Archive.net: The source ...The preprocessor is what you are looking at - not the compiler. The preprocesor is not required to process the text it expands a macro with, so this is expected ... 7/25/2012 11:37:50 PM
|