Support Unpacked Structures' Constrained Randomization (#5657) (#5759)

This commit is contained in:
Yilou Wang
2025-02-03 11:56:00 -05:00
committed by GitHub
parent e0e164cea2
commit 6b4183632c
10 changed files with 235 additions and 16 deletions
+25
View File
@@ -629,6 +629,11 @@ class ConstraintExprVisitor final : public VNVisitor {
const uint32_t unpackedDimensions = dims.second;
dimension = unpackedDimensions;
}
if (VN_IS(varp->dtypeSkipRefp(), StructDType)
&& !VN_AS(varp->dtypeSkipRefp(), StructDType)->packed()) {
VN_AS(varp->dtypeSkipRefp(), StructDType)->markConstrainedRand(true);
dimension = 1;
}
methodp->dtypeSetVoid();
AstClass* const classp = VN_AS(varp->user2p(), Class);
AstVarRef* const varRefp
@@ -706,6 +711,26 @@ class ConstraintExprVisitor final : public VNVisitor {
editSMT(nodep, nodep->fromp(), lsbp, msbp);
}
void visit(AstStructSel* nodep) override {
if (VN_IS(nodep->fromp()->dtypep()->skipRefp(), StructDType)) {
AstMemberDType* memberp
= VN_AS(nodep->fromp()->dtypep()->skipRefp(), StructDType)->membersp();
while (memberp->nextp()) {
if (memberp->name() == nodep->name()) {
memberp->markConstrainedRand(true);
break;
} else
memberp = VN_CAST(memberp->nextp(), MemberDType);
}
}
iterateChildren(nodep);
if (editFormat(nodep)) return;
FileLine* const fl = nodep->fileline();
AstSFormatF* const newp
= new AstSFormatF{fl, nodep->fromp()->name() + "." + nodep->name(), false, nullptr};
nodep->replaceWith(newp);
VL_DO_DANGLING(pushDeletep(nodep), nodep);
}
void visit(AstAssocSel* nodep) override {
if (editFormat(nodep)) return;
FileLine* const fl = nodep->fileline();