Use static const for emitted parameter declarations.

This commit is contained in:
Wilson Snyder 2020-10-16 19:05:28 -04:00
parent 4849c0530b
commit 44f938e507
2 changed files with 37 additions and 26 deletions

View File

@ -162,23 +162,25 @@ class CUseVisitor : public AstNVisitor {
funcp->addStmtsp(new AstCStmt(nodep->fileline(), "std::string out;\n")); funcp->addStmtsp(new AstCStmt(nodep->fileline(), "std::string out;\n"));
std::string comma; std::string comma;
for (AstNode* itemp = nodep->membersp(); itemp; itemp = itemp->nextp()) { for (AstNode* itemp = nodep->membersp(); itemp; itemp = itemp->nextp()) {
if (VN_IS(itemp, Var)) { if (auto* varp = VN_CAST(itemp, Var)) {
string stmt = "out += \""; if (!varp->isParam()) {
stmt += comma; string stmt = "out += \"";
comma = ", "; stmt += comma;
stmt += itemp->origNameProtect(); comma = ", ";
stmt += ":\" + "; stmt += itemp->origNameProtect();
if (itemp->isWide()) { stmt += ":\" + ";
stmt += "VL_TO_STRING_W("; if (itemp->isWide()) {
stmt += cvtToStr(itemp->widthWords()); stmt += "VL_TO_STRING_W(";
stmt += ", "; stmt += cvtToStr(itemp->widthWords());
} else { stmt += ", ";
stmt += "VL_TO_STRING("; } else {
stmt += "VL_TO_STRING(";
}
stmt += itemp->nameProtect();
stmt += ");\n";
nodep->user1(true); // So what we extend dumps this
funcp->addStmtsp(new AstCStmt(nodep->fileline(), stmt));
} }
stmt += itemp->nameProtect();
stmt += ");\n";
nodep->user1(true); // So what we extend dumps this
funcp->addStmtsp(new AstCStmt(nodep->fileline(), stmt));
} }
} }
if (nodep->extendsp() && nodep->extendsp()->classp()->user1()) { if (nodep->extendsp() && nodep->extendsp()->classp()->user1()) {

View File

@ -156,6 +156,7 @@ public:
} }
void emitParams(AstNodeModule* modp, bool init, bool* firstp, string& sectionr) { void emitParams(AstNodeModule* modp, bool init, bool* firstp, string& sectionr) {
bool anyi = false;
for (AstNode* nodep = modp->stmtsp(); nodep; nodep = nodep->nextp()) { for (AstNode* nodep = modp->stmtsp(); nodep; nodep = nodep->nextp()) {
if (const AstVar* varp = VN_CAST(nodep, Var)) { if (const AstVar* varp = VN_CAST(nodep, Var)) {
if (varp->isParam() && (varp->isUsedParam() || varp->isSigPublic())) { if (varp->isParam() && (varp->isUsedParam() || varp->isSigPublic())) {
@ -172,12 +173,15 @@ public:
} }
} else if (varp->isString()) { } else if (varp->isString()) {
if (init) { if (init) {
emitCtorSep(firstp); puts("const std::string ");
puts(protect("var_" + varp->name()) + " ("); puts(prefixNameProtect(modp) + "::" + protect("var_" + varp->name())
+ "(");
iterateAndNextNull(varp->valuep()); iterateAndNextNull(varp->valuep());
puts(")"); puts(");\n");
anyi = true;
} else { } else {
puts("const std::string " + protect("var_" + varp->name()) + ";\n"); puts("static const std::string " + protect("var_" + varp->name())
+ ";\n");
} }
} else if (!VN_IS(varp->valuep(), Const)) { // Unsupported for output } else if (!VN_IS(varp->valuep(), Const)) { // Unsupported for output
// putsDecoration("// enum ..... "+varp->nameProtect() // putsDecoration("// enum ..... "+varp->nameProtect()
@ -187,10 +191,12 @@ public:
->isOpaque()) { // Can't put out e.g. doubles ->isOpaque()) { // Can't put out e.g. doubles
} else { } else {
if (init) { if (init) {
emitCtorSep(firstp); puts(varp->isQuad() ? "const QData " : "const IData ");
puts(protect("var_" + varp->name()) + " ("); puts(prefixNameProtect(modp) + "::" + protect("var_" + varp->name())
+ "(");
iterateAndNextNull(varp->valuep()); iterateAndNextNull(varp->valuep());
puts(")"); puts(");\n");
anyi = true;
} else { } else {
// enum // enum
puts(varp->isQuad() ? "enum _QData" : "enum _IData"); puts(varp->isQuad() ? "enum _QData" : "enum _IData");
@ -198,13 +204,14 @@ public:
iterateAndNextNull(varp->valuep()); iterateAndNextNull(varp->valuep());
puts("};\n"); puts("};\n");
// var // var
puts(varp->isQuad() ? "const QData " : "const IData "); puts(varp->isQuad() ? "static const QData " : "static const IData ");
puts(protect("var_" + varp->name()) + ";\n"); puts(protect("var_" + varp->name()) + ";\n");
} }
} }
} }
} }
} }
if (anyi) puts("\n");
} }
struct CmpName { struct CmpName {
@ -2319,6 +2326,9 @@ void EmitCImp::emitMTaskVertexCtors(bool* firstp) {
void EmitCImp::emitCtorImp(AstNodeModule* modp) { void EmitCImp::emitCtorImp(AstNodeModule* modp) {
puts("\n"); puts("\n");
bool first = true; bool first = true;
string section("");
emitParams(modp, true, &first, section /*ref*/);
if (VN_IS(modp, Class)) { if (VN_IS(modp, Class)) {
modp->v3fatalSrc("constructors should be AstCFuncs instead"); modp->v3fatalSrc("constructors should be AstCFuncs instead");
} else if (optSystemC() && modp->isTop()) { } else if (optSystemC() && modp->isTop()) {
@ -2329,8 +2339,7 @@ void EmitCImp::emitCtorImp(AstNodeModule* modp) {
} }
emitVarCtors(&first); emitVarCtors(&first);
if (modp->isTop() && v3Global.opt.mtasks()) emitMTaskVertexCtors(&first); if (modp->isTop() && v3Global.opt.mtasks()) emitMTaskVertexCtors(&first);
string section("");
emitParams(modp, true, &first, section /*ref*/);
puts(" {\n"); puts(" {\n");
emitCellCtors(modp); emitCellCtors(modp);
emitSensitives(); emitSensitives();