diff --git a/sv-parser-pp/testcases/expected/macro_arguments.sv b/sv-parser-pp/testcases/expected/macro_arguments.sv new file mode 100644 index 0000000..0637660 --- /dev/null +++ b/sv-parser-pp/testcases/expected/macro_arguments.sv @@ -0,0 +1,23 @@ +// Macro with parameters with usage spread over multiple lines. +// Final line of macro is line14. +// Argument value `clk` is equal to its name. +// Argument value of exp contains matching brackets and parentheses. +// Bracketed value of msg is required to avoid being parsed as a parameterized +// macro instead of argumnts to $display. +// NOTE: Trailing whitespace is not exercised here, i.e. continuations +// immediately follow non-whitespace. +`define disp(clk, exp, msg)\ + always @(posedge clk)\ + if (exp) begin\ + $display msg;\ + end\ + +module M (); + + always @(posedge clk) + if (!(a[i].b && c[i])) begin + $display ("xxx(()[]]{}}}", a[i].b, c[i]); + end +; // NOTE: Semi-colon is unnecessary. + +endmodule diff --git a/sv-parser-pp/testcases/expected/macro_basic.sv b/sv-parser-pp/testcases/expected/macro_basic.sv index c5f5078..6ff2696 100644 --- a/sv-parser-pp/testcases/expected/macro_basic.sv +++ b/sv-parser-pp/testcases/expected/macro_basic.sv @@ -1,4 +1,6 @@ -`define MOD_INST u_mysubmod -module mymod; -mysubmod u_mysubmod() ; +`define A aaa +module M; +aaa#() a0 (.*); // No trailing whitespace. +aaa #() a1 (.*); // Trailing 1 space. +aaa #() a2 (.*); // Trailing 2 spaces. endmodule diff --git a/sv-parser-pp/testcases/expected/macro_comment.sv b/sv-parser-pp/testcases/expected/macro_comment.sv index 836e665..a9759dd 100644 --- a/sv-parser-pp/testcases/expected/macro_comment.sv +++ b/sv-parser-pp/testcases/expected/macro_comment.sv @@ -1,2 +1,16 @@ -`define A 42 // Comment -interface i #(p = 42) (); endinterface +/* IEEE1800-2017 Clause 22.5.1, page 676 +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. +*/ + +// A has no comment +// B has a comment after 1 space +// C has a comment after 3 spaces +`define A 11 +`define B 22 // Comment not included in macro, but whitespace before `//` is. +`define C 33 // Comment not included in macro, but whitespace before `//` is. + +interface A #(p=11) (); endinterface +interface B #(p=22 ) (); endinterface +interface C #(p=33 ) (); endinterface diff --git a/sv-parser-pp/testcases/expected/macro_delimiters.sv b/sv-parser-pp/testcases/expected/macro_delimiters.sv new file mode 100644 index 0000000..d3abef6 --- /dev/null +++ b/sv-parser-pp/testcases/expected/macro_delimiters.sv @@ -0,0 +1,17 @@ +// Multi-line macro defined with 2 trailing spaces before initial continuation. +// First line has no trailing space, second has trailing space, third is end. +// Macro contains 2-space indent, so indented usage gets extra. +// Delimiters (``) used before and after arguments. +`define connect(NAME, INDEX = 0) \ + assign NAME``_``INDEX``__x = NAME[INDEX].x;\ + assign NAME``_``INDEX``__y = NAME[INDEX].y; \ + assign NAME``_``INDEX``__z = NAME[INDEX].z; + +module M (); + assign a_0__x = a[0].x; + assign a_0__y = a[0].y; + assign a_0__z = a[0].z; + assign a_1__x = a[1].x; + assign a_1__y = a[1].y; + assign a_1__z = a[1].z; +endmodule diff --git a/sv-parser-pp/testcases/expected/macro_identifier.sv b/sv-parser-pp/testcases/expected/macro_identifier.sv index 71e4b1e..3812a08 100644 --- a/sv-parser-pp/testcases/expected/macro_identifier.sv +++ b/sv-parser-pp/testcases/expected/macro_identifier.sv @@ -1,10 +1,10 @@ -module a; `define A "aaa" `define \B "bbb" -initial begin -$display("aaa"); -$display("aaa"); -$display("bbb"); -$display("bbb"); -end +module M; + initial begin + $display("aaa"); + $display("aaa" ); + $display("bbb"); + $display("bbb" ); + end endmodule diff --git a/sv-parser-pp/testcases/expected/macro_multiline_comment.sv b/sv-parser-pp/testcases/expected/macro_multiline_comment.sv index 85ed300..989e21b 100644 --- a/sv-parser-pp/testcases/expected/macro_multiline_comment.sv +++ b/sv-parser-pp/testcases/expected/macro_multiline_comment.sv @@ -1,10 +1,19 @@ +// Leading whitespace on 4 lines. +// initial \ Space before line continuation. +// begin\ No space before line continuation. +// $display(); // comment \ Continuation at end of comment. +// end +// NOTE: Trailing whitespace on lines ending `initial ` and `$display(); `. + `define A \ - initial begin // comment \ - end - -module test(); - -initial begin - end + initial \ + begin\ + $display(); // comment \ + end +module M; + initial + begin + $display(); + end endmodule diff --git a/sv-parser-pp/testcases/expected/macro_parameters_defaultvalue.sv b/sv-parser-pp/testcases/expected/macro_parameters_defaultvalue.sv deleted file mode 100644 index 7cc0596..0000000 --- a/sv-parser-pp/testcases/expected/macro_parameters_defaultvalue.sv +++ /dev/null @@ -1,9 +0,0 @@ -`define connect(NAME, INDEX = 0) \ - assign NAME``_``INDEX``__x = NAME[INDEX].x; \ - assign NAME``_``INDEX``__y = NAME[INDEX].y; - -module a (); - - assign a_0__x = a[0].x; - assign a_0__y = a[0].y; assign a_1__x = a[1].x; - assign a_1__y = a[1].y; endmodule diff --git a/sv-parser-pp/testcases/expected/macro_parameters_multiline.sv b/sv-parser-pp/testcases/expected/macro_parameters_multiline.sv deleted file mode 100644 index c4839c4..0000000 --- a/sv-parser-pp/testcases/expected/macro_parameters_multiline.sv +++ /dev/null @@ -1,17 +0,0 @@ -`define disp(clk, exp, msg) \ - always @(posedge clk) begin \ - if (!(exp)) begin \ - $display msg; \ - end \ - end \ - -module a (); - -always @(posedge clk) begin - if (!(!(a[i].b && c[i]))) begin - $display ("xxx(()[]]{}}}", a[i].b, c[i]); - end - end - ; - -endmodule diff --git a/sv-parser-pp/testcases/macro_arguments.sv b/sv-parser-pp/testcases/macro_arguments.sv new file mode 100644 index 0000000..fae8300 --- /dev/null +++ b/sv-parser-pp/testcases/macro_arguments.sv @@ -0,0 +1,23 @@ +// Macro with parameters with usage spread over multiple lines. +// Final line of macro is line14. +// Argument value `clk` is equal to its name. +// Argument value of exp contains matching brackets and parentheses. +// Bracketed value of msg is required to avoid being parsed as a parameterized +// macro instead of argumnts to $display. +// NOTE: Trailing whitespace is not exercised here, i.e. continuations +// immediately follow non-whitespace. +`define disp(clk, exp, msg)\ + always @(posedge clk)\ + if (exp) begin\ + $display msg;\ + end\ + +module M (); + +`disp( + clk, + !(a[i].b && c[i]), + ("xxx(()[]]{}}}", a[i].b, c[i]) +); // NOTE: Semi-colon is unnecessary. + +endmodule diff --git a/sv-parser-pp/testcases/macro_basic.sv b/sv-parser-pp/testcases/macro_basic.sv index 083382a..17c60ca 100644 --- a/sv-parser-pp/testcases/macro_basic.sv +++ b/sv-parser-pp/testcases/macro_basic.sv @@ -1,4 +1,6 @@ -`define MOD_INST u_mysubmod -module mymod; -mysubmod `MOD_INST (); +`define A aaa +module M; +`A#() a0 (.*); // No trailing whitespace. +`A #() a1 (.*); // Trailing 1 space. +`A #() a2 (.*); // Trailing 2 spaces. endmodule diff --git a/sv-parser-pp/testcases/macro_comment.sv b/sv-parser-pp/testcases/macro_comment.sv index 2adacc4..af7dafa 100644 --- a/sv-parser-pp/testcases/macro_comment.sv +++ b/sv-parser-pp/testcases/macro_comment.sv @@ -1,2 +1,16 @@ -`define A 42 // Comment -interface i #(p = `A) (); endinterface +/* IEEE1800-2017 Clause 22.5.1, page 676 +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. +*/ + +// A has no comment +// B has a comment after 1 space +// C has a comment after 3 spaces +`define A 11 +`define B 22 // Comment not included in macro, but whitespace before `//` is. +`define C 33 // Comment not included in macro, but whitespace before `//` is. + +interface A #(p=`A) (); endinterface +interface B #(p=`B) (); endinterface +interface C #(p=`C) (); endinterface diff --git a/sv-parser-pp/testcases/macro_delimiters.sv b/sv-parser-pp/testcases/macro_delimiters.sv new file mode 100644 index 0000000..8779224 --- /dev/null +++ b/sv-parser-pp/testcases/macro_delimiters.sv @@ -0,0 +1,13 @@ +// Multi-line macro defined with 2 trailing spaces before initial continuation. +// First line has no trailing space, second has trailing space, third is end. +// Macro contains 2-space indent, so indented usage gets extra. +// Delimiters (``) used before and after arguments. +`define connect(NAME, INDEX = 0) \ + assign NAME``_``INDEX``__x = NAME[INDEX].x;\ + assign NAME``_``INDEX``__y = NAME[INDEX].y; \ + assign NAME``_``INDEX``__z = NAME[INDEX].z; + +module M (); + `connect(a) + `connect(a, 1) +endmodule diff --git a/sv-parser-pp/testcases/macro_identifier.sv b/sv-parser-pp/testcases/macro_identifier.sv index 36065de..321f611 100644 --- a/sv-parser-pp/testcases/macro_identifier.sv +++ b/sv-parser-pp/testcases/macro_identifier.sv @@ -1,10 +1,10 @@ -module a; `define A "aaa" `define \B "bbb" -initial begin -$display(`A); -$display(`\A ); -$display(`B); -$display(`\B ); -end +module M; + initial begin + $display(`A); + $display(`\A ); + $display(`B); + $display(`\B ); + end endmodule diff --git a/sv-parser-pp/testcases/macro_multiline_comment.sv b/sv-parser-pp/testcases/macro_multiline_comment.sv index 258b0b4..d5488cb 100644 --- a/sv-parser-pp/testcases/macro_multiline_comment.sv +++ b/sv-parser-pp/testcases/macro_multiline_comment.sv @@ -1,9 +1,16 @@ +// Leading whitespace on 4 lines. +// initial \ Space before line continuation. +// begin\ No space before line continuation. +// $display(); // comment \ Continuation at end of comment. +// end +// NOTE: Trailing whitespace on lines ending `initial ` and `$display(); `. + `define A \ - initial begin // comment \ - end - -module test(); + initial \ + begin\ + $display(); // comment \ + end +module M; `A - endmodule diff --git a/sv-parser-pp/testcases/macro_parameters_defaultvalue.sv b/sv-parser-pp/testcases/macro_parameters_defaultvalue.sv deleted file mode 100644 index f28b184..0000000 --- a/sv-parser-pp/testcases/macro_parameters_defaultvalue.sv +++ /dev/null @@ -1,10 +0,0 @@ -`define connect(NAME, INDEX = 0) \ - assign NAME``_``INDEX``__x = NAME[INDEX].x; \ - assign NAME``_``INDEX``__y = NAME[INDEX].y; - -module a (); - - `connect(a) - `connect(a, 1) - -endmodule diff --git a/sv-parser-pp/testcases/macro_parameters_multiline.sv b/sv-parser-pp/testcases/macro_parameters_multiline.sv deleted file mode 100644 index 7466db6..0000000 --- a/sv-parser-pp/testcases/macro_parameters_multiline.sv +++ /dev/null @@ -1,16 +0,0 @@ -`define disp(clk, exp, msg) \ - always @(posedge clk) begin \ - if (!(exp)) begin \ - $display msg; \ - end \ - end \ - -module a (); - -`disp( - clk, - !(a[i].b && c[i]), - ("xxx(()[]]{}}}", a[i].b, c[i]) -); - -endmodule