diff --git a/Changes b/Changes index e618b01dc..cd10c0fe6 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,8 @@ The contributors that suggested a given feature are shown in []. Thanks! *** Change --quiet-exit to also suppress 'Exiting due to N errors'. +**** Fix parameter type redeclaring a type, #2195. [hdzhangdoc] + * Verilator 4.030 2020-03-08 diff --git a/src/verilog.y b/src/verilog.y index 089331484..f0130d76a 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1010,6 +1010,7 @@ paramPortDeclOrArgList: // IEEE: list_of_param_assignments + { parameter_ paramPortDeclOrArg: // IEEE: param_assignment + parameter_port_declaration // // We combine the two as we can't tell which follows a comma parameter_port_declarationFrontE param_assignment { $$ = $2; } + | parameter_port_declarationTypeFrontE type_assignment { $$ = $2; } ; portsStarE: // IEEE: .* + list_of_ports + list_of_port_declarations + empty @@ -1342,6 +1343,7 @@ local_parameter_declaration: // IEEE: local_parameter_declaration // // See notes in parameter_declaration // // Front must execute first so VARDTYPE is ready before list of vars local_parameter_declarationFront list_of_param_assignments { $$ = $2; } + | local_parameter_declarationTypeFront list_of_type_assignments { $$ = $2; } ; parameter_declaration: // IEEE: parameter_declaration @@ -1350,21 +1352,30 @@ parameter_declaration: // IEEE: parameter_declaration // // we use list_of_param_assignments because for port handling // // it already must accept types, so simpler to have code only one place // // Front must execute first so VARDTYPE is ready before list of vars - parameter_declarationFront list_of_param_assignments { $$ = $2; } + parameter_declarationFront list_of_param_assignments { $$ = $2; } + | parameter_declarationTypeFront list_of_type_assignments { $$ = $2; } ; local_parameter_declarationFront: // IEEE: local_parameter_declaration w/o assignment // // Front must execute first so VARDTYPE is ready before list of vars varLParamReset implicit_typeE { /*VARRESET-in-varLParam*/ VARDTYPE($2); } | varLParamReset data_type { /*VARRESET-in-varLParam*/ VARDTYPE($2); } - | varLParamReset yTYPE { /*VARRESET-in-varLParam*/ VARDTYPE(new AstParseTypeDType($2)); } + ; + +local_parameter_declarationTypeFront: // IEEE: local_parameter_declaration w/o assignment + // // Front must execute first so VARDTYPE is ready before list of vars + varLParamReset yTYPE { /*VARRESET-in-varLParam*/ VARDTYPE(new AstParseTypeDType($2)); } ; parameter_declarationFront: // IEEE: parameter_declaration w/o assignment // // Front must execute first so VARDTYPE is ready before list of vars varGParamReset implicit_typeE { /*VARRESET-in-varGParam*/ VARDTYPE($2); } | varGParamReset data_type { /*VARRESET-in-varGParam*/ VARDTYPE($2); } - | varGParamReset yTYPE { /*VARRESET-in-varGParam*/ VARDTYPE(new AstParseTypeDType($2)); } + ; + +parameter_declarationTypeFront: // IEEE: parameter_declaration w/o assignment + // // Front must execute first so VARDTYPE is ready before list of vars + varGParamReset yTYPE { /*VARRESET-in-varGParam*/ VARDTYPE(new AstParseTypeDType($2)); } ; parameter_port_declarationFrontE: // IEEE: parameter_port_declaration w/o assignment @@ -1373,12 +1384,18 @@ parameter_port_declarationFrontE: // IEEE: parameter_port_declaration w/o assign // // Front must execute first so VARDTYPE is ready before list of vars varGParamReset implicit_typeE { /*VARRESET-in-varGParam*/ VARDTYPE($2); } | varGParamReset data_type { /*VARRESET-in-varGParam*/ VARDTYPE($2); } - | varGParamReset yTYPE { /*VARRESET-in-varGParam*/ VARDTYPE(new AstParseTypeDType($2)); } | varLParamReset implicit_typeE { /*VARRESET-in-varLParam*/ VARDTYPE($2); } | varLParamReset data_type { /*VARRESET-in-varLParam*/ VARDTYPE($2); } - | varLParamReset yTYPE { /*VARRESET-in-varLParam*/ VARDTYPE(new AstParseTypeDType($2)); } | implicit_typeE { /*VARRESET-in-varGParam*/ VARDTYPE($1); } | data_type { /*VARRESET-in-varGParam*/ VARDTYPE($1); } + ; + +parameter_port_declarationTypeFrontE: // IEEE: parameter_port_declaration w/o assignment + // // IEEE: parameter_declaration (minus assignment) + // // IEEE: local_parameter_declaration (minus assignment) + // // Front must execute first so VARDTYPE is ready before list of vars + varGParamReset yTYPE { /*VARRESET-in-varGParam*/ VARDTYPE(new AstParseTypeDType($2)); } + | varLParamReset yTYPE { /*VARRESET-in-varLParam*/ VARDTYPE(new AstParseTypeDType($2)); } | yTYPE { /*VARRESET-in-varGParam*/ VARDTYPE(new AstParseTypeDType($1)); } ; @@ -2348,8 +2365,7 @@ packed_dimension: // ==IEEE: packed_dimension param_assignment: // ==IEEE: param_assignment // // IEEE: constant_param_expression // // constant_param_expression: '$' is in expr - // // note exptOrDataType being a data_type is only for yPARAMETER yTYPE - id/*new-parameter*/ variable_dimensionListE sigAttrListE '=' exprOrDataType + 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); @@ -2362,6 +2378,17 @@ list_of_param_assignments: // ==IEEE: list_of_param_assignments | list_of_param_assignments ',' param_assignment { $$ = $1; $1->addNext($3); } ; +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); } + ; + +list_of_type_assignments: // ==IEEE: list_of_type_assignments + type_assignment { $$ = $1; } + | list_of_type_assignments ',' type_assignment { $$ = $1; $1->addNext($3); } + ; + list_of_defparam_assignments: //== IEEE: list_of_defparam_assignments defparam_assignment { $$ = $1; } | list_of_defparam_assignments ',' defparam_assignment { $$ = $1->addNext($3); } diff --git a/test_regress/t/t_param_type3.pl b/test_regress/t/t_param_type3.pl new file mode 100755 index 000000000..9abe0d581 --- /dev/null +++ b/test_regress/t/t_param_type3.pl @@ -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. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile( + ); + +#execute( +# check_finished => 1, +# ); + +ok(1); +1; diff --git a/test_regress/t/t_param_type3.v b/test_regress/t/t_param_type3.v new file mode 100644 index 000000000..d0fc19307 --- /dev/null +++ b/test_regress/t/t_param_type3.v @@ -0,0 +1,50 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2012 by Iztok Jeras. +// SPDX-License-Identifier: CC0-1.0 + +typedef logic T_t; + +module t (/*AUTOARG*/ + // Outputs + o, o2, + // Inputs + i + ); + + input T_t i; + output T_t o; + output T_t o2; + + sub #(.T_t(T_t)) + sub (.i, .o); + + sub2 #(.T_t(T_t)) + sub2 (.i, .o(o2)); + +endmodule + +module sub (i,o); + parameter type T_t = logic; + localparam type T2_t = T_t; + input T_t i; + output T2_t o; + assign o = i; +endmodule + +module sub2 + #( + parameter type T_t = logic, + localparam type T2_t = T_t + ) + ( + input T_t i, + output T_t o + ); + assign o = i; +endmodule + +// Local Variables: +// verilog-typedef-regexp: "_t$" +// End: diff --git a/test_regress/t/t_param_type_bad.out b/test_regress/t/t_param_type_bad.out index e4269b2d1..1f3353b19 100644 --- a/test_regress/t/t_param_type_bad.out +++ b/test_regress/t/t_param_type_bad.out @@ -1,4 +1,4 @@ -%Error: t/t_param_type_bad.v:9:20: Parameter type's initial value isn't a type: 'bad2' +%Error: t/t_param_type_bad.v:9:27: syntax error, unexpected INTEGER NUMBER, expecting TYPE-IDENTIFIER localparam type bad2 = 2; - ^~~~ + ^ %Error: Exiting due to diff --git a/test_regress/t/t_param_type_bad2.out b/test_regress/t/t_param_type_bad2.out index 25e6fc5ee..5ab3e9fca 100644 --- a/test_regress/t/t_param_type_bad2.out +++ b/test_regress/t/t_param_type_bad2.out @@ -1,9 +1,7 @@ -%Error: t/t_param_type_bad2.v:8:19: Operator VAR 't' expected non-datatype Initial value but 'logic' is a datatype. - : ... In instance t +%Error: t/t_param_type_bad2.v:8:24: syntax error, unexpected ';', expecting "'{" localparam t = logic; - ^~~~~ -%Error: t/t_param_type_bad2.v:9:20: Operator VAR 't2' expected non-datatype Initial value but 'real' is a datatype. - : ... In instance t + ^ +%Error: t/t_param_type_bad2.v:9:28: syntax error, unexpected ';', expecting "'{" localparam t2 = realtime; - ^~~~~~~~ + ^ %Error: Exiting due to