diff --git a/Changes b/Changes index f4453b7ce..a091c1f48 100644 --- a/Changes +++ b/Changes @@ -23,6 +23,8 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix splitting eval functions with --output-split-cfuncs (#2368). [Geza Lore] +**** Fix queues as class members (#2525). [nanduraj1] + * Verilator 4.040 2020-08-15 diff --git a/include/verilated_vcd_sc.h b/include/verilated_vcd_sc.h index 9e69ebe1e..15d0aae61 100644 --- a/include/verilated_vcd_sc.h +++ b/include/verilated_vcd_sc.h @@ -66,9 +66,9 @@ private: virtual void set_time_unit(double v, sc_time_unit tu) {} // LCOV_EXCL_LINE //-------------------------------------------------- - // SystemC 2.1.v1 -# define DECL_TRACE_METHOD_A(tp) virtual void trace(const tp& object, const std::string& name); -# define DECL_TRACE_METHOD_B(tp) \ +// SystemC 2.1.v1 +#define DECL_TRACE_METHOD_A(tp) virtual void trace(const tp& object, const std::string& name); +#define DECL_TRACE_METHOD_B(tp) \ virtual void trace(const tp& object, const std::string& name, int width); virtual void write_comment(const std::string&); diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 436ebc44f..081dcbd10 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -2358,7 +2358,7 @@ private: newp->didWidth(true); } else if (nodep->name() == "delete") { // function void delete([input integer index]) methodOkArguments(nodep, 0, 1); - methodCallLValue(nodep, nodep->fromp(), true); + methodCallLValueRecurse(nodep, nodep->fromp(), true); if (!nodep->pinsp()) { newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), "clear", nullptr); @@ -2387,20 +2387,24 @@ private: VL_DANGLING(index_exprp); // May have been edited return VN_CAST(nodep->pinsp(), Arg)->exprp(); } - void methodCallLValue(AstMethodCall* nodep, AstNode* childp, bool lvalue) { - AstNodeVarRef* varrefp = VN_CAST(childp, NodeVarRef); - if (!varrefp) { + void methodCallLValueRecurse(AstMethodCall* nodep, AstNode* childp, bool lvalue) { + if (AstNodeVarRef* varrefp = VN_CAST(childp, NodeVarRef)) { + if (lvalue) varrefp->lvalue(true); + } else if (AstMemberSel* ichildp = VN_CAST(childp, MemberSel)) { + methodCallLValueRecurse(nodep, ichildp->fromp(), lvalue); + } else if (AstNodeSel* ichildp = VN_CAST(childp, NodeSel)) { + methodCallLValueRecurse(nodep, ichildp->fromp(), lvalue); + } else { + UINFO(1, " Related node: " << childp << endl); nodep->v3warn(E_UNSUPPORTED, "Unsupported: Non-variable on LHS of built-in method '" << nodep->prettyName() << "'"); - } else { - if (lvalue) varrefp->lvalue(true); } } void methodCallDyn(AstMethodCall* nodep, AstDynArrayDType* adtypep) { AstCMethodHard* newp = nullptr; if (nodep->name() == "at") { // Created internally for [] methodOkArguments(nodep, 1, 1); - methodCallLValue(nodep, nodep->fromp(), true); + methodCallLValueRecurse(nodep, nodep->fromp(), true); newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), "at", nullptr); newp->dtypeFrom(adtypep->subDTypep()); @@ -2415,7 +2419,7 @@ private: newp->protect(false); } else if (nodep->name() == "delete") { // function void delete() methodOkArguments(nodep, 0, 0); - methodCallLValue(nodep, nodep->fromp(), true); + methodCallLValueRecurse(nodep, nodep->fromp(), true); newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), "clear", nullptr); newp->makeStatement(); @@ -2433,7 +2437,7 @@ private: AstCMethodHard* newp = nullptr; if (nodep->name() == "at") { // Created internally for [] methodOkArguments(nodep, 1, 1); - methodCallLValue(nodep, nodep->fromp(), true); + methodCallLValueRecurse(nodep, nodep->fromp(), true); newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), "at", nullptr); newp->dtypeFrom(adtypep->subDTypep()); @@ -2449,7 +2453,7 @@ private: newp->protect(false); } else if (nodep->name() == "delete") { // function void delete([input integer index]) methodOkArguments(nodep, 0, 1); - methodCallLValue(nodep, nodep->fromp(), true); + methodCallLValueRecurse(nodep, nodep->fromp(), true); if (!nodep->pinsp()) { newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), "clear", nullptr); @@ -2476,7 +2480,7 @@ private: } } else if (nodep->name() == "insert") { methodOkArguments(nodep, 2, 2); - methodCallLValue(nodep, nodep->fromp(), true); + methodCallLValueRecurse(nodep, nodep->fromp(), true); AstNode* index_exprp = methodCallQueueIndexExpr(nodep); AstArg* argp = VN_CAST(nodep->pinsp()->nextp(), Arg); iterateCheckTyped(nodep, "insert value", argp->exprp(), adtypep->subDTypep(), BOTH); @@ -2497,7 +2501,7 @@ private: } } else if (nodep->name() == "pop_front" || nodep->name() == "pop_back") { methodOkArguments(nodep, 0, 0); - methodCallLValue(nodep, nodep->fromp(), true); + methodCallLValueRecurse(nodep, nodep->fromp(), true); newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), nodep->name(), nullptr); newp->dtypeFrom(adtypep->subDTypep()); @@ -2506,7 +2510,7 @@ private: if (!nodep->firstAbovep()) { newp->makeStatement(); } } else if (nodep->name() == "push_back" || nodep->name() == "push_front") { methodOkArguments(nodep, 1, 1); - methodCallLValue(nodep, nodep->fromp(), true); + methodCallLValueRecurse(nodep, nodep->fromp(), true); AstArg* argp = VN_CAST(nodep->pinsp(), Arg); iterateCheckTyped(nodep, "push value", argp->exprp(), adtypep->subDTypep(), BOTH); newp = new AstCMethodHard(nodep->fileline(), nodep->fromp()->unlinkFrBack(), diff --git a/test_regress/t/t_queue_class.pl b/test_regress/t/t_queue_class.pl new file mode 100755 index 000000000..b46d46042 --- /dev/null +++ b/test_regress/t/t_queue_class.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_queue_class.v b/test_regress/t/t_queue_class.v new file mode 100644 index 000000000..7424ff429 --- /dev/null +++ b/test_regress/t/t_queue_class.v @@ -0,0 +1,32 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2019 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +module t (/*AUTOARG*/); + class Cls; + int que[$]; + + task push_data(int val); + que.push_back(val); + endtask + endclass + + initial begin + Cls c2 [1:0]; + + c2[0] = new(); + + c2[0].push_data(20); // Works + + if (c2[0].que.size() != 1) $stop; + + c2[0].que.push_back(10); // Unsupported + if (c2[0].que.size() != 2) $stop; + + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule