Skip to content

Commit

Permalink
WIP: Add resize function to AstWith
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Nov 13, 2024
1 parent 9fd5d22 commit 2d39694
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ class RandomizeVisitor final : public VNVisitor {
// AstVar::user3() -> bool. Handled in constraints
// AstClass::user3p() -> AstVar*. Constrained randomizer variable
// AstConstraint::user3p() -> AstTask*. Pointer to resize procedure
// AstWith::user3p() -> AstTask*. Pointer to resize procedure
// AstClass::user4p() -> AstVar*. Constraint mode state variable
// AstVar::user4p() -> AstVar*. Size variable
// VNUser1InUse m_inuser1; (Allocated for use in RandomizeMarkVisitor)
Expand All @@ -1142,6 +1143,7 @@ class RandomizeVisitor final : public VNVisitor {

// STATE
V3UniqueNames m_inlineUniqueNames; // For generating unique function names
V3UniqueNames m_inlineUniqueConstrNames{"__Vresize"}; // For generating unique function names
V3UniqueNames m_modeUniqueNames{"__Vmode"}; // For generating unique rand/constraint
// mode state var names
VMemberMap m_memberMap; // Member names cached for fast lookup
Expand All @@ -1153,6 +1155,7 @@ class RandomizeVisitor final : public VNVisitor {
int m_randCaseNum = 0; // Randcase number within a module for var naming
std::map<std::string, AstCDType*> m_randcDtypes; // RandC data type deduplication
AstConstraint* m_constraintp = nullptr;
AstWith* m_withp = nullptr;

// METHODS
void createRandomGenerator(AstClass* const classp) {
Expand Down Expand Up @@ -2093,6 +2096,8 @@ class RandomizeVisitor final : public VNVisitor {
iterateChildren(nodep);
return;
}
VL_RESTORER(m_withp);
m_withp = withp;
withp->unlinkFrBack();

iterateChildren(nodep);
Expand Down Expand Up @@ -2207,7 +2212,7 @@ class RandomizeVisitor final : public VNVisitor {
void visit(AstCMethodHard* nodep) override {
iterateChildren(nodep);
FileLine* fl = nodep->fileline();
if (m_constraintp && nodep->fromp()->user1() && nodep->name() == "size") {
if ((m_constraintp || m_withp) && nodep->fromp()->user1() && nodep->name() == "size") {
AstClass* const classp = VN_AS(m_modp, Class);
AstVar* const queueVarp = VN_AS(nodep->fromp(), VarRef)->varp();
AstVar* sizeVarp = VN_CAST(queueVarp->user4p(), Var);
Expand All @@ -2220,10 +2225,19 @@ class RandomizeVisitor final : public VNVisitor {

queueVarp->user4p(sizeVarp);

AstTask* resizerTaskp = VN_AS(m_constraintp->user3p(), Task);
if (!resizerTaskp) {
resizerTaskp = newResizeConstrainedArrayTask(classp, m_constraintp->name());
m_constraintp->user3p(resizerTaskp);
AstTask* resizerTaskp;
if (m_constraintp) {
resizerTaskp = VN_AS(m_constraintp->user3p(), Task);
if (!resizerTaskp) {
resizerTaskp = newResizeConstrainedArrayTask(classp, m_constraintp->name());
m_constraintp->user3p(resizerTaskp);
}
} else if (m_withp) {
resizerTaskp = VN_AS(m_withp->user3p(), Task);
if (!resizerTaskp) {
resizerTaskp = newResizeConstrainedArrayTask(classp, m_inlineUniqueConstrNames.get(m_withp));
m_withp->user3p(resizerTaskp);
}
}
AstCMethodHard* const resizep
= new AstCMethodHard{fl, nodep->fromp()->unlinkFrBack(), "resize",
Expand All @@ -2237,7 +2251,11 @@ class RandomizeVisitor final : public VNVisitor {
sizeVarRefp->user1(true);
AstGteS* const sizeGtep = new AstGteS{fl, sizeVarRefp, new AstConst{fl, 0}};
sizeGtep->user1(true);
m_constraintp->addItemsp(new AstConstraintExpr{fl, sizeGtep});
if (m_constraintp) {
m_constraintp->addItemsp(new AstConstraintExpr{fl, sizeGtep});
} else if (m_withp) {
m_withp->addExprp(new AstConstraintExpr{fl, sizeGtep});
}
}
AstVarRef* const sizeVarRefp = new AstVarRef{fl, sizeVarp, VAccess::READ};
sizeVarRefp->user1(true);
Expand Down

0 comments on commit 2d39694

Please sign in to comment.