Skip to content

Commit

Permalink
Resize constrained arrays
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Nov 5, 2024
1 parent deb0393 commit 78feed9
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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};
}
Expand Down

0 comments on commit 78feed9

Please sign in to comment.