From 8255f3f9fe76554e837e557463ee2f5bf69d74d5 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 25 May 2020 18:41:47 -0400 Subject: [PATCH] Internals: Parser cleanup of parameters, first part. --- src/V3LinkParse.cpp | 4 ++++ src/verilog.y | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index ed78d7546..aae9f23c3 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -173,6 +173,10 @@ private: virtual void visit(AstVar* nodep) VL_OVERRIDE { cleanFileline(nodep); + if (nodep->isParam() && !nodep->valuep() + && nodep->fileline()->language() < V3LangCode::L1800_2009) { + nodep->v3error("Parameter requires default value, or use IEEE 1800-2009 or later."); + } if (VN_IS(nodep->subDTypep(), ParseTypeDType)) { // It's a parameter type. Use a different node type for this. AstNodeDType* dtypep = VN_CAST(nodep->valuep(), NodeDType); diff --git a/src/verilog.y b/src/verilog.y index 908a8a720..28ab64e8c 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -2431,12 +2431,14 @@ packed_dimension: // ==IEEE: packed_dimension param_assignment: // ==IEEE: param_assignment // // IEEE: constant_param_expression // // constant_param_expression: '$' is in expr - id/*new-parameter*/ variable_dimensionListE sigAttrListE '=' expr - /**/ { $$ = VARDONEA($1,*$1, $2, $3); $$->valuep($5); } - | id/*new-parameter*/ variable_dimensionListE sigAttrListE - /**/ { $$ = VARDONEA($1,*$1, $2, $3); - if ($1->language() < V3LangCode::L1800_2009) { - $1->v3error("Parameter requires default value, or use IEEE 1800-2009 or later."); } } + id/*new-parameter*/ variable_dimensionListE sigAttrListE param_assignmentEqE + { $$ = VARDONEA($1, *$1, $2, $3); if ($4) $$->valuep($4); } + ; + +param_assignmentEqE: //IEEE: part of param_assignment ('=' expr or empty) + // // constant_param_expression: '$' is in expr + /*empty*/ { $$ = NULL; } + | '=' expr { $$ = $2; } ; list_of_param_assignments: // ==IEEE: list_of_param_assignments @@ -2447,7 +2449,7 @@ list_of_param_assignments: // ==IEEE: list_of_param_assignments type_assignment: // ==IEEE: type_assignment // // note exptOrDataType being a data_type is only for yPARAMETER yTYPE idAny/*new-parameter*/ sigAttrListE '=' data_type - /**/ { $$ = VARDONEA($1,*$1, NULL, $2); $$->valuep($4); } + { $$ = VARDONEA($1, *$1, NULL, $2); $$->valuep($4); } ; list_of_type_assignments: // ==IEEE: list_of_type_assignments