From cd0b360575ca0aebf6fd6487764e633aa8e510a5 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Tue, 20 Dec 2022 17:30:57 +0000 Subject: [PATCH] Support free-form `default_net_type directives. --- ivtest/ivltests/br_gh782f.v | 19 +++++++++++++++++++ ivtest/regress-vlg.list | 1 + lexor.lex | 27 ++++++++++++++++----------- 3 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 ivtest/ivltests/br_gh782f.v diff --git a/ivtest/ivltests/br_gh782f.v b/ivtest/ivltests/br_gh782f.v new file mode 100644 index 000000000..b33b10c2d --- /dev/null +++ b/ivtest/ivltests/br_gh782f.v @@ -0,0 +1,19 @@ +// This is just a syntax test. + +/* comment */ `default_nettype /* comment */ // comment +/* comment */ wire /* comment */ // comment +module m1; +endmodule + +/* comment */`default_nettype/* + comment */ +/* comment */tri0/* + comment */ +module m2; +endmodule + +module test; + +initial $display("PASSED"); + +endmodule diff --git a/ivtest/regress-vlg.list b/ivtest/regress-vlg.list index 57f4c21fa..ef165b190 100644 --- a/ivtest/regress-vlg.list +++ b/ivtest/regress-vlg.list @@ -352,6 +352,7 @@ br_gh732 normal ivltests gold=br_gh732.gold br_gh782c normal ivltests br_gh782d normal ivltests br_gh782e normal ivltests +br_gh782f normal ivltests br_gh788 normal,-gno-io-range-error,-Wno-anachronisms ivltests gold=br_gh788.gold br_gh793 normal ivltests br_ml20150315 normal ivltests gold=br_ml_20150315.gold diff --git a/lexor.lex b/lexor.lex index cad2d6350..74e3ca983 100644 --- a/lexor.lex +++ b/lexor.lex @@ -152,6 +152,7 @@ void lex_in_package_scope(PPackage*pkg) %x PPUCDRIVE %x PPUCDRIVE_ERROR %x PPDEFAULT_NETTYPE +%x PPDEFAULT_NETTYPE_ERROR %x PPBEGIN_KEYWORDS %x PPBEGIN_KEYWORDS_ERROR %s EDGES @@ -785,16 +786,12 @@ TU [munpf] } } - /* Notice and handle the default_nettype directive. The lexor - detects the default_nettype keyword, and the second part of the - rule collects the rest of the line and processes it. We only need - to look for the first work, and interpret it. */ + /* Notice and handle the `default_nettype directive. */ -`default_nettype{W}? { BEGIN(PPDEFAULT_NETTYPE); } -.* { +`default_nettype { BEGIN(PPDEFAULT_NETTYPE); } + +[a-zA-Z0-9_]+ { NetNet::Type net_type; - size_t wordlen = strcspn(yytext, " \t\f\r\n"); - yytext[wordlen] = 0; /* Add support for other wire types and better error detection. */ if (strcmp(yytext,"wire") == 0) { net_type = NetNet::WIRE; @@ -832,11 +829,19 @@ TU [munpf] error_count += 1; } pform_set_default_nettype(net_type, yylloc.text, yylloc.first_line); + BEGIN(0); } -\n { - yylloc.first_line += 1; - BEGIN(0); } +"//" { comment_enter = PPDEFAULT_NETTYPE; BEGIN(LCOMMENT); } +"/*" { comment_enter = PPDEFAULT_NETTYPE; BEGIN(CCOMMENT); } +"\n" { yylloc.first_line += 1; } +{W} { ; } +. { BEGIN(PPDEFAULT_NETTYPE_ERROR); } + + /* On error, try to recover by skipping to the end of the line. */ +[^\n]+ { + VLerror(yylloc, "error: Invalid `default_nettype directive."); + BEGIN(0); } /* These are directives that are not supported by me and should have been handled by an external preprocessor such as ivlpp. */