diff --git a/src/V3AstAttr.h b/src/V3AstAttr.h index 3a3f7bd8f..8e0f8bdc9 100644 --- a/src/V3AstAttr.h +++ b/src/V3AstAttr.h @@ -783,7 +783,8 @@ public: FORK_INIT, FORK_JOIN, RANDOMIZER_BASIC_STD_RANDOMIZATION, - RANDOMIZER_CLEAR, + RANDOMIZER_CLEARCONSTRAINTS, + RANDOMIZER_CLEARALL, RANDOMIZER_HARD, RANDOMIZER_WRITE_VAR, RNG_GET_RANDSTATE, @@ -911,7 +912,8 @@ inline std::ostream& operator<<(std::ostream& os, const VCMethod& rhs) { {FORK_INIT, "init", false}, \ {FORK_JOIN, "join", false}, \ {RANDOMIZER_BASIC_STD_RANDOMIZATION, "basicStdRandomization", false}, \ - {RANDOMIZER_CLEAR, "clear", false}, \ + {RANDOMIZER_CLEARCONSTRAINTS, "clearConstraints", false}, \ + {RANDOMIZER_CLEARALL, "clearAll", false}, \ {RANDOMIZER_HARD, "hard", false}, \ {RANDOMIZER_WRITE_VAR, "write_var", false}, \ {RNG_GET_RANDSTATE, "__Vm_rng.get_randstate", true}, \ diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index 707d994af..2cd8bd65d 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -371,15 +371,6 @@ class RandomizeMarkVisitor final : public VNVisitor { iterateChildren(nodep); if (!nodep->backp()) VL_DO_DANGLING(nodep->deleteTree(), nodep); } - void visit(AstWith* nodep) override { - for (AstNode* pinp = m_stdRandCallp ? m_stdRandCallp->pinsp() : nullptr; pinp; - pinp = pinp->nextp()) { - AstWith* const withp = VN_CAST(pinp, With); - if (withp == nodep) m_inStdWith = true; - } - iterateChildrenConst(nodep); - m_inStdWith = false; - } void visit(AstNodeFTaskRef* nodep) override { if (nodep->classOrPackagep() && nodep->classOrPackagep()->name() == "std") m_stdRandCallp = nodep; @@ -705,7 +696,13 @@ class RandomizeMarkVisitor final : public VNVisitor { void visit(AstWith* nodep) override { VL_RESTORER(m_withp); m_withp = nodep; + for (AstNode* pinp = m_stdRandCallp ? m_stdRandCallp->pinsp() : nullptr; pinp; + pinp = pinp->nextp()) { + AstWith* const withp = VN_CAST(pinp, With); + if (withp == nodep) m_inStdWith = true; + } iterateChildrenConst(nodep); + m_inStdWith = false; } void visit(AstNodeExpr* nodep) override { @@ -2650,10 +2647,10 @@ class RandomizeVisitor final : public VNVisitor { ConstraintExprVisitor{m_memberMap, capturedTreep, randomizeFuncp, stdrand, nullptr}; } - AstVarRef* const randNextp = new AstVarRef{fl, stdrand, VAccess::READWRITE}; - randNextp->AstNode::addNext(new AstText{fl, ".next()"}); - AstNodeExpr* const solverCallp = new AstCExpr{fl, randNextp}; + AstCExpr* const solverCallp = new AstCExpr{fl}; solverCallp->dtypeSetBit(); + solverCallp->add(new AstVarRef{fl, stdrand, VAccess::READWRITE}); + solverCallp->add(".next()"); AstVar* const fvarp = VN_AS(randomizeFuncp->fvarp(), Var); AstVarRef* const retvalReadp = new AstVarRef{fl, fvarp, VAccess::READ}; AstNodeExpr* const andExprp = new AstAnd{fl, retvalReadp, solverCallp};