From 2b21697b868a203b0184e2c321b6f8c62dfd9ee3 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 18 Mar 2023 17:26:36 -0400 Subject: [PATCH] Support class extends of package::class. --- Changes | 1 + src/V3LinkDot.cpp | 26 ++++++++++++++++-------- test_regress/t/t_class_extends2.out | 5 ----- test_regress/t/t_class_extends2.pl | 11 ++++++---- test_regress/t/t_class_extends_colon.out | 5 ----- test_regress/t/t_class_extends_colon.pl | 11 ++++++---- 6 files changed, 33 insertions(+), 26 deletions(-) delete mode 100644 test_regress/t/t_class_extends2.out delete mode 100644 test_regress/t/t_class_extends_colon.out diff --git a/Changes b/Changes index 849ff3ca8..e913ad400 100644 --- a/Changes +++ b/Changes @@ -17,6 +17,7 @@ Verilator 5.009 devel * Add --public-params flag (#3990). [Andrew Nolte] * Support complicated IEEE 'for' assignments. * Support $fopen as an expression. +* Support class extends of package::class. * Change ZERODLY to a warning. * Fix UNDRIVEN warning seg fault (#3989). [Felix Neumärker] * Fix symbol entries when inheriting classes (#3995) (#3996). [Krzysztof Boroński] diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 9a4cdffcd..05440ea5b 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -3272,17 +3272,26 @@ private: " (IEEE 1800-2017 8.13)"); } if (cextp->childDTypep() || cextp->dtypep()) continue; // Already converted - if (VN_IS(cextp->classOrPkgsp(), Dot)) { - itemp->v3warn(E_UNSUPPORTED, "Unsupported: Hierarchical class references"); - continue; + AstNode* cprp = cextp->classOrPkgsp(); + VSymEnt* lookSymp = m_curSymp; + if (AstDot* const dotp = VN_CAST(cextp->classOrPkgsp(), Dot)) { + dotp->user3(true); + if (AstClassOrPackageRef* lookNodep + = VN_CAST(dotp->lhsp(), ClassOrPackageRef)) { + iterate(lookNodep); + cprp = dotp->rhsp(); + lookSymp = m_statep->getNodeSym(lookNodep->classOrPackagep()); + } else { + dotp->lhsp()->v3error("Attempting to extend" // LCOV_EXCL_LINE + " using non-class under dot"); + } } - AstClassOrPackageRef* const cpackagerefp - = VN_CAST(cextp->classOrPkgsp(), ClassOrPackageRef); + AstClassOrPackageRef* const cpackagerefp = VN_CAST(cprp, ClassOrPackageRef); if (VL_UNCOVERABLE(!cpackagerefp)) { // Linking the extend gives an error before this is hit cextp->v3error("Attempting to extend using non-class"); // LCOV_EXCL_LINE } else { - VSymEnt* const foundp = m_curSymp->findIdFallback(cpackagerefp->name()); + VSymEnt* const foundp = lookSymp->findIdFallback(cpackagerefp->name()); if (foundp) { AstClassRefDType* classRefDtypep = nullptr; AstClass* classp = VN_CAST(foundp->nodep(), Class); @@ -3353,8 +3362,9 @@ private: if (!cextp->isImplements()) { m_curSymp->importFromClass(m_statep->symsp(), srcp); } - VL_DO_DANGLING(cpackagerefp->unlinkFrBack()->deleteTree(), - cpackagerefp); + VL_DO_DANGLING( + cextp->classOrPkgsp()->unlinkFrBack()->deleteTree(), + cpackagerefp); } } } else { diff --git a/test_regress/t/t_class_extends2.out b/test_regress/t/t_class_extends2.out deleted file mode 100644 index 9b587f905..000000000 --- a/test_regress/t/t_class_extends2.out +++ /dev/null @@ -1,5 +0,0 @@ -%Error-UNSUPPORTED: t/t_class_extends2.v:18:19: Unsupported: Hierarchical class references - 18 | class Ext extends Pkg::Base0; - | ^~~ - ... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest -%Error: Exiting due to diff --git a/test_regress/t/t_class_extends2.pl b/test_regress/t/t_class_extends2.pl index 8a9b721f2..696e24d17 100755 --- a/test_regress/t/t_class_extends2.pl +++ b/test_regress/t/t_class_extends2.pl @@ -8,11 +8,14 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di # Version 2.0. # SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 -scenarios(linter => 1); +scenarios(simulator => 1); -lint( - fails => $Self->{vlt}, - expect_filename => $Self->{golden_filename}, +compile( + make_flags => 'VM_PARALLEL_BUILDS=1', # bug2775 + ); + +execute( + check_finished => 1, ); ok(1); diff --git a/test_regress/t/t_class_extends_colon.out b/test_regress/t/t_class_extends_colon.out deleted file mode 100644 index ae67bbf79..000000000 --- a/test_regress/t/t_class_extends_colon.out +++ /dev/null @@ -1,5 +0,0 @@ -%Error-UNSUPPORTED: t/t_class_extends_colon.v:20:21: Unsupported: Hierarchical class references - 20 | class Cls12 extends Pkg::Icls1; - | ^~~ - ... For error description see https://verilator.org/warn/UNSUPPORTED?v=latest -%Error: Exiting due to diff --git a/test_regress/t/t_class_extends_colon.pl b/test_regress/t/t_class_extends_colon.pl index 8a9b721f2..696e24d17 100755 --- a/test_regress/t/t_class_extends_colon.pl +++ b/test_regress/t/t_class_extends_colon.pl @@ -8,11 +8,14 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di # Version 2.0. # SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 -scenarios(linter => 1); +scenarios(simulator => 1); -lint( - fails => $Self->{vlt}, - expect_filename => $Self->{golden_filename}, +compile( + make_flags => 'VM_PARALLEL_BUILDS=1', # bug2775 + ); + +execute( + check_finished => 1, ); ok(1);