|
From: Cary R. <cy...@ya...> - 2017-03-24 05:46:43
|
Icarus supports this as stated in the following comment which seems wrong:
"The "//" style comments go to the end of the line and terminate the definition"
The standard states that a single line comment "//...." should be ignored in a macro definition.
>From 1800-2012 page 640 "If a one-line comment (that is, a comment specified with the characters //) is included in the text, then the comment shall not become part of the substituted text."
Given how single line comments work it seems like any line continuation character would become part of the comment so it would seem prudent to assume that a single line comment in a macro definition would effectively be replaced in its entirety by "\" to continue the macro. The only place doing this that could create confusion is if the comment was on the last line of the macro where you could get an extra unexpected line, but most people would put a empty line after a macro definition so this may often go unnoticed.
I would expect the following code to compile correctly:
module top;
logic [1:0] out;
logic in, clk, rst;
`define macro_with_comment(q,d,clk,rst) \
// Make the internal stage the same size as the output.
logic [$bits(q)-1:0] \q``_staged ; \
// logic [$bits(d)-1:0] \q``_staged ; \
// Does a space before work?
always @(posedge clk or posedge rst) begin \
if (rst) \q``_staged <= '0; // Reset the first stage. \
else \q``_staged <= d; \
end \
always @(posedge clk or posedge rst) begin \
if (rst) q <= '0; \
else q <= \q``_staged ; \
end // The next line is part of the macro!
`macro_with_comment(out[0], in, clk, rst)
initial $display("PASSED");
endmodule
And more specifically I would expect a single line comment to be ignored no matter the space before it or even if there are actual Verilog commands before it, but not terminate the macro otherwise what is the use of the comment? I agree the standard should state explicitly if the single line comment terminates or continues the macro, but I could not find it if it does.
Could this get tested on various simulators to see what they do and I will try to update Icarus to match the consensus of the simulators or what we agree is best.
Cary
|