Add mnemonic to parameter constants in JSON for FSM Coverage (#7531)

This commit is contained in:
Yogish Sekhar
2026-05-06 07:25:03 -04:00
committed by GitHub
parent 227812ecce
commit 22db9d2c66
8 changed files with 394 additions and 127 deletions
+56
View File
@@ -543,6 +543,22 @@ AstNetlist::AstNetlist()
addMiscsp(m_constPoolp);
}
string AstNetlist::astConstOrigParamName(const AstConst* nodep) const {
if (!nodep->num().hasOrigParamName()) return "";
const auto it = m_constOrigParamNames.find(nodep);
UASSERT_OBJ(it != m_constOrigParamNames.end(), nodep, "Missing originating parameter name");
return it->second;
}
void AstNetlist::astConstOrigParamName(const AstConst* nodep, const string& name) {
UASSERT(!name.empty(), "Empty originating parameter name");
m_constOrigParamNames[nodep] = name;
}
void AstNetlist::astConstOrigParamNameErase(const AstConst* nodep) {
m_constOrigParamNames.erase(nodep);
}
void AstNetlist::timeprecisionMerge(FileLine*, const VTimescale& value) {
const VTimescale prec = v3Global.opt.timeComputePrec(value);
if (prec.isNone() || prec == m_timeprecision) {
@@ -1819,6 +1835,46 @@ string AstBasicDType::prettyDTypeName(bool) const {
void AstNodeExpr::dump(std::ostream& str) const { this->AstNode::dump(str); }
void AstNodeExpr::dumpJson(std::ostream& str) const { dumpJsonGen(str); }
AstConst::~AstConst() {
// Only rare constants carry originating parameter-name metadata. For all other AstConst nodes,
// the V3Number bit keeps this destructor from touching AstNetlist's side table. When the bit is
// set, erase the entry before this AstConst address can be reused by a different node.
if (m_num.hasOrigParamName()) v3Global.rootp()->astConstOrigParamNameErase(this);
}
string AstConst::origParamName() const {
if (!m_num.hasOrigParamName()) return "";
return v3Global.rootp()->astConstOrigParamName(this);
}
void AstConst::origParamName(const string& name) {
UASSERT(!name.empty(), "Empty originating parameter name");
v3Global.rootp()->astConstOrigParamName(this, name);
m_num.hasOrigParamName(true);
}
void AstConst::cloneRelink() {
// Preserve parameter-origin metadata across AST clones; the side-table key must be this
// new AstConst, not the original node.
if (const AstConst* const oldp = clonep()) {
const string name = oldp->origParamName();
m_num.hasOrigParamName(false);
if (!name.empty()) origParamName(name);
}
m_num.nodep(this);
}
void AstConst::dump(std::ostream& str) const {
this->AstNodeExpr::dump(str);
const string name = origParamName();
if (!name.empty()) str << " origParamName=" << name;
}
void AstConst::dumpJson(std::ostream& str) const {
const string name = origParamName();
if (!name.empty()) dumpJsonStr(str, "origParamName", name);
dumpJsonGen(str);
}
bool AstNodeExpr::isLValue() const {
if (const AstNodeVarRef* const varrefp = VN_CAST(this, NodeVarRef)) {
return varrefp->access().isWriteOrRW();