diff --git a/src/V3AstInlines.h b/src/V3AstInlines.h index 8759e1bea..8c5d67b49 100644 --- a/src/V3AstInlines.h +++ b/src/V3AstInlines.h @@ -77,6 +77,12 @@ int AstNodeArrayDType::lo() const VL_MT_STABLE { return rangep()->loConst(); } int AstNodeArrayDType::elementsConst() const VL_MT_STABLE { return rangep()->elementsConst(); } VNumRange AstNodeArrayDType::declRange() const VL_MT_STABLE { return VNumRange{left(), right()}; } +AstFuncRef::AstFuncRef(FileLine* fl, AstFunc* taskp, AstNodeExpr* pinsp) + : ASTGEN_SUPER_FuncRef(fl, taskp->name(), pinsp) { + this->taskp(taskp); + dtypeFrom(taskp); +} + AstRange::AstRange(FileLine* fl, int left, int right) : ASTGEN_SUPER_Range(fl) { leftp(new AstConst{fl, static_cast(left)}); @@ -96,11 +102,6 @@ int AstRange::rightConst() const VL_MT_STABLE { return (constp ? constp->toSInt() : 0); } -int AstQueueDType::boundConst() const VL_MT_STABLE { - AstConst* const constp = VN_CAST(boundp(), Const); - return (constp ? constp->toSInt() : 0); -} - AstPin::AstPin(FileLine* fl, int pinNum, AstVarRef* varname, AstNode* exprp) : ASTGEN_SUPER_Pin(fl) , m_pinNum{pinNum} @@ -127,6 +128,17 @@ AstPackArrayDType::AstPackArrayDType(FileLine* fl, AstNodeDType* dtp, AstRange* widthForce(width, width); } +int AstQueueDType::boundConst() const VL_MT_STABLE { + AstConst* const constp = VN_CAST(boundp(), Const); + return (constp ? constp->toSInt() : 0); +} + +AstTaskRef::AstTaskRef(FileLine* fl, AstTask* taskp, AstNodeExpr* pinsp) + : ASTGEN_SUPER_TaskRef(fl, taskp->name(), pinsp) { + this->taskp(taskp); + dtypeSetVoid(); +} + int AstBasicDType::hi() const { return (rangep() ? rangep()->hiConst() : m.m_nrange.hi()); } int AstBasicDType::lo() const { return (rangep() ? rangep()->loConst() : m.m_nrange.lo()); } int AstBasicDType::elements() const { diff --git a/src/V3AstNodeExpr.h b/src/V3AstNodeExpr.h index a97853dd2..00ab118b6 100644 --- a/src/V3AstNodeExpr.h +++ b/src/V3AstNodeExpr.h @@ -4375,6 +4375,7 @@ class AstFuncRef final : public AstNodeFTaskRef { // A reference to a function bool m_superReference = false; // Called with super reference public: + inline AstFuncRef(FileLine* fl, AstFunc* taskp, AstNodeExpr* pinsp); AstFuncRef(FileLine* fl, AstParseRef* namep, AstNodeExpr* pinsp) : ASTGEN_SUPER_FuncRef(fl, (AstNode*)namep, pinsp) {} AstFuncRef(FileLine* fl, const string& name, AstNodeExpr* pinsp) @@ -4415,6 +4416,7 @@ class AstTaskRef final : public AstNodeFTaskRef { // A reference to a task bool m_superReference = false; // Called with super reference public: + inline AstTaskRef(FileLine* fl, AstTask* taskp, AstNodeExpr* pinsp); AstTaskRef(FileLine* fl, AstParseRef* namep, AstNodeExpr* pinsp) : ASTGEN_SUPER_TaskRef(fl, (AstNode*)namep, pinsp) { dtypeSetVoid(); diff --git a/src/V3Fork.cpp b/src/V3Fork.cpp index 30dc0fa82..21485ce98 100644 --- a/src/V3Fork.cpp +++ b/src/V3Fork.cpp @@ -603,9 +603,7 @@ class ForkVisitor final : public VNVisitor { m_modp->addStmtsp(taskp); UINFO(9, "new " << taskp << endl); - AstTaskRef* const taskrefp - = new AstTaskRef{nodep->fileline(), taskp->name(), m_capturedVarRefsp}; - taskrefp->taskp(taskp); + AstTaskRef* const taskrefp = new AstTaskRef{nodep->fileline(), taskp, m_capturedVarRefsp}; AstStmtExpr* const taskcallp = taskrefp->makeStmt(); // Replaced nodes will be revisited, so we don't need to "lift" the arguments // as captures in case of nested forks. diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index a6c259d6d..15cfccf47 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -1105,13 +1105,11 @@ class CaptureVisitor final : public VNVisitor { AstNodeExpr* const pinsp = nodep->pinsp() ? nodep->pinsp()->unlinkFrBackWithNext() : nullptr; AstNodeFTaskRef* taskRefp = nullptr; - if (VN_IS(nodep->taskp(), Task)) - taskRefp = new AstTaskRef{nodep->fileline(), nodep->name(), pinsp}; - else if (VN_IS(nodep->taskp(), Func)) - taskRefp = new AstFuncRef{nodep->fileline(), nodep->name(), pinsp}; + if (AstTask* const taskp = VN_CAST(nodep->taskp(), Task)) + taskRefp = new AstTaskRef{nodep->fileline(), taskp, pinsp}; + else if (AstFunc* const taskp = VN_CAST(nodep->taskp(), Func)) + taskRefp = new AstFuncRef{nodep->fileline(), taskp, pinsp}; UASSERT_OBJ(taskRefp, nodep, "Node needs to point to regular method"); - taskRefp->taskp(nodep->taskp()); - taskRefp->dtypep(nodep->dtypep()); fixupClassOrPackage(nodep->taskp(), taskRefp); taskRefp->user1(nodep->user1()); nodep->replaceWith(taskRefp); @@ -1596,9 +1594,7 @@ class RandomizeVisitor final : public VNVisitor { } void addPrePostCall(AstClass* const classp, AstFunc* const funcp, const string& name) { if (AstTask* userFuncp = VN_CAST(m_memberMap.findMember(classp, name), Task)) { - AstTaskRef* const callp - = new AstTaskRef{userFuncp->fileline(), userFuncp->name(), nullptr}; - callp->taskp(userFuncp); + AstTaskRef* const callp = new AstTaskRef{userFuncp->fileline(), userFuncp, nullptr}; funcp->addStmtsp(callp->makeStmt()); } } @@ -1940,8 +1936,7 @@ class RandomizeVisitor final : public VNVisitor { constrp->user2p(taskp); } AstTaskRef* const setupTaskRefp - = new AstTaskRef{constrp->fileline(), taskp->name(), nullptr}; - setupTaskRefp->taskp(taskp); + = new AstTaskRef{constrp->fileline(), taskp, nullptr}; setupTaskRefp->classOrPackagep(classp); AstTask* const setupAllTaskp = getCreateConstraintSetupFunc(nodep); @@ -1951,8 +1946,7 @@ class RandomizeVisitor final : public VNVisitor { if (AstTask* const resizeTaskp = VN_CAST(constrp->user3p(), Task)) { AstTask* const resizeAllTaskp = getCreateAggrResizeTask(nodep); AstTaskRef* const resizeTaskRefp - = new AstTaskRef{constrp->fileline(), resizeTaskp->name(), nullptr}; - resizeTaskRefp->taskp(resizeTaskp); + = new AstTaskRef{constrp->fileline(), resizeTaskp, nullptr}; resizeTaskRefp->classOrPackagep(classp); resizeAllTaskp->addStmtsp(resizeTaskRefp->makeStmt()); } @@ -1965,8 +1959,7 @@ class RandomizeVisitor final : public VNVisitor { }); randomizep->addStmtsp(implementConstraintsClear(fl, genp)); AstTask* setupAllTaskp = getCreateConstraintSetupFunc(nodep); - AstTaskRef* const setupTaskRefp = new AstTaskRef{fl, setupAllTaskp->name(), nullptr}; - setupTaskRefp->taskp(setupAllTaskp); + AstTaskRef* const setupTaskRefp = new AstTaskRef{fl, setupAllTaskp, nullptr}; randomizep->addStmtsp(setupTaskRefp->makeStmt()); AstNodeModule* const genModp = VN_AS(genp->user2p(), NodeModule); @@ -1994,17 +1987,14 @@ class RandomizeVisitor final : public VNVisitor { if (AstTask* const resizeAllTaskp = VN_AS(m_memberMap.findMember(nodep, "__Vresize_constrained_arrays"), Task)) { - AstTaskRef* const resizeTaskRefp = new AstTaskRef{fl, resizeAllTaskp->name(), nullptr}; - resizeTaskRefp->taskp(resizeAllTaskp); + AstTaskRef* const resizeTaskRefp = new AstTaskRef{fl, resizeAllTaskp, nullptr}; randomizep->addStmtsp(resizeTaskRefp->makeStmt()); } AstFunc* const basicRandomizep = V3Randomize::newRandomizeFunc(m_memberMap, nodep, "__Vbasic_randomize"); addBasicRandomizeBody(basicRandomizep, nodep, randModeVarp); - AstFuncRef* const basicRandomizeCallp = new AstFuncRef{fl, "__Vbasic_randomize", nullptr}; - basicRandomizeCallp->taskp(basicRandomizep); - basicRandomizeCallp->dtypep(basicRandomizep->dtypep()); + AstFuncRef* const basicRandomizeCallp = new AstFuncRef{fl, basicRandomizep, nullptr}; AstVarRef* const fvarRefReadp = fvarRefp->cloneTree(false); fvarRefReadp->access(VAccess::READ); @@ -2176,16 +2166,12 @@ class RandomizeVisitor final : public VNVisitor { AstFunc* const basicRandomizeFuncp = V3Randomize::newRandomizeFunc(m_memberMap, classp, "__Vbasic_randomize"); AstFuncRef* const basicRandomizeFuncCallp - = new AstFuncRef{nodep->fileline(), "__Vbasic_randomize", nullptr}; - basicRandomizeFuncCallp->taskp(basicRandomizeFuncp); - basicRandomizeFuncCallp->dtypep(basicRandomizeFuncp->dtypep()); + = new AstFuncRef{nodep->fileline(), basicRandomizeFuncp, nullptr}; // Copy (derive) class constraints if present if (classGenp) { AstTask* const constrSetupFuncp = getCreateConstraintSetupFunc(classp); - AstTaskRef* const callp - = new AstTaskRef{nodep->fileline(), constrSetupFuncp->name(), nullptr}; - callp->taskp(constrSetupFuncp); + AstTaskRef* const callp = new AstTaskRef{nodep->fileline(), constrSetupFuncp, nullptr}; randomizeFuncp->addStmtsp(callp->makeStmt()); randomizeFuncp->addStmtsp(new AstAssign{ nodep->fileline(), new AstVarRef{nodep->fileline(), localGenp, VAccess::WRITE}, diff --git a/src/V3Task.cpp b/src/V3Task.cpp index b54af15c1..a0aac92a6 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -1849,16 +1849,13 @@ AstNodeFTask* V3Task::taskConnectWrapNew(AstNodeFTask* taskp, const string& newn newFVarp->name(newTaskp->name()); newTaskp->fvarp(newFVarp); newTaskp->dtypeFrom(newFVarp); - newCallp = new AstFuncRef{taskp->fileline(), taskp->name(), nullptr}; - newCallp->taskp(taskp); - newCallp->dtypeFrom(newFVarp); + newCallp = new AstFuncRef{taskp->fileline(), VN_AS(taskp, Func), nullptr}; newCallInsertp = new AstAssign{taskp->fileline(), new AstVarRef{fvarp->fileline(), newFVarp, VAccess::WRITE}, newCallp}; newCallInsertp->dtypeFrom(newFVarp); } else if (VN_IS(taskp, Task)) { - newCallp = new AstTaskRef{taskp->fileline(), taskp->name(), nullptr}; - newCallp->taskp(taskp); + newCallp = new AstTaskRef{taskp->fileline(), VN_AS(taskp, Task), nullptr}; newCallInsertp = new AstStmtExpr{taskp->fileline(), newCallp}; } else { taskp->v3fatalSrc("Unsupported: Non-constant default value in missing argument in a " diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 51848261c..bb91fc3c6 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -3788,11 +3788,10 @@ class WidthVisitor final : public VNVisitor { if (nodep->pinsp()) argsp = nodep->pinsp()->unlinkFrBackWithNext(); AstNodeFTaskRef* newp = nullptr; if (VN_IS(ftaskp, Task)) { - newp = new AstTaskRef{nodep->fileline(), ftaskp->name(), argsp}; + newp = new AstTaskRef{nodep->fileline(), VN_AS(ftaskp, Task), argsp}; } else { - newp = new AstFuncRef{nodep->fileline(), ftaskp->name(), argsp}; + newp = new AstFuncRef{nodep->fileline(), VN_AS(ftaskp, Func), argsp}; } - newp->taskp(ftaskp); newp->classOrPackagep(ifacep); nodep->replaceWith(newp); VL_DO_DANGLING(nodep->deleteTree(), nodep); @@ -3927,11 +3926,10 @@ class WidthVisitor final : public VNVisitor { if (nodep->pinsp()) argsp = nodep->pinsp()->unlinkFrBackWithNext(); AstNodeFTaskRef* newp = nullptr; if (VN_IS(ftaskp, Task)) { - newp = new AstTaskRef{nodep->fileline(), ftaskp->name(), argsp}; + newp = new AstTaskRef{nodep->fileline(), VN_AS(ftaskp, Task), argsp}; } else { - newp = new AstFuncRef{nodep->fileline(), ftaskp->name(), argsp}; + newp = new AstFuncRef{nodep->fileline(), VN_AS(ftaskp, Func), argsp}; } - newp->taskp(ftaskp); newp->classOrPackagep(classp); nodep->replaceWith(newp); VL_DO_DANGLING(nodep->deleteTree(), nodep);