Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes for preprocess(), plus organise and extend tests. #61

Merged
merged 62 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
6d826d5
ppTests Descriptive names.
DaveMcEwan Jul 20, 2022
1a77bbb
ppTests Rename get_testcase -> testcase_path
DaveMcEwan Jul 20, 2022
9a25410
ppTest Move expected pp output to separate files.
DaveMcEwan Jul 20, 2022
93f305c
ppTests Add tests from LRM, but don't run them yet.
DaveMcEwan Jul 21, 2022
bed9b08
ppTests mv escaped_identifier
DaveMcEwan Jul 21, 2022
c16de49
ppTests mv ifdef_nested
DaveMcEwan Jul 21, 2022
c64a151
ppTests ifdef_undefined,ifdef_predefined
DaveMcEwan Jul 21, 2022
c78276b
ppTests include_origin,include_ignore
DaveMcEwan Jul 21, 2022
a3d4898
ppTests mv ifndef_undefined
DaveMcEwan Jul 21, 2022
12d43f8
ppTests mv macro_LINE
DaveMcEwan Jul 21, 2022
493fa21
ppTests mv whitespace_directives
DaveMcEwan Jul 21, 2022
b9f9011
ppTests mv macro_parameters_multiline
DaveMcEwan Jul 21, 2022
60e4630
ppTests mv macro_parameters_defaultvalue
DaveMcEwan Jul 21, 2022
e844296
ppTests mv macro_recursion_direct
DaveMcEwan Jul 21, 2022
c375b46
ppTests mv macro_recursion_indirect
DaveMcEwan Jul 21, 2022
25783f0
ppTests mv include_sameline_include
DaveMcEwan Jul 21, 2022
2635d27
ppTests mv include_sameline_keyword
DaveMcEwan Jul 21, 2022
dca16d2
ppTests mv include_sameline_comment
DaveMcEwan Jul 21, 2022
e4b2fdb
ppTests mv include_basic
DaveMcEwan Jul 21, 2022
81e3d1e
ppTests mv macro_multiline_comment
DaveMcEwan Jul 21, 2022
637e970
ppTests mv macro_basic
DaveMcEwan Jul 21, 2022
d40374b
ppTests mv IEEE18002017_macro_noexpand_string
DaveMcEwan Jul 21, 2022
f4554b0
ppTests mv IEEE18002017_macro_mix_quotes
DaveMcEwan Jul 21, 2022
6f752c4
ppTests rm missed expected
DaveMcEwan Jul 21, 2022
3e8db79
ppTests mv macro_comment
DaveMcEwan Jul 21, 2022
e966beb
ppTests mv macro_identifier
DaveMcEwan Jul 21, 2022
812014e
ppTests Add two quotes from LRM in split_text().
DaveMcEwan Jul 21, 2022
daa5513
ppTests MESSY Rearrange tests alphabetically.
DaveMcEwan Jul 21, 2022
c5ba2b4
ppTests Fix bad filename.
DaveMcEwan Jul 21, 2022
d1e6f6e
ppTests Fix bad filename.
DaveMcEwan Jul 21, 2022
f927aee
ppTests Add missing IEEE18002017_* tests.
DaveMcEwan Jul 21, 2022
bd1fc19
ppTests Rename test2.svh -> included.svh
DaveMcEwan Jul 21, 2022
1be39f0
ppTests Fold markers around tests.
DaveMcEwan Jul 21, 2022
28cbd8a
ppTests Extend non-IEEE tests around macros.
DaveMcEwan Jul 21, 2022
d1e7f32
ppTests Comment-only explain replacements.
DaveMcEwan Jul 21, 2022
026e606
ppTests Fix IEEE18002017_macro_without_defaults
DaveMcEwan Jul 21, 2022
4f1b566
ppTests Use rearrange tests alphabetically after renames.
DaveMcEwan Jul 21, 2022
7236f51
ppTests Correct whitespace in macro expansion.
DaveMcEwan Jul 21, 2022
2e77dbc
ppTests Extend macro_LINE to catch more unusual behaviour seen in the…
DaveMcEwan Jul 25, 2022
f85809f
ppTests macro_FILE
DaveMcEwan Jul 25, 2022
963e17a
ppTests Allow `define __FILE__ and `define __LINE__ to parse.
DaveMcEwan Jul 25, 2022
565d15c
ppTests mv macro_FILE into alphabetical position.
DaveMcEwan Jul 26, 2022
4d647bf
ppTests IEEE1800-2017_keyword_*
DaveMcEwan Jul 26, 2022
fc26dbf
ppTests rm whitespace_directives
DaveMcEwan Jul 26, 2022
15c38aa
ppTests keywords
DaveMcEwan Jul 26, 2022
dc36b4b
ppTests timescale
DaveMcEwan Jul 26, 2022
466301c
ppTests celldefine
DaveMcEwan Jul 26, 2022
5c96bcb
ppTests default_nettype
DaveMcEwan Jul 26, 2022
3641284
ppTests unconnected_drive
DaveMcEwan Jul 26, 2022
c56c6a9
ppTests pragma
DaveMcEwan Jul 26, 2022
3c693d0
ppTests resetall
DaveMcEwan Jul 26, 2022
bf6e568
ppTests line
DaveMcEwan Jul 26, 2022
ae43678
ppTests undef
DaveMcEwan Jul 26, 2022
5439150
ppTests undefineall
DaveMcEwan Jul 26, 2022
ab4845a
ppTests Avoid removal of `undef and `undefineall directives.
DaveMcEwan Jul 26, 2022
edf6684
ppTests Add missing undefineall test.
DaveMcEwan Jul 26, 2022
ddf33de
ppTests Explain and rename include_basic,include_origin -> include_wi…
DaveMcEwan Jul 26, 2022
2b9ed78
ppTests Comment-only explain include implementation.
DaveMcEwan Jul 26, 2022
de09889
ppTests Simplify tests with `preprocess_usualargs()`.
DaveMcEwan Jul 26, 2022
3755299
ppTests include_recursive
DaveMcEwan Jul 26, 2022
8e461d0
ppTests Protect against infinite include recursion.
DaveMcEwan Jul 26, 2022
da61579
ppTests include_quoted_(a|b|c|d)
DaveMcEwan Jul 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions sv-parser-parser/src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,6 @@ pub(crate) const KEYWORDS_1800_2017: &[&str] = &[
];

pub(crate) const KEYWORDS_DIRECTIVE: &[&str] = &[
"__FILE__",
"__LINE__",
"begin_keywords",
"celldefine",
"default_nettype",
Expand Down
1,063 changes: 582 additions & 481 deletions sv-parser-pp/src/preprocess.rs

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_keywords_if2_13642005.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

`begin_keywords "1364-2005" // use IEEE Std 1364-2005 Verilog keywords
interface if2 (); // ERROR: "interface" is not a keyword in 1364-2005
// This interface should pass the preprocessor, but not the main parser
// because the identifiers `interface` and `endinterface` are not reserved
// keywords in IEEE1364-2005.
endinterface // ERROR: "endinterface" is not a keyword in 1364-2005
`end_keywords
8 changes: 8 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_keywords_m2_13642001.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

`begin_keywords "1364-2001"
module m2 ();
// "logic" is NOT a reserved keyword in IEEE1364-2001.
// This module should pass both the preprocessor, AND the main parser.
reg [63:0] logic;
endmodule
`end_keywords
8 changes: 8 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_keywords_m2_18002005.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

`begin_keywords "1800-2005"
module m2 ();
// "logic" IS a reserved keyword in IEEE1800-2005.
// This module should pass both the preprocessor, but NOT the main parser.
reg [63:0] logic;
endmodule
`end_keywords
10 changes: 10 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_macro_argument_expansion.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* IEEE1800-2017 Clause 22.5.1 page 679
*/

`define max(a,b)((a) > (b) ? (a) : (b))
`define TOP(a,b) a + b

module m;
assign n = `max(p+q, r+s) ;
assign z = `TOP( `TOP(b,1), `TOP(42,a) );
endmodule
7 changes: 7 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_macro_delimit_tokens.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* IEEE1800-2017 Clause 22.5.1 page 680
*/

`define append(f) f``_master

module `append(clock);
endmodule
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* IEEE1800-2017 Clause 22.5.1 page 680
*/

`define msg(x,y) `"x: `\`"y`\`"`"

module a;
Expand Down
13 changes: 13 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_macro_noexpand_string.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* IEEE1800-2017 Clause 22.5.1 page 679
*/

module main;
`define HI Hello
`define LO "`HI, world"
`define H(x) "Hello, x"
initial begin
$display("`HI, world");
$display(`LO);
$display(`H(world));
end
endmodule
25 changes: 25 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_macro_with_defaults.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* IEEE1800-2017 Clause 22.5.1 page 678
* NOTE: Illegal cases are not included in this testcase.
* NOTE: Use of EMPTY is suggested on page 679
*/

`define MACRO1(a=5,b="B",c) $display(a,,b,,c);
`define MACRO2(a=5, b, c="C") $display(a,,b,,c);
`define MACRO3(a=5, b=0, c="C") $display(a,,b,,c);

`define EMPTY

module m;
initial begin
`MACRO1 ( , 2, 3 )
`MACRO1 ( 1 , , 3 )
`MACRO1 ( , 2, )
`MACRO2 (1, , 3)
`MACRO2 (, 2, )
`MACRO2 (, 2)
`MACRO3 ( 1 )
`MACRO3 ( )

`MACRO3 (`EMPTY,`EMPTY,`EMPTY)
end
endmodule
13 changes: 13 additions & 0 deletions sv-parser-pp/testcases/IEEE18002017_macro_without_defaults.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* IEEE1800-2017 Clause 22.5.1 page 677
* NOTE: Illegal cases are not included in this testcase.
*/

`define D(x,y) initial $display("start", x , y, "end");

module m;
`D( "msg1" , "msg2" )
`D( " msg1", )
`D(, "msg2 ")
`D(,)
`D( , )
endmodule
13 changes: 13 additions & 0 deletions sv-parser-pp/testcases/celldefine.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// IEEE1800-2017 Clause 22.10
// The directives `celldefine and `endcelldefine tag modules as cell modules.
// Cells are used by certain PLI routines and may be useful for applications
// such as delay calculations. It is advisable to pair each `celldefine with an
// `endcelldefine, but it is not required. The latest occurrence of either
// directive in the source controls whether modules are tagged as cell modules.
// More than one of these pairs may appear in a single source description.
// These directives may appear anywhere in the source description, but it is
// recommended that the directives be specified outside any design elements.
// The `resetall directive includes the effects of a `endcelldefine directive.
`celldefine
`endcelldefine
// This file should be emitted from the preprocessor unchanged.
22 changes: 22 additions & 0 deletions sv-parser-pp/testcases/default_nettype.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// IEEE1800-2017 Clause 22.8
// The directive `default_nettype controls the net type created for implicit
// net declarations. It can be used only outside design elements. Multiple
// `default_nettype directives are allowed. The latest occurrence of this
// directive in the source controls the type of nets that will be implicitly
// declared.
// When no `default_nettype directive is present or if the `resetall directive
// is specified, implicit nets are of type wire. When the `default_nettype is
// set to none, all nets shall be explicitly declared. If a net is not
// explicitly declared, an error is generated.
`default_nettype wire // Comment immmediately after keyword+space
`default_nettype tri
`default_nettype tri0
`default_nettype tri1
`default_nettype wand
`default_nettype triand
`default_nettype wor
`default_nettype trior
`default_nettype trireg
`default_nettype uwire
`default_nettype none// Comment immmediately after keyword
// This file should be emitted from the preprocessor unchanged.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

`begin_keywords "1364-2005" // use IEEE Std 1364-2005 Verilog keywords
interface if2 (); // ERROR: "interface" is not a keyword in 1364-2005
// This interface should pass the preprocessor, but not the main parser
// because the identifiers `interface` and `endinterface` are not reserved
// keywords in IEEE1364-2005.
endinterface // ERROR: "endinterface" is not a keyword in 1364-2005
`end_keywords
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

`begin_keywords "1364-2001"
module m2 ();
// "logic" is NOT a reserved keyword in IEEE1364-2001.
// This module should pass both the preprocessor, AND the main parser.
reg [63:0] logic;
endmodule
`end_keywords
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

`begin_keywords "1800-2005"
module m2 ();
// "logic" IS a reserved keyword in IEEE1800-2005.
// This module should pass both the preprocessor, but NOT the main parser.
reg [63:0] logic;
endmodule
`end_keywords
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* IEEE1800-2017 Clause 22.5.1 page 679
*/

`define max(a,b)((a) > (b) ? (a) : (b))
`define TOP(a,b) a + b

module m;
assign n = ((p+q) > (r+s) ? (p+q) : (r+s)) ;
assign z = b + 1 + 42 + a;
endmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* IEEE1800-2017 Clause 22.5.1 page 680
*/

`define append(f) f``_master

module clock_master;
endmodule
10 changes: 10 additions & 0 deletions sv-parser-pp/testcases/expected/IEEE18002017_macro_mix_quotes.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* IEEE1800-2017 Clause 22.5.1 page 680
*/

`define msg(x,y) `"x: `\`"y`\`"`"

module a;
initial begin
$display("left side: \"right side\"");
end
endmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* IEEE1800-2017 Clause 22.5.1 page 679
*/

module main;
`define HI Hello
`define LO "`HI, world"
`define H(x) "Hello, x"
initial begin
$display("`HI, world");
$display("`HI, world");
$display("Hello, x");
end
endmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* IEEE1800-2017 Clause 22.5.1 page 678
* NOTE: Illegal cases are not included in this testcase.
* NOTE: Use of EMPTY is suggested on page 679
*/

`define MACRO1(a=5,b="B",c) $display(a,,b,,c);
`define MACRO2(a=5, b, c="C") $display(a,,b,,c);
`define MACRO3(a=5, b=0, c="C") $display(a,,b,,c);

`define EMPTY

module m;
initial begin
$display(5,,2,,3);
$display(1,,"B",,3);
$display(5,,2,,);
$display(1,,,,3);
$display(5,,2,,"C");
$display(5,,2,,"C");
$display(1,,0,,"C");
$display(5,,0,,"C");

$display(,,,,);
end
endmodule
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* IEEE1800-2017 Clause 22.5.1 page 677
* NOTE: Illegal cases are not included in this testcase.
*/

`define D(x,y) initial $display("start", x , y, "end");

module m;
initial $display("start", "msg1" , "msg2", "end");
initial $display("start", " msg1" , , "end");
initial $display("start", , "msg2 ", "end");
initial $display("start", , , "end");
initial $display("start", , , "end");
endmodule
3 changes: 3 additions & 0 deletions sv-parser-pp/testcases/expected/escaped_identifier.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module a;
reg \`~!-_=+\|[]{};:'"",./<>? ;
endmodule
5 changes: 5 additions & 0 deletions sv-parser-pp/testcases/expected/ifdef_nested.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module A;
wire a = 1'b0;


endmodule
7 changes: 7 additions & 0 deletions sv-parser-pp/testcases/expected/ifdef_predefined.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module and_op (a, b, c);
output a;
input b, c;

wire a = b & c;

endmodule
7 changes: 7 additions & 0 deletions sv-parser-pp/testcases/expected/ifdef_undefined.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module and_op (a, b, c);
output a;
input b, c;

and a1 (a,b,c);

endmodule
5 changes: 5 additions & 0 deletions sv-parser-pp/testcases/expected/ifndef_undefined.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// pragma translate_off
module A;
endmodule
// pragma translate_on

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module and_op (a, b, c);
`include "test2.svh"
endmodule
8 changes: 8 additions & 0 deletions sv-parser-pp/testcases/expected/include_noindent.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module and_op (a, b, c);
output a;
input b, c;

and a1 (a,b,c);


endmodule
9 changes: 9 additions & 0 deletions sv-parser-pp/testcases/expected/include_quoted_c.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Based on last example of IEEE1800-2017 Clause 22.5.1, page 680.
`define APPEND_SVH(path) `"path.svh`"
module and_op (a, b, c);
output a;
input b, c;

and a1 (a,b,c);

endmodule
8 changes: 8 additions & 0 deletions sv-parser-pp/testcases/expected/include_quoted_d.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
`define PATH "included.svh"
module and_op (a, b, c);
output a;
input b, c;

and a1 (a,b,c);

endmodule
8 changes: 8 additions & 0 deletions sv-parser-pp/testcases/expected/include_sameline_comment.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module and_op (a, b, c);
output a;
input b, c;

and a1 (a,b,c);

// comment
endmodule
9 changes: 9 additions & 0 deletions sv-parser-pp/testcases/expected/include_withindent.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module and_op (a, b, c);
// a
output a;
input b, c;

and a1 (a,b,c);


endmodule
15 changes: 15 additions & 0 deletions sv-parser-pp/testcases/expected/macro_FILE.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// __FILE__ = `__FILE__

// This block SHOULD be emitted from the preprocessor.


// Emitted instead.


// The following define should have no effect.
`define __FILE__ "FOO"

// The following undef should have no effect.
`undef __FILE__

// NOTE: Comparison against expected value are destined to fail in testcase.
21 changes: 21 additions & 0 deletions sv-parser-pp/testcases/expected/macro_LINE.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// __LINE__ = `__LINE__

// This block SHOULD be emitted from the preprocessor.


// Emitted instead.


// The following define should have no effect.
`define __LINE__ -2

// The following undef should have no effect.
`undef __LINE__

module M;
initial
if (26 == 28) // Should be "26 == 28".
$display("PASS");
else if (28 == 28) // Should be "28 == 28".
$display("FAIL");
endmodule
Loading