Add error when use parameters without value, bug1424.

This commit is contained in:
Wilson Snyder 2019-04-30 19:16:41 -04:00
parent 274b2002c2
commit 08d041cb93
7 changed files with 57 additions and 22 deletions

View File

@ -6,6 +6,8 @@ The contributors that suggested a given feature are shown in []. Thanks!
**** Support '#' comments in $readmem, bug1411. [Frederick Requin]
**** Add error when use parameters without value, bug1424. [Peter Gerst]
**** Fix missing VL_SHIFTL_ errors, bug1412, bug1415. [Larry Lee]
**** Fix MinGW GCC 6 printf formats, bug1413. [Sergey Kvachonok]

View File

@ -271,21 +271,29 @@ private:
// Make sure all parameters are constantified
virtual void visit(AstVar* nodep) {
if (!nodep->user5SetOnce()) { // Process once
if (!nodep->user5SetOnce()) { // Process once
iterateChildren(nodep);
if (nodep->isParam()) {
if (!nodep->valuep()) { nodep->v3fatalSrc("Parameter without initial value"); }
V3Const::constifyParamsEdit(nodep); // The variable, not just the var->init()
if (!VN_IS(nodep->valuep(), Const)) { // Complex init, like an array
// Make a new INITIAL to set the value.
// This allows the normal array/struct handling code to properly initialize the parameter
nodep->addNext(new AstInitial(nodep->fileline(),
new AstAssign(nodep->fileline(),
new AstVarRef(nodep->fileline(), nodep, true),
nodep->valuep()->cloneTree(true))));
}
}
}
if (nodep->isParam()) {
if (!nodep->valuep()) {
nodep->v3error("Parameter without initial value is never given value"
<<" (IEEE 1800-2017 6.20.1): "
<<nodep->prettyName());
} else {
V3Const::constifyParamsEdit(nodep); // The variable, not just the var->init()
if (!VN_IS(nodep->valuep(), Const)) { // Complex init, like an array
// Make a new INITIAL to set the value.
// This allows the normal array/struct handling code to properly
// initialize the parameter.
nodep->addNext(
new AstInitial(nodep->fileline(),
new AstAssign(
nodep->fileline(),
new AstVarRef(nodep->fileline(), nodep, true),
nodep->valuep()->cloneTree(true))));
}
}
}
}
}
// Make sure varrefs cause vars to constify before things above
virtual void visit(AstVarRef* nodep) {

View File

@ -2085,7 +2085,9 @@ param_assignment<varp>: // ==IEEE: param_assignment
id/*new-parameter*/ variable_dimensionListE sigAttrListE '=' exprOrDataType
/**/ { $$ = VARDONEA($<fl>1,*$1, $2, $3); $$->valuep($5); }
| id/*new-parameter*/ variable_dimensionListE sigAttrListE
/**/ { $$ = VARDONEA($<fl>1,*$1, $2, $3); }
/**/ { $$ = VARDONEA($<fl>1,*$1, $2, $3);
if ($<fl>1->language() < V3LangCode::L1800_2009) {
$<fl>1->v3error("Parameter requires default value, or use IEEE 1800-2009 or later."); } }
;
list_of_param_assignments<varp>: // ==IEEE: list_of_param_assignments

View File

@ -0,0 +1,2 @@
%Error: t/t_param_default_bad.v:6: Parameter without initial value is never given value (IEEE 1800-2017 6.20.1): Foo
%Error: Exiting due to

View File

@ -7,15 +7,13 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
scenarios(simulator => 1);
scenarios(vlt => 1);
compile(
fails => 1,
expect =>
'%Error: Internal Error: t/t_param_default_bad.v:6: ../V3Param.cpp:\d+: Parameter without initial value
%Error: Internal Error: See the manual and http://www.veripool.org/verilator for more assistance.
.*%Error: Command Failed.*',
);
v_flags2 => ["--lint-only"],
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;

View File

@ -0,0 +1,2 @@
%Error: t/t_param_default_bad.v:6: Parameter requires default value, or use IEEE 1800-2009 or later.
%Error: Exiting due to

View File

@ -0,0 +1,21 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
scenarios(vlt => 1);
top_filename("t/t_param_default_bad.v");
compile(
v_flags2 => ["--lint-only --language 1800-2005"],
fails => 1,
expect_filename => $Self->{golden_filename},
);
ok(1);
1;