From 78feed966af4da8d0b9f20a0ec3323f9861e2783 Mon Sep 17 00:00:00 2001 From: Ryszard Rozak Date: Tue, 5 Nov 2024 12:53:03 +0100 Subject: [PATCH] Resize constrained arrays Signed-off-by: Ryszard Rozak --- src/V3Randomize.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index e9fb06d65c..f3394355a6 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -1161,6 +1161,17 @@ class RandomizeVisitor final : public VNVisitor { m_memberMap.insert(classp, setupAllTaskp); return setupAllTaskp; } + AstTask* getCreateAggrResizeTask(AstClass* classp) { + static const char* const name = "__Vresize_constrained_arrays"; + AstTask* resizeTaskp = VN_AS(m_memberMap.findMember(classp, name), Task); + if (resizeTaskp) return resizeTaskp; + resizeTaskp = new AstTask{classp->fileline(), name, nullptr}; + resizeTaskp->classMethod(true); + resizeTaskp->isVirtual(true); + classp->addMembersp(resizeTaskp); + m_memberMap.insert(classp, resizeTaskp); + return resizeTaskp; + } AstVar* getCreateRandModeVar(AstClass* const classp) { if (classp->user2p()) return VN_AS(classp->user2p(), Var); if (AstClassExtends* const extendsp = classp->extendsp()) { @@ -1887,6 +1898,16 @@ class RandomizeVisitor final : public VNVisitor { setupAllTaskp->addStmtsp(setupTaskRefp->makeStmt()); + if (AstTask* resizeTaskp = VN_CAST(constrp->user3p(), Task)) { + AstTask* const resizeAllTaskp = getCreateAggrResizeTask(nodep); + AstTaskRef* const resizeTaskRefp + = new AstTaskRef{constrp->fileline(), resizeTaskp->name(), nullptr}; + resizeTaskRefp->taskp(resizeTaskp); + resizeTaskRefp->classOrPackagep(classp); + + resizeAllTaskp->addStmtsp(resizeTaskRefp->makeStmt()); + } + ConstraintExprVisitor{m_memberMap, constrp->itemsp(), nullptr, genp, randModeVarp}; if (constrp->itemsp()) { taskp->addStmtsp(wrapIfConstraintMode( @@ -1915,6 +1936,15 @@ class RandomizeVisitor final : public VNVisitor { UASSERT_OBJ(newp, randModeClassp, "No new() in class"); addSetRandMode(newp, genp, randModeVarp); } + + AstTask* const resizeAllTaskp + = VN_AS(m_memberMap.findMember(nodep, "__Vresize_constrained_arrays"), Task); + if (resizeAllTaskp) { + AstTaskRef* const resizeTaskRefp + = new AstTaskRef{fl, resizeAllTaskp->name(), nullptr}; + resizeTaskRefp->taskp(resizeAllTaskp); + randomizep->addStmtsp(resizeTaskRefp->makeStmt()); + } } else { beginValp = new AstConst{fl, AstConst::WidthedValue{}, 32, 1}; }