Support solve before with associative array (#8232)

This commit is contained in:
Kamil Danecki
2026-08-28 15:19:08 -04:00
committed by GitHub
parent 2954756190
commit d2920a627d
5 changed files with 73 additions and 46 deletions
+4 -14
View File
@@ -913,7 +913,7 @@ class ConstraintExprVisitor final : public VNVisitor {
// Returns nullptr for unsupported expression types.
// Helper: build a dynamic AstCExpr for "baseName[idx]" pattern
AstCExpr* buildArraySelNameExpr(FileLine* fl, const std::string& baseName,
const AstArraySel* selp) {
const AstNodeSel* selp) {
AstCExpr* const p = new AstCExpr{fl, ""};
p->add("(\""s + baseName + ".\" + vlToSolverHex(");
p->add(selp->bitp()->cloneTreePure(false));
@@ -974,7 +974,9 @@ class ConstraintExprVisitor final : public VNVisitor {
p->dtypeSetString();
return p;
}
if (const AstArraySel* const selp = VN_CAST(exprp, ArraySel)) {
const AstNodeSel* selp = VN_CAST(exprp, ArraySel);
if (!selp) selp = VN_CAST(exprp, AssocSel);
if (selp) {
// arr[i] -> dynamic name
std::string baseName;
if (const AstVarRef* const vp = VN_CAST(selp->fromp(), VarRef)) {
@@ -2379,12 +2381,6 @@ class ConstraintExprVisitor final : public VNVisitor {
AstNodeModule* const genModp = VN_AS(m_genp->user2p(), NodeModule);
for (AstNodeExpr* lhsp = nodep->lhssp(); lhsp; lhsp = VN_CAST(lhsp->nextp(), NodeExpr)) {
if (VN_IS(lhsp->dtypep()->skipRefp(), AssocArrayDType)) {
lhsp->v3warn(E_UNSUPPORTED,
"Unsupported: 'solve ... before' with associative array");
VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep);
return;
}
AstNodeExpr* const lhsTestp = buildSolveBeforeNameExpr(fl, lhsp);
if (!lhsTestp) {
lhsp->v3fatalSrc("Unexpected expression type in solve...before lhs");
@@ -2393,12 +2389,6 @@ class ConstraintExprVisitor final : public VNVisitor {
VL_DO_DANGLING(lhsTestp->deleteTree(), lhsTestp);
for (AstNodeExpr* rhsp = nodep->rhssp(); rhsp;
rhsp = VN_CAST(rhsp->nextp(), NodeExpr)) {
if (VN_IS(rhsp->dtypep()->skipRefp(), AssocArrayDType)) {
rhsp->v3warn(E_UNSUPPORTED,
"Unsupported: 'solve ... before' with associative array");
VL_DO_DANGLING(nodep->unlinkFrBack()->deleteTree(), nodep);
return;
}
AstNodeExpr* const rhsNamep = buildSolveBeforeNameExpr(fl, rhsp);
if (!rhsNamep) {
rhsp->v3fatalSrc("Unexpected expression type in solve...before rhs");