From 44f938e507436b507b40920629b78133b9063c03 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 16 Oct 2020 19:05:28 -0400 Subject: [PATCH] Use static const for emitted parameter declarations. --- src/V3CUse.cpp | 34 ++++++++++++++++++---------------- src/V3EmitC.cpp | 29 +++++++++++++++++++---------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/V3CUse.cpp b/src/V3CUse.cpp index dc33b101e..78afb6dea 100644 --- a/src/V3CUse.cpp +++ b/src/V3CUse.cpp @@ -162,23 +162,25 @@ class CUseVisitor : public AstNVisitor { funcp->addStmtsp(new AstCStmt(nodep->fileline(), "std::string out;\n")); std::string comma; for (AstNode* itemp = nodep->membersp(); itemp; itemp = itemp->nextp()) { - if (VN_IS(itemp, Var)) { - string stmt = "out += \""; - stmt += comma; - comma = ", "; - stmt += itemp->origNameProtect(); - stmt += ":\" + "; - if (itemp->isWide()) { - stmt += "VL_TO_STRING_W("; - stmt += cvtToStr(itemp->widthWords()); - stmt += ", "; - } else { - stmt += "VL_TO_STRING("; + if (auto* varp = VN_CAST(itemp, Var)) { + if (!varp->isParam()) { + string stmt = "out += \""; + stmt += comma; + comma = ", "; + stmt += itemp->origNameProtect(); + stmt += ":\" + "; + if (itemp->isWide()) { + stmt += "VL_TO_STRING_W("; + stmt += cvtToStr(itemp->widthWords()); + stmt += ", "; + } 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()) { diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 467d8af97..6d6e79cd2 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -156,6 +156,7 @@ public: } void emitParams(AstNodeModule* modp, bool init, bool* firstp, string& sectionr) { + bool anyi = false; for (AstNode* nodep = modp->stmtsp(); nodep; nodep = nodep->nextp()) { if (const AstVar* varp = VN_CAST(nodep, Var)) { if (varp->isParam() && (varp->isUsedParam() || varp->isSigPublic())) { @@ -172,12 +173,15 @@ public: } } else if (varp->isString()) { if (init) { - emitCtorSep(firstp); - puts(protect("var_" + varp->name()) + " ("); + puts("const std::string "); + puts(prefixNameProtect(modp) + "::" + protect("var_" + varp->name()) + + "("); iterateAndNextNull(varp->valuep()); - puts(")"); + puts(");\n"); + anyi = true; } 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 // putsDecoration("// enum ..... "+varp->nameProtect() @@ -187,10 +191,12 @@ public: ->isOpaque()) { // Can't put out e.g. doubles } else { if (init) { - emitCtorSep(firstp); - puts(protect("var_" + varp->name()) + " ("); + puts(varp->isQuad() ? "const QData " : "const IData "); + puts(prefixNameProtect(modp) + "::" + protect("var_" + varp->name()) + + "("); iterateAndNextNull(varp->valuep()); - puts(")"); + puts(");\n"); + anyi = true; } else { // enum puts(varp->isQuad() ? "enum _QData" : "enum _IData"); @@ -198,13 +204,14 @@ public: iterateAndNextNull(varp->valuep()); puts("};\n"); // var - puts(varp->isQuad() ? "const QData " : "const IData "); + puts(varp->isQuad() ? "static const QData " : "static const IData "); puts(protect("var_" + varp->name()) + ";\n"); } } } } } + if (anyi) puts("\n"); } struct CmpName { @@ -2319,6 +2326,9 @@ void EmitCImp::emitMTaskVertexCtors(bool* firstp) { void EmitCImp::emitCtorImp(AstNodeModule* modp) { puts("\n"); bool first = true; + string section(""); + emitParams(modp, true, &first, section /*ref*/); + if (VN_IS(modp, Class)) { modp->v3fatalSrc("constructors should be AstCFuncs instead"); } else if (optSystemC() && modp->isTop()) { @@ -2329,8 +2339,7 @@ void EmitCImp::emitCtorImp(AstNodeModule* modp) { } emitVarCtors(&first); if (modp->isTop() && v3Global.opt.mtasks()) emitMTaskVertexCtors(&first); - string section(""); - emitParams(modp, true, &first, section /*ref*/); + puts(" {\n"); emitCellCtors(modp); emitSensitives();