From 6a225d5d008451337bdfb32635934f74d83e08c7 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 8 Aug 2025 05:09:54 -0400 Subject: [PATCH] Internals: Remove AstSysFuncAsTask --- src/V3AstNodeOther.h | 18 ------------------ src/V3EmitCFunc.h | 11 +++++------ src/V3EmitV.cpp | 4 ---- src/V3Width.cpp | 25 +++++++++++-------------- src/verilog.y | 2 +- test_regress/t/t_dump_json.out | 4 ++-- 6 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/V3AstNodeOther.h b/src/V3AstNodeOther.h index 8f3ebc539..af7d445d4 100644 --- a/src/V3AstNodeOther.h +++ b/src/V3AstNodeOther.h @@ -3522,24 +3522,6 @@ public: string emitVerilog() const { return m_isFatal ? "$fatal" : "$stop"; } bool isFatal() const { return m_isFatal; } }; -class AstSysFuncAsTask final : public AstNodeStmt { - // TODO: This is superseded by AstStmtExpr, remove - // Call what is normally a system function (with a return) in a non-return context - // @astgen op1 := lhsp : AstNodeExpr -public: - AstSysFuncAsTask(FileLine* fl, AstNodeExpr* lhsp) - : ASTGEN_SUPER_SysFuncAsTask(fl) { - this->lhsp(lhsp); - } - ASTGEN_MEMBERS_AstSysFuncAsTask; - string verilogKwd() const override { return ""; } - bool isGateOptimizable() const override { return true; } - bool isPredictOptimizable() const override { return true; } - bool isPure() override { return true; } - bool isOutputter() override { return false; } - int instrCount() const override { return 0; } - bool sameNode(const AstNode* /*samep*/) const override { return true; } -}; class AstSystemT final : public AstNodeStmt { // $system used as task // @astgen op1 := lhsp : AstNodeExpr diff --git a/src/V3EmitCFunc.h b/src/V3EmitCFunc.h index 9172013b5..b17552635 100644 --- a/src/V3EmitCFunc.h +++ b/src/V3EmitCFunc.h @@ -1044,11 +1044,6 @@ public: } puts(")"); } - void visit(AstSysFuncAsTask* nodep) override { - if (!nodep->lhsp()->isWide()) putns(nodep, "(void)"); - iterateAndNextConstNull(nodep->lhsp()); - if (!nodep->lhsp()->isWide()) putns(nodep, ";\n"); - } void visit(AstStackTraceF* nodep) override { putns(nodep, "VL_STACKTRACE_N()"); } void visit(AstStackTraceT* nodep) override { putns(nodep, "VL_STACKTRACE();\n"); } void visit(AstSystemT* nodep) override { @@ -1076,7 +1071,11 @@ public: puts(")"); } void visit(AstStmtExpr* nodep) override { - putns(nodep, ""); + if (VN_IS(nodep->exprp()->dtypep()->skipRefp(), VoidDType)) { + putns(nodep, ""); + } else { + putns(nodep, "(void)"); // Prevent unused expression warning in C + } iterateConst(nodep->exprp()); puts(";\n"); } diff --git a/src/V3EmitV.cpp b/src/V3EmitV.cpp index 468417706..81050ab49 100644 --- a/src/V3EmitV.cpp +++ b/src/V3EmitV.cpp @@ -344,10 +344,6 @@ class EmitVBaseVisitorConst VL_NOT_FINAL : public VNVisitorConst { } puts(");\n"); } - void visit(AstSysFuncAsTask* nodep) override { - iterateAndNextConstNull(nodep->lhsp()); - puts(";\n"); - } void visit(AstSysIgnore* nodep) override { putfs(nodep, nodep->verilogKwd()); putbs("("); diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 269006aaf..22a7c78b8 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -1432,6 +1432,11 @@ class WidthVisitor final : public VNVisitor { } } + void visit(AstStmtExpr* nodep) override { + assertAtStatement(nodep); + userIterateAndNext(nodep->exprp(), WidthVP{SELF, BOTH}.p()); + } + void visit(AstImplication* nodep) override { if (m_vup->prelim()) { iterateCheckBool(nodep, "LHS", nodep->lhsp(), BOTH); @@ -4193,16 +4198,12 @@ class WidthVisitor final : public VNVisitor { nodep->dtypeFrom(ftaskp); nodep->classOrPackagep(classp); if (VN_IS(ftaskp, Task)) { - if (!m_vup) { - nodep->dtypeSetVoid(); - } else { - if (m_vup->prelim()) { - nodep->v3error( - "Cannot call a task/void-function as a member function: " - << nodep->prettyNameQ()); - } - nodep->dtypeSetVoid(); + if (m_vup && m_vup->prelim() && !VN_IS(nodep->backp(), StmtExpr)) { + nodep->v3error( + "Cannot call a task/void-function as a member function: " + << nodep->prettyNameQ()); } + nodep->dtypeSetVoid(); } if (withp) nodep->addPinsp(withp); processFTaskRefArgs(nodep); @@ -5766,10 +5767,6 @@ class WidthVisitor final : public VNVisitor { nodep->dtypeSetSigned32(); // Spec says integer return } } - void visit(AstSysFuncAsTask* nodep) override { - assertAtStatement(nodep); - userIterateAndNext(nodep->lhsp(), WidthVP{SELF, BOTH}.p()); - } void visit(AstSystemT* nodep) override { assertAtStatement(nodep); userIterateAndNext(nodep->lhsp(), WidthVP{SELF, BOTH}.p()); @@ -6143,7 +6140,7 @@ class WidthVisitor final : public VNVisitor { visit(static_cast(nodep)); if (nodep->taskp() && VN_IS(nodep->taskp(), Task)) { UASSERT_OBJ(m_vup, nodep, "Function reference where widthed expression expection"); - if (m_vup->prelim()) + if (m_vup->prelim() && !VN_IS(nodep->backp(), StmtExpr)) nodep->v3error( "Cannot call a task/void-function as a function: " << nodep->prettyNameQ()); nodep->dtypeSetVoid(); diff --git a/src/verilog.y b/src/verilog.y index 8f1242b03..8f9051fdf 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -4430,7 +4430,7 @@ system_t_call: // IEEE: system_tf_call (as task) nullptr, nullptr}; } // // Any system function as a task - | system_f_call_or_t { $$ = new AstSysFuncAsTask{$1, $1}; } + | system_f_call_or_t { $$ = new AstStmtExpr{$1, $1}; } ; system_f_call: // IEEE: system_tf_call (as func) diff --git a/test_regress/t/t_dump_json.out b/test_regress/t/t_dump_json.out index 7f456ecf7..3d03126d8 100644 --- a/test_regress/t/t_dump_json.out +++ b/test_regress/t/t_dump_json.out @@ -1028,8 +1028,8 @@ "childDTypep": [ {"type":"BASICDTYPE","name":"string","addr":"(KQ)","loc":"d,231:35,231:41","dtypep":"(KQ)","keyword":"string","generic":false,"rangep": []} ],"delayp": [],"valuep": [],"attrsp": []}, - {"type":"SYSFUNCASTASK","name":"","addr":"(LQ)","loc":"d,232:10,232:18", - "lhsp": [ + {"type":"STMTEXPR","name":"","addr":"(LQ)","loc":"d,232:10,232:18", + "exprp": [ {"type":"RAND","name":"","addr":"(MQ)","loc":"d,232:10,232:18","dtypep":"UNLINKED", "seedp": [ {"type":"DOT","name":"","addr":"(NQ)","loc":"d,232:20,232:21","dtypep":"UNLINKED","colon":false,