From 4ec75b261854f0013781e515678c3f79de884fa1 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Tue, 24 Sep 2024 18:53:32 -0400 Subject: [PATCH] Fix over-permissive parsing of UDPs without identifiers --- src/V3ParseImp.cpp | 3 ++- src/verilog.y | 20 ++++++++++++++------ test_regress/t/t_preproc_inc_bad.out | 2 +- test_regress/t/t_vams_kwd_bad.out | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/V3ParseImp.cpp b/src/V3ParseImp.cpp index ea60f2061..fc6d979df 100644 --- a/src/V3ParseImp.cpp +++ b/src/V3ParseImp.cpp @@ -656,7 +656,8 @@ int V3ParseImp::tokenToBison() { m_bisonLastFileline = yylval.fl; // yylval.scp = nullptr; // Symbol table not yet needed - no packages - if (debugFlex() >= 6 || debugBison() >= 6) { // --debugi-flex and --debugi-bison + if (debug() >= 6 || debugFlex() >= 6 + || debugBison() >= 6) { // --debugi-flex and --debugi-bison cout << "tokenToBison " << yylval << endl; } return yylval.token; diff --git a/src/verilog.y b/src/verilog.y index 1f2b62e3f..18be2aba6 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3242,7 +3242,9 @@ instDecl: // // Currently disambiguated from data_declaration based on // // VARs being type, and cells non-type. // // IEEE requires a '(' to disambiguate, we need TODO force this - id parameter_value_assignmentE {INSTPREP($1, *$1, $2);} instnameList ';' + id parameter_value_assignmentE + /*mid*/ { INSTPREP($1, *$1, $2); } + /*cont*/ instnameList ';' { $$ = $4; GRAMMARP->m_impliedDecl = false; if (GRAMMARP->m_instParamp) { @@ -3257,6 +3259,12 @@ instDecl: /*cont*/ mpInstnameList ';' { $$ = VARDONEP($5, nullptr, nullptr); } //UNSUP: strengthSpecE for udp_instantiations + // // IEEE: part of udp_instance when no name_of_instance + // // Note no unpacked dimension nor list of instances + | id + /*mid*/ { INSTPREP($1, *$1, nullptr); } + /*cont*/ instnameParenUdpn ';' + { $$ = $3; GRAMMARP->m_impliedDecl = false; } ; mpInstnameList: // Similar to instnameList, but for modport instantiations which have no parenthesis @@ -3278,7 +3286,10 @@ instnameParen: { $$ = GRAMMARP->createCellOrIfaceRef($1, *$1, $4, $2, true); } | id instRangeListE { $$ = GRAMMARP->createCellOrIfaceRef($1, *$1, nullptr, $2, false); } - | '(' cellpinListE ')' // When UDP has empty name, unpacked dimensions must not be used + ; + +instnameParenUdpn: // IEEE: part of udp_instance when no name_of_instance + '(' cellpinListE ')' // When UDP has empty name, unpacked dimensions must not be used { $$ = GRAMMARP->createCellOrIfaceRef($1, "", $2, nullptr, true); } ; @@ -4607,7 +4618,7 @@ taskId: SYMP->pushNewUnderNodeOrCurrent($$, $1); } ; -funcId: // IEEE: function_data_type_or_implicit + part of function_body_declaration +funcId: // IEEE: function_data_type_or_implicit + part of function_body_declaration // // IEEE: function_data_type_or_implicit must be expanded here to prevent conflict // // function_data_type expanded here to prevent conflicts with // // implicit_type:empty vs data_type:ID @@ -6552,9 +6563,6 @@ boolean_abbrev: // ==IEEE: boolean_abbrev { $$ = $2; BBUNSUP($1, "Unsupported: [-> boolean abbrev expression"); } ; -//************************************************ -// Let - //************************************************ // Covergroup diff --git a/test_regress/t/t_preproc_inc_bad.out b/test_regress/t/t_preproc_inc_bad.out index 2f46dacbd..006f0ec09 100644 --- a/test_regress/t/t_preproc_inc_bad.out +++ b/test_regress/t/t_preproc_inc_bad.out @@ -1,4 +1,4 @@ -%Error: t/t_preproc_inc_inc_bad.vh:11:1: syntax error, unexpected endmodule, expecting IDENTIFIER or '(' or randomize +%Error: t/t_preproc_inc_inc_bad.vh:11:1: syntax error, unexpected endmodule, expecting IDENTIFIER or randomize 11 | endmodule | ^~~~~~~~~ t/t_preproc_inc_bad.v:10:1: ... note: In file included from 't_preproc_inc_bad.v' diff --git a/test_regress/t/t_vams_kwd_bad.out b/test_regress/t/t_vams_kwd_bad.out index 9e3a97617..0d6fac32e 100644 --- a/test_regress/t/t_vams_kwd_bad.out +++ b/test_regress/t/t_vams_kwd_bad.out @@ -2,7 +2,7 @@ 12 | int above; | ^~~~~ ... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest -%Error: t/t_vams_kwd_bad.v:12:13: syntax error, unexpected ';', expecting IDENTIFIER or '(' or randomize +%Error: t/t_vams_kwd_bad.v:12:13: syntax error, unexpected ';', expecting IDENTIFIER or randomize 12 | int above; | ^ %Error-UNSUPPORTED: t/t_vams_kwd_bad.v:13:8: Unsupported: AMS reserved word not implemented: 'abs'