Keep one member map for randomize method creation (#5263)
No functional change intended. Signed-off-by: Krzysztof Bieganski <kbieganski@antmicro.com>
This commit is contained in:
parent
164a7a7c5d
commit
34e37d7bd0
|
|
@ -710,7 +710,7 @@ class RandomizeVisitor final : public VNVisitor {
|
||||||
iterateChildren(nodep);
|
iterateChildren(nodep);
|
||||||
if (!nodep->user1()) return; // Doesn't need randomize, or already processed
|
if (!nodep->user1()) return; // Doesn't need randomize, or already processed
|
||||||
UINFO(9, "Define randomize() for " << nodep << endl);
|
UINFO(9, "Define randomize() for " << nodep << endl);
|
||||||
AstFunc* const funcp = V3Randomize::newRandomizeFunc(nodep);
|
AstFunc* const funcp = V3Randomize::newRandomizeFunc(m_memberMap, nodep);
|
||||||
nodep->user3p(funcp);
|
nodep->user3p(funcp);
|
||||||
AstVar* const fvarp = VN_AS(funcp->fvarp(), Var);
|
AstVar* const fvarp = VN_AS(funcp->fvarp(), Var);
|
||||||
addPrePostCall(nodep, funcp, "pre_randomize");
|
addPrePostCall(nodep, funcp, "pre_randomize");
|
||||||
|
|
@ -758,7 +758,8 @@ class RandomizeVisitor final : public VNVisitor {
|
||||||
"Unsupported: random member variable with type of a current class");
|
"Unsupported: random member variable with type of a current class");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
AstFunc* const memberFuncp = V3Randomize::newRandomizeFunc(classRefp->classp());
|
AstFunc* const memberFuncp
|
||||||
|
= V3Randomize::newRandomizeFunc(m_memberMap, classRefp->classp());
|
||||||
AstMethodCall* const callp = new AstMethodCall{
|
AstMethodCall* const callp = new AstMethodCall{
|
||||||
fl, new AstVarRef{fl, memberVarp, VAccess::WRITE}, "randomize", nullptr};
|
fl, new AstVarRef{fl, memberVarp, VAccess::WRITE}, "randomize", nullptr};
|
||||||
callp->taskp(memberFuncp);
|
callp->taskp(memberFuncp);
|
||||||
|
|
@ -784,7 +785,8 @@ class RandomizeVisitor final : public VNVisitor {
|
||||||
if (nodep->user2p()) return; // Already visited
|
if (nodep->user2p()) return; // Already visited
|
||||||
AstNodeFTask* const newp = VN_AS(m_memberMap.findMember(m_modp, "new"), NodeFTask);
|
AstNodeFTask* const newp = VN_AS(m_memberMap.findMember(m_modp, "new"), NodeFTask);
|
||||||
UASSERT_OBJ(newp, m_modp, "No new() in class");
|
UASSERT_OBJ(newp, m_modp, "No new() in class");
|
||||||
AstFunc* const randomizep = V3Randomize::newRandomizeFunc(VN_AS(m_modp, Class));
|
AstFunc* const randomizep
|
||||||
|
= V3Randomize::newRandomizeFunc(m_memberMap, VN_AS(m_modp, Class));
|
||||||
AstTask* const taskp = newSetupConstraintTask(VN_AS(m_modp, Class), nodep->name());
|
AstTask* const taskp = newSetupConstraintTask(VN_AS(m_modp, Class), nodep->name());
|
||||||
nodep->user2p(taskp);
|
nodep->user2p(taskp);
|
||||||
AstTaskRef* const setupTaskRefp
|
AstTaskRef* const setupTaskRefp
|
||||||
|
|
@ -902,7 +904,7 @@ class RandomizeVisitor final : public VNVisitor {
|
||||||
localGenp->funcLocal(true);
|
localGenp->funcLocal(true);
|
||||||
|
|
||||||
AstFunc* const randomizeFuncp
|
AstFunc* const randomizeFuncp
|
||||||
= V3Randomize::newRandomizeFunc(classp, m_inlineUniqueNames.get(nodep));
|
= V3Randomize::newRandomizeFunc(m_memberMap, classp, m_inlineUniqueNames.get(nodep));
|
||||||
|
|
||||||
// Detach the expression and prepare variable copies
|
// Detach the expression and prepare variable copies
|
||||||
const CaptureFrame<AstNode> captured{withp->exprp(), classp, false};
|
const CaptureFrame<AstNode> captured{withp->exprp(), classp, false};
|
||||||
|
|
@ -994,10 +996,9 @@ void V3Randomize::randomizeNetlist(AstNetlist* nodep) {
|
||||||
V3Global::dumpCheckGlobalTree("randomize", 0, dumpTreeEitherLevel() >= 3);
|
V3Global::dumpCheckGlobalTree("randomize", 0, dumpTreeEitherLevel() >= 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
AstFunc* V3Randomize::newRandomizeFunc(AstClass* nodep, const std::string& name) {
|
AstFunc* V3Randomize::newRandomizeFunc(VMemberMap& memberMap, AstClass* nodep,
|
||||||
VMemberMap memberMap;
|
const std::string& name) {
|
||||||
AstFunc* funcp = VN_AS(memberMap.findMember(nodep, name), Func);
|
AstFunc* funcp = VN_AS(memberMap.findMember(nodep, name), Func);
|
||||||
|
|
||||||
if (!funcp) {
|
if (!funcp) {
|
||||||
v3Global.useRandomizeMethods(true);
|
v3Global.useRandomizeMethods(true);
|
||||||
AstNodeDType* const dtypep
|
AstNodeDType* const dtypep
|
||||||
|
|
@ -1013,14 +1014,14 @@ AstFunc* V3Randomize::newRandomizeFunc(AstClass* nodep, const std::string& name)
|
||||||
funcp->classMethod(true);
|
funcp->classMethod(true);
|
||||||
funcp->isVirtual(nodep->isExtended());
|
funcp->isVirtual(nodep->isExtended());
|
||||||
nodep->addMembersp(funcp);
|
nodep->addMembersp(funcp);
|
||||||
|
memberMap.insert(nodep, funcp);
|
||||||
AstClass* const basep = nodep->baseMostClassp();
|
AstClass* const basep = nodep->baseMostClassp();
|
||||||
basep->needRNG(true);
|
basep->needRNG(true);
|
||||||
}
|
}
|
||||||
return funcp;
|
return funcp;
|
||||||
}
|
}
|
||||||
|
|
||||||
AstFunc* V3Randomize::newSRandomFunc(AstClass* nodep) {
|
AstFunc* V3Randomize::newSRandomFunc(VMemberMap& memberMap, AstClass* nodep) {
|
||||||
VMemberMap memberMap;
|
|
||||||
AstClass* const basep = nodep->baseMostClassp();
|
AstClass* const basep = nodep->baseMostClassp();
|
||||||
AstFunc* funcp = VN_AS(memberMap.findMember(basep, "srandom"), Func);
|
AstFunc* funcp = VN_AS(memberMap.findMember(basep, "srandom"), Func);
|
||||||
if (!funcp) {
|
if (!funcp) {
|
||||||
|
|
@ -1036,6 +1037,7 @@ AstFunc* V3Randomize::newSRandomFunc(AstClass* nodep) {
|
||||||
funcp->classMethod(true);
|
funcp->classMethod(true);
|
||||||
funcp->isVirtual(false);
|
funcp->isVirtual(false);
|
||||||
basep->addMembersp(funcp);
|
basep->addMembersp(funcp);
|
||||||
|
memberMap.insert(nodep, funcp);
|
||||||
funcp->addStmtsp(new AstCStmt{basep->fileline(), "__Vm_rng.srandom(seed);\n"});
|
funcp->addStmtsp(new AstCStmt{basep->fileline(), "__Vm_rng.srandom(seed);\n"});
|
||||||
basep->needRNG(true);
|
basep->needRNG(true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,15 @@ class AstClass;
|
||||||
class AstFunc;
|
class AstFunc;
|
||||||
class AstNetlist;
|
class AstNetlist;
|
||||||
|
|
||||||
|
class VMemberMap;
|
||||||
|
|
||||||
class V3Randomize final {
|
class V3Randomize final {
|
||||||
public:
|
public:
|
||||||
static void randomizeNetlist(AstNetlist* nodep) VL_MT_DISABLED;
|
static void randomizeNetlist(AstNetlist* nodep) VL_MT_DISABLED;
|
||||||
|
|
||||||
static AstFunc* newRandomizeFunc(AstClass* nodep,
|
static AstFunc* newRandomizeFunc(VMemberMap& memberMap, AstClass* nodep,
|
||||||
const std::string& name = "randomize") VL_MT_DISABLED;
|
const std::string& name = "randomize") VL_MT_DISABLED;
|
||||||
static AstFunc* newSRandomFunc(AstClass* nodep) VL_MT_DISABLED;
|
static AstFunc* newSRandomFunc(VMemberMap& memberMap, AstClass* nodep) VL_MT_DISABLED;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // Guard
|
#endif // Guard
|
||||||
|
|
|
||||||
|
|
@ -3716,13 +3716,11 @@ class WidthVisitor final : public VNVisitor {
|
||||||
adtypep->findBitDType(), adtypep);
|
adtypep->findBitDType(), adtypep);
|
||||||
methodOkArguments(nodep, 0, 0);
|
methodOkArguments(nodep, 0, 0);
|
||||||
methodCallLValueRecurse(nodep, nodep->fromp(), VAccess::WRITE);
|
methodCallLValueRecurse(nodep, nodep->fromp(), VAccess::WRITE);
|
||||||
V3Randomize::newRandomizeFunc(first_classp);
|
V3Randomize::newRandomizeFunc(m_memberMap, first_classp);
|
||||||
m_memberMap.clear();
|
|
||||||
} else if (nodep->name() == "srandom") {
|
} else if (nodep->name() == "srandom") {
|
||||||
methodOkArguments(nodep, 1, 1);
|
methodOkArguments(nodep, 1, 1);
|
||||||
methodCallLValueRecurse(nodep, nodep->fromp(), VAccess::WRITE);
|
methodCallLValueRecurse(nodep, nodep->fromp(), VAccess::WRITE);
|
||||||
V3Randomize::newSRandomFunc(first_classp);
|
V3Randomize::newSRandomFunc(m_memberMap, first_classp);
|
||||||
m_memberMap.clear();
|
|
||||||
}
|
}
|
||||||
UASSERT_OBJ(first_classp, nodep, "Unlinked");
|
UASSERT_OBJ(first_classp, nodep, "Unlinked");
|
||||||
for (AstClass* classp = first_classp; classp;) {
|
for (AstClass* classp = first_classp; classp;) {
|
||||||
|
|
@ -5956,10 +5954,9 @@ class WidthVisitor final : public VNVisitor {
|
||||||
AstClass* const classp = VN_CAST(nodep->classOrPackagep(), Class);
|
AstClass* const classp = VN_CAST(nodep->classOrPackagep(), Class);
|
||||||
UASSERT_OBJ(classp, nodep, "Should have failed in V3LinkDot");
|
UASSERT_OBJ(classp, nodep, "Should have failed in V3LinkDot");
|
||||||
if (nodep->name() == "randomize") {
|
if (nodep->name() == "randomize") {
|
||||||
nodep->taskp(V3Randomize::newRandomizeFunc(classp));
|
nodep->taskp(V3Randomize::newRandomizeFunc(m_memberMap, classp));
|
||||||
m_memberMap.clear();
|
|
||||||
} else if (nodep->name() == "srandom") {
|
} else if (nodep->name() == "srandom") {
|
||||||
nodep->taskp(V3Randomize::newSRandomFunc(classp));
|
nodep->taskp(V3Randomize::newSRandomFunc(m_memberMap, classp));
|
||||||
m_memberMap.clear();
|
m_memberMap.clear();
|
||||||
} else if (nodep->name() == "get_randstate") {
|
} else if (nodep->name() == "get_randstate") {
|
||||||
methodOkArguments(nodep, 0, 0);
|
methodOkArguments(nodep, 0, 0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue