Internals: Improve readability of selects in output (#6980)

This commit is contained in:
Geza Lore 2026-02-01 12:29:56 +00:00 committed by GitHub
parent 197f11044e
commit ca17904a62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View File

@ -4280,7 +4280,7 @@ public:
ASTGEN_MEMBERS_AstArraySel;
void numberOperate(V3Number&, const V3Number&, const V3Number&) override { V3ERROR_NA; }
string emitVerilog() override { return "%k(%l%f[%r])"; }
string emitC() override { return "%li%k[%ri]"; }
string emitC() override { V3ERROR_NA_RETURN(""); } // Special cased
string emitSMT() const override { return "(select %l %r)"; }
bool cleanOut() const override { return true; }
bool cleanLhs() const override { return false; }
@ -4361,9 +4361,7 @@ public:
ASTGEN_MEMBERS_AstWordSel;
void numberOperate(V3Number&, const V3Number&, const V3Number&) override { V3ERROR_NA; }
string emitVerilog() override { return "%k(%l%f[%r])"; }
string emitC() override {
return "%li[%ri]";
} // Not %k, as usually it's a small constant rhsp
string emitC() override { V3ERROR_NA_RETURN(""); } // Special cased
bool cleanOut() const override { return true; }
bool cleanLhs() const override { return true; }
bool cleanRhs() const override { return true; }

View File

@ -1651,6 +1651,22 @@ public:
puts(VSelfPointerText::replaceThis(m_useSelfForThis, "this"));
puts("}");
}
void visit(AstNodeSel* nodep) override {
if (!VN_IS(nodep, ArraySel) && !VN_IS(nodep, WordSel)) {
visit(static_cast<AstNodeBiop*>(nodep));
return;
}
// ArraySel or WordSel
iterateAndNextConstNull(nodep->fromp());
// Special case constant index for readability
if (AstConst* const idxp = VN_CAST(nodep->bitp(), Const)) {
puts("[" + std::to_string(idxp->toUInt()) + "U]");
return;
}
putbs("[");
iterateAndNextConstNull(nodep->bitp());
puts("]");
}
//
void visit(AstConsAssoc* nodep) override {