Support selects on arbitrary string expressions (#5773)

This commit is contained in:
Krzysztof Bieganski
2025-02-11 12:06:34 -05:00
committed by GitHub
parent caa19c0cb3
commit f753ae2518
3 changed files with 89 additions and 5 deletions
+11 -5
View File
@@ -305,13 +305,19 @@ class WidthSelVisitor final : public VNVisitor {
VL_DO_DANGLING(pushDeletep(nodep), nodep);
} else if (VN_IS(ddtypep, BasicDType) && ddtypep->isString()) {
// SELBIT(string, index) -> GETC(string, index)
const AstNodeVarRef* const varrefp = VN_CAST(fromp, NodeVarRef);
if (!varrefp) {
nodep->v3warn(E_UNSUPPORTED,
"Unsupported: String array operation on non-variable");
AstNodeExpr* exprp = fromp;
while (true) {
if (AstMemberSel* const memberselp = VN_CAST(exprp, MemberSel)) {
exprp = memberselp->fromp();
} else if (AstStructSel* const structselp = VN_CAST(exprp, StructSel)) {
exprp = structselp->fromp();
} else {
break;
}
}
const AstNodeVarRef* const varrefp = VN_CAST(exprp, NodeVarRef);
AstNodeExpr* newp;
if (varrefp && varrefp->access().isReadOnly()) {
if (!varrefp || varrefp->access().isReadOnly()) {
newp = new AstGetcN{nodep->fileline(), fromp, rhsp};
} else {
newp = new AstGetcRefN{nodep->fileline(), fromp, rhsp};