Fix error on enums with x/z using .name(), and internal refactoring

This commit is contained in:
Wilson Snyder
2024-10-11 22:37:48 -04:00
parent 789698cb5c
commit 2fc94557a0
5 changed files with 993 additions and 971 deletions
+22 -17
View File
@@ -31,6 +31,24 @@ VL_DEFINE_DEBUG_FUNCTIONS;
//######################################################################
// Common component builders
string V3Common::makeToStringCall(AstNodeDType* nodep, const std::string& lhs) {
std::string stmt;
if (VN_IS(nodep->skipRefp(), BasicDType) && nodep->isWide()) {
stmt += "VL_TO_STRING_W(";
stmt += cvtToStr(nodep->widthWords());
stmt += ", ";
} else if (VN_IS(nodep->skipRefp(), BasicDType) && nodep->isWide()) {
stmt += "VL_TO_STRING_W(";
stmt += cvtToStr(nodep->widthWords());
stmt += ", ";
} else {
stmt += "VL_TO_STRING(";
}
stmt += lhs;
stmt += ")";
return stmt;
}
static void makeVlToString(AstClass* nodep) {
AstCFunc* const funcp
= new AstCFunc{nodep->fileline(), "VL_TO_STRING", nullptr, "std::string"};
@@ -78,14 +96,8 @@ static void makeVlToString(AstNodeUOrStructDType* nodep) {
stmt += ", ";
}
stmt += VIdProtect::protect(itemp->prettyName()) + ":\" + ";
if (VN_IS(itemp->dtypep()->skipRefp(), BasicDType) && itemp->isWide()) {
stmt += "VL_TO_STRING_W(";
stmt += cvtToStr(itemp->widthWords());
stmt += ", ";
} else {
stmt += "VL_TO_STRING(";
}
stmt += "obj." + itemp->nameProtect() + ");\n";
stmt += V3Common::makeToStringCall(itemp->dtypep(), "obj."s + itemp->nameProtect());
stmt += ";\n";
funcp->addStmtsp(new AstCStmt{nodep->fileline(), stmt});
}
funcp->addStmtsp(new AstCStmt{nodep->fileline(), "out += \"}\";\n"});
@@ -121,15 +133,8 @@ static void makeToStringMiddle(AstClass* nodep) {
comma = ", ";
stmt += itemp->origNameProtect();
stmt += ":\" + ";
if (VN_IS(itemp->dtypep()->skipRefp(), BasicDType) && itemp->isWide()) {
stmt += "VL_TO_STRING_W(";
stmt += cvtToStr(itemp->widthWords());
stmt += ", ";
} else {
stmt += "VL_TO_STRING(";
}
stmt += itemp->nameProtect();
stmt += ");\n";
stmt += V3Common::makeToStringCall(itemp->dtypep(), itemp->nameProtect());
stmt += ";\n";
nodep->user1(true); // So what we extend dumps this
funcp->addStmtsp(new AstCStmt{nodep->fileline(), stmt});
}