From 97d89cce35142d1a1f4c08571d436d5a65e34901 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 8 Oct 2018 22:18:09 -0400 Subject: [PATCH] Move some unsupported syntax to parser for cleaner errors. --- src/verilog.l | 6 ++--- src/verilog.y | 64 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/src/verilog.l b/src/verilog.l index df6f5824d..1cd4acca8 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -474,7 +474,9 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "endproperty" { FL; return yENDPROPERTY; } "enum" { FL; return yENUM; } "export" { FL; return yEXPORT; } + "extern" { FL; return yEXTERN; } "final" { FL; return yFINAL; } + "forkjoin" { FL; return yFORKJOIN; } "iff" { FL; return yIFF; } "import" { FL; return yIMPORT; } "inside" { FL; return yINSIDE; } @@ -494,6 +496,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "restrict" { FL; return yRESTRICT; } "return" { FL; return yRETURN; } "shortint" { FL; return ySHORTINT; } + "shortreal" { FL; return ySHORTREAL; } "static" { FL; return ySTATIC; } "string" { FL; return ySTRING; } "struct" { FL; return ySTRUCT; } @@ -523,9 +526,7 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "endsequence" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "expect" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "extends" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } - "extern" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "first_match" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } - "forkjoin" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "ignore_bins" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "illegal_bins" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "intersect" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } @@ -541,7 +542,6 @@ vnum {vnum1}|{vnum2}|{vnum3}|{vnum4}|{vnum5} "randsequence" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "ref" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "sequence" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } - "shortreal" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "solve" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "super" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } "tagged" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); } diff --git a/src/verilog.y b/src/verilog.y index d275b874e..31dd8f000 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -347,10 +347,12 @@ class AstSenTree; %token yENDTASK "endtask" %token yENUM "enum" %token yEXPORT "export" +%token yEXTERN "extern" %token yFINAL "final" %token yFOR "for" %token yFOREACH "foreach" %token yFOREVER "forever" +%token yFORKJOIN "forkjoin" %token yFUNCTION "function" %token yGENERATE "generate" %token yGENVAR "genvar" @@ -408,6 +410,7 @@ class AstSenTree; %token yRTRANIF1 "rtranif1" %token ySCALARED "scalared" %token ySHORTINT "shortint" +%token ySHORTREAL "shortreal" %token ySIGNED "signed" %token ySPECIFY "specify" %token ySPECPARAM "specparam" @@ -707,8 +710,8 @@ package_declaration: // ==IEEE: package_declaration ; packageFront: - yPACKAGE idAny ';' - { $$ = new AstPackage($1,*$2); + yPACKAGE lifetimeE idAny ';' + { $$ = new AstPackage($1,*$3); $$->inLibrary(true); // packages are always libraries; don't want to make them a "top" $$->modTrace(GRAMMARP->allTracingOn($$->fileline())); PARSEP->rootp()->addModulep($$); @@ -727,7 +730,7 @@ package_itemList: // IEEE: { package_item } package_item: // ==IEEE: package_item package_or_generate_item_declaration { $$ = $1; } - //UNSUP anonymous_program { $$ = $1; } + | anonymous_program { $$ = $1; } | package_export_declaration { $$ = $1; } | timeunits_declaration { $$ = $1; } ; @@ -812,8 +815,8 @@ module_declaration: // ==IEEE: module_declaration SYMP->popScope($1); GRAMMARP->endLabel($7,$1,$7); } // - //UNSUP yEXTERN modFront parameter_port_listE portsStarE ';' - //UNSUP { UNSUP } + | yEXTERN modFront parameter_port_listE portsStarE ';' + { $1->v3error("Unsupported: extern module"); } ; modFront: @@ -997,7 +1000,8 @@ interface_declaration: // IEEE: interface_declaration + interface_nonansi_heade if ($3) $1->addStmtp($3); if ($5) $1->addStmtp($5); SYMP->popScope($1); } - //UNSUP yEXTERN intFront parameter_port_listE portsStarE ';' { } + | yEXTERN intFront parameter_port_listE portsStarE ';' + { $1->v3error("Unsupported: extern interface"); } ; intFront: @@ -1040,12 +1044,36 @@ interface_or_generate_item: // ==IEEE: interface_or_generate_item // // module_common_item in interface_item, as otherwise duplicated // // with module_or_generate_item's module_common_item modport_declaration { $$ = $1; } - //UNSUP extern_tf_declaration { $$ = $1; } + | extern_tf_declaration { $$ = $1; } ; //********************************************************************** // Program headers +anonymous_program: // ==IEEE: anonymous_program + // // See the spec - this doesn't change the scope, items still go up "top" + yPROGRAM ';' anonymous_program_itemListE yENDPROGRAM { $1->v3error("Unsupported: Anonymous programs"); $$ = NULL; } + ; + +anonymous_program_itemListE: // IEEE: { anonymous_program_item } + /* empty */ { $$ = NULL; } + | anonymous_program_itemList { $$ = $1; } + ; + +anonymous_program_itemList: // IEEE: { anonymous_program_item } + anonymous_program_item { $$ = $1; } + | anonymous_program_itemList anonymous_program_item { $$ = $1->addNextNull($2); } + ; + +anonymous_program_item: // ==IEEE: anonymous_program_item + task_declaration { $$ = $1; } + | function_declaration { $$ = $1; } + //UNSUP class_declaration { $$ = $1; } + //UNSUP covergroup_declaration { $$ = $1; } + // // class_constructor_declaration is part of function_declaration + | ';' { } + ; + program_declaration: // IEEE: program_declaration + program_nonansi_header + program_ansi_header: // // timeunits_delcarationE is instead in program_item pgmFront parameter_port_listE portsStarE ';' @@ -1055,8 +1083,9 @@ program_declaration: // IEEE: program_declaration + program_nonansi_header + pr if ($5) $1->addStmtp($5); SYMP->popScope($1); GRAMMARP->endLabel($7,$1,$7); } - //UNSUP yEXTERN pgmFront parameter_port_listE portsStarE ';' - //UNSUP { PARSEP->symPopScope(VAstType::PROGRAM); } + | yEXTERN pgmFront parameter_port_listE portsStarE ';' + { $1->v3error("Unsupported: extern program"); + SYMP->popScope($2); } ; pgmFront: @@ -1099,6 +1128,12 @@ program_generate_item: // ==IEEE: program_generate_item | elaboration_system_task { $$ = $1; } ; +extern_tf_declaration: // ==IEEE: extern_tf_declaration + yEXTERN task_prototype ';' { $1->v3error("Unsupported: extern task"); $$ = NULL; } + | yEXTERN function_prototype ';' { $1->v3error("Unsupported: extern function"); $$ = NULL; } + | yEXTERN yFORKJOIN task_prototype ';' { $1->v3error("Unsupported: extern forkjoin"); $$ = NULL; } + ; + modport_declaration: // ==IEEE: modport_declaration yMODPORT modport_itemList ';' { $$ = $2; } ; @@ -1213,6 +1248,7 @@ net_declaration: // IEEE: net_declaration - excluding implict net_declarationFront: // IEEE: beginning of net_declaration net_declRESET net_type strengthSpecE net_scalaredE net_dataType { VARDTYPE($5); } + //UNSUP net_declRESET yINTERCONNECT signingE rangeListE { VARNET($2); VARDTYPE(x); } ; net_declRESET: @@ -1331,7 +1367,8 @@ integer_vector_type: // ==IEEE: integer_atom_type non_integer_type: // ==IEEE: non_integer_type yREAL { $$ = new AstBasicDType($1,AstBasicDTypeKwd::DOUBLE); } | yREALTIME { $$ = new AstBasicDType($1,AstBasicDTypeKwd::DOUBLE); } - //UNSUP ySHORTREAL { $$ = new AstBasicDType($1,AstBasicDTypeKwd::FLOAT); } + | ySHORTREAL { $1->v3error("Unsupported: shortreal (use real instead)"); + $$ = new AstBasicDType($1,AstBasicDTypeKwd::DOUBLE); } ; signingE: // IEEE: signing - plus empty @@ -1659,6 +1696,7 @@ type_declaration: // ==IEEE: type_declaration | yTYPEDEF ySTRUCT idAny ';' { $$ = NULL; $$ = new AstTypedefFwd($1, *$3); SYMP->reinsert($$); PARSEP->tagNodep($$); } | yTYPEDEF yUNION idAny ';' { $$ = NULL; $$ = new AstTypedefFwd($1, *$3); SYMP->reinsert($$); PARSEP->tagNodep($$); } //UNSUP yTYPEDEF yCLASS idAny ';' { $$ = NULL; $$ = new AstTypedefFwd($1, *$3); SYMP->reinsert($$); PARSEP->tagNodep($$); } + //UNSUP yTYPEDEF yINTERFACE yCLASS idAny ';' { ... } ; dtypeAttrListE: @@ -2033,7 +2071,7 @@ packed_dimensionList: // IEEE: { packed_dimension } packed_dimension: // ==IEEE: packed_dimension anyrange { $$ = $1; } - //UNSUP '[' ']' { UNSUP } + | '[' ']' { $1->v3error("Unsupported: [] dimensions"); $$ = NULL; } ; //************************************************ @@ -2849,6 +2887,7 @@ task_declaration: // ==IEEE: task_declaration task_prototype: // ==IEEE: task_prototype yTASK taskId '(' tf_port_listE ')' { $$=$2; $$->addStmtsp($4); $$->prototype(true); SYMP->popScope($$); } + | yTASK taskId { $$=$2; $$->prototype(true); SYMP->popScope($$); } ; function_declaration: // IEEE: function_declaration + function_body_declaration @@ -2860,6 +2899,7 @@ function_declaration: // IEEE: function_declaration + function_body_decl function_prototype: // IEEE: function_prototype yFUNCTION funcId '(' tf_port_listE ')' { $$=$2; $$->addStmtsp($4); $$->prototype(true); SYMP->popScope($$); } + | yFUNCTION funcId { $$=$2; $$->prototype(true); SYMP->popScope($$); } ; funcIsolateE: @@ -3611,8 +3651,6 @@ id: ; idAny: // Any kind of identifier - //UNSUP yaID__aCLASS { $$ = $1; $$=$1; } - //UNSUP yaID__aCOVERGROUP { $$ = $1; $$=$1; } yaID__aPACKAGE { $$ = $1; $$=$1; } | yaID__aTYPE { $$ = $1; $$=$1; } | yaID__ETC { $$ = $1; $$=$1; }