From 47a7e75841ef9efba4c1843282b785238e87e6ca Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Wed, 22 Feb 2023 11:26:25 +0100 Subject: [PATCH] Fix subsequent parameter declarations (#3969) --- src/verilog.y | 15 ++++++--------- test_regress/t/t_param_type5.pl | 21 +++++++++++++++++++++ test_regress/t/t_param_type5.v | 27 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 9 deletions(-) create mode 100755 test_regress/t/t_param_type5.pl create mode 100644 test_regress/t/t_param_type5.v diff --git a/src/verilog.y b/src/verilog.y index fba31aa97..ce1ad406a 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -1876,7 +1876,11 @@ parameter_port_declarationFrontE: // IEEE: local_ or parameter_port_declaration // // Front must execute first so VARDTYPE is ready before list of vars varParamReset implicit_typeE { /*VARRESET-in-varParam*/ VARDTYPE($2); } | varParamReset data_type { /*VARRESET-in-varParam*/ VARDTYPE($2); } - | implicit_typeE { /*VARRESET-in-varParam*/ VARDTYPE($1); } + | implicit_typeE + { /*VARRESET-in-varParam*/ + // Keep previous type to handle subsequent declarations. + // This rule is also used when the previous parameter is a type parameter + } | data_type { /*VARRESET-in-varParam*/ VARDTYPE($1); } ; @@ -3058,14 +3062,7 @@ param_assignment: // ==IEEE: param_assignment // // IEEE: constant_param_expression // // constant_param_expression: '$' is in expr id/*new-parameter*/ variable_dimensionListE sigAttrListE exprOrDataTypeEqE - { // To handle #(type A=int, B=A) and properly imply B - // as a type (for parsing) we need to detect "A" is a type - if (AstNodeDType* const refp = VN_CAST($4, NodeDType)) { - if (VSymEnt* const foundp = SYMP->symCurrentp()->findIdFallback(refp->name())) { - UINFO(9, "declaring type via param assignment" << foundp->nodep() << endl); - VARDTYPE(new AstParseTypeDType{$1}); - SYMP->reinsert(foundp->nodep()->cloneTree(false), nullptr, *$1); }} - $$ = VARDONEA($1, *$1, $2, $3); + { $$ = VARDONEA($1, *$1, $2, $3); if ($4) $$->valuep($4); } ; diff --git a/test_regress/t/t_param_type5.pl b/test_regress/t/t_param_type5.pl new file mode 100755 index 000000000..b46d46042 --- /dev/null +++ b/test_regress/t/t_param_type5.pl @@ -0,0 +1,21 @@ +#!/usr/bin/env 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_type5.v b/test_regress/t/t_param_type5.v new file mode 100644 index 000000000..cd73625c7 --- /dev/null +++ b/test_regress/t/t_param_type5.v @@ -0,0 +1,27 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2023 by Antmicro Ltd. +// SPDX-License-Identifier: CC0-1.0 + +class ParamClass #(string P = "ABC", R = "GDF"); +endclass + +module t #(parameter int A = 0, B = 1, C = 2, type D = int, E = string); + parameter bit F = 1'b0, G = 1'b1; + parameter type H = int, I = string; + E str1 = "abc"; + I str2 = ""; + initial begin + automatic ParamClass param_class = new; + if ($typename(B) != "int") $stop; + if ($typename(C) != "int") $stop; + if (str1.len() != 3) $stop; + if ($typename(G) != "bit") $stop; + if (str2.len() != 0) $stop; + if ($typename(param_class.R) != "string") $stop; + + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule