From 131623de34752eda18c14ea440602d63389732ee Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 14 Jul 2024 11:39:45 -0400 Subject: [PATCH] Internals: Favor s string literals. No functional change. --- include/verilated_save.cpp | 3 +-- src/V3Assert.cpp | 4 ++-- src/V3AstNodeOther.h | 6 +++--- src/V3AstNodes.cpp | 7 +++---- src/V3Begin.cpp | 2 +- src/V3Descope.cpp | 2 +- src/V3EmitCFunc.cpp | 6 +++--- src/V3EmitCFunc.h | 4 ++-- src/V3EmitCImp.cpp | 4 ++-- src/V3EmitCSyms.cpp | 2 +- src/V3EmitMk.cpp | 18 +++++++++--------- src/V3LinkInc.cpp | 2 +- src/V3LinkJump.cpp | 2 +- src/V3PreProc.cpp | 4 ++-- src/V3Split.cpp | 2 +- src/V3Task.cpp | 4 ++-- 16 files changed, 35 insertions(+), 37 deletions(-) diff --git a/include/verilated_save.cpp b/include/verilated_save.cpp index 361f80091..c2c8e3cdd 100644 --- a/include/verilated_save.cpp +++ b/include/verilated_save.cpp @@ -95,8 +95,7 @@ void VerilatedDeserialize::header() VL_MT_UNSAFE_ONE { if (VL_UNLIKELY(os.readDiffers(VLTSAVE_HEADER_STR, std::strlen(VLTSAVE_HEADER_STR)))) { const std::string fn = filename(); const std::string msg - = std:: - string{"Can't deserialize; file has wrong header signature, or file not found: "} + = "Can't deserialize; file has wrong header signature, or file not found: "s + filename(); VL_FATAL_MT(fn.c_str(), 0, "", msg.c_str()); // Die before we close() as close would infinite loop diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index ddedab65e..df96c4153 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -66,11 +66,11 @@ class AssertVisitor final : public VNVisitor { string assertDisplayMessage(AstNode* nodep, const string& prefix, const string& message, VDisplayType severity) { if (severity == VDisplayType::DT_ERROR || severity == VDisplayType::DT_FATAL) { - return (string{"[%0t] " + prefix + ": "} + nodep->fileline()->filebasename() + ":" + return ("[%0t] "s + prefix + ": " + nodep->fileline()->filebasename() + ":" + cvtToStr(nodep->fileline()->lineno()) + ": Assertion failed in %m" + ((message != "") ? ": " : "") + message + "\n"); } else { - return (string{"[%0t] " + prefix + ": "} + nodep->fileline()->filebasename() + ":" + return ("[%0t] "s + prefix + ": " + nodep->fileline()->filebasename() + ":" + cvtToStr(nodep->fileline()->lineno()) + ": %m" + ((message != "") ? ": " : "") + message + "\n"); } diff --git a/src/V3AstNodeOther.h b/src/V3AstNodeOther.h index 985434c97..f1e09defc 100644 --- a/src/V3AstNodeOther.h +++ b/src/V3AstNodeOther.h @@ -1111,7 +1111,7 @@ public: BROKEN_RTN(!fmtp()); return nullptr; } - string verilogKwd() const override { return string{"$"} + string{displayType().ascii()}; } + string verilogKwd() const override { return "$"s + string{displayType().ascii()}; } bool isGateOptimizable() const override { return false; } bool isPredictOptimizable() const override { return false; } bool isPure() override { return false; } // SPECIAL: $display has 'visual' ordering @@ -2894,8 +2894,8 @@ public: return nullptr; } string verilogKwd() const override { - return (filep() ? string{"$f"} + string{displayType().ascii()} - : string{"$"} + string{displayType().ascii()}); + return (filep() ? "$f"s + string{displayType().ascii()} + : "$"s + string{displayType().ascii()}); } bool isGateOptimizable() const override { return false; } bool isPredictOptimizable() const override { return false; } diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 7d9932cf8..3e67a3034 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -672,14 +672,13 @@ string AstVar::dpiTmpVarType(const string& varName) const { string AstVar::scType() const { if (isScBigUint()) { - return (string{"sc_dt::sc_biguint<"} + cvtToStr(widthMin()) + return ("sc_dt::sc_biguint<"s + cvtToStr(widthMin()) + "> "); // Keep the space so don't get >> } else if (isScUint() || isScUintBool()) { - return (string{"sc_dt::sc_uint<"} + cvtToStr(widthMin()) + return ("sc_dt::sc_uint<"s + cvtToStr(widthMin()) + "> "); // Keep the space so don't get >> } else if (isScBv()) { - return (string{"sc_dt::sc_bv<"} + cvtToStr(widthMin()) - + "> "); // Keep the space so don't get >> + return ("sc_dt::sc_bv<"s + cvtToStr(widthMin()) + "> "); // Keep the space so don't get >> } else if (widthMin() == 1) { return "bool"; } else if (widthMin() <= VL_IDATASIZE) { diff --git a/src/V3Begin.cpp b/src/V3Begin.cpp index 088d3f7ed..d79f5187e 100644 --- a/src/V3Begin.cpp +++ b/src/V3Begin.cpp @@ -274,7 +274,7 @@ class BeginVisitor final : public VNVisitor { // To keep correct visual order, must add before other Text's AstText* const afterp = nodep->scopeAttrp(); if (afterp) afterp->unlinkFrBackWithNext(); - nodep->addScopeAttrp(new AstText{nodep->fileline(), string{"__DOT__"} + scname}); + nodep->addScopeAttrp(new AstText{nodep->fileline(), "__DOT__"s + scname}); if (afterp) nodep->addScopeAttrp(afterp); } iterateChildren(nodep); diff --git a/src/V3Descope.cpp b/src/V3Descope.cpp index 2b42fc1be..42c718c9b 100644 --- a/src/V3Descope.cpp +++ b/src/V3Descope.cpp @@ -193,7 +193,7 @@ class DescopeVisitor final : public VNVisitor { // to come up with some return value // newfuncp->addStmtsp(new AstDisplay(newfuncp->fileline(), // VDisplayType::DT_WARNING, - // string{"%%Error: "}+name+"() called with bad + // "%%Error: "s+name+"() called with bad // scope", nullptr)); // newfuncp->addStmtsp(new AstStop(newfuncp->fileline())); if (debug() >= 9) newfuncp->dumpTree("- newfunc: "); diff --git a/src/V3EmitCFunc.cpp b/src/V3EmitCFunc.cpp index 3c934aac9..dc6393bbf 100644 --- a/src/V3EmitCFunc.cpp +++ b/src/V3EmitCFunc.cpp @@ -274,9 +274,9 @@ void EmitCFunc::displayArg(AstNode* dispp, AstNode** elistp, bool isScan, const double dchars = mantissabits / 3.321928094887362 + 1.0; if (fmtLetter == 'd') dchars++; // space for sign const int nchars = int(dchars); - pfmt = string{"%"} + cvtToStr(nchars) + fmtLetter; + pfmt = "%"s + cvtToStr(nchars) + fmtLetter; } else { - pfmt = string{"%"} + vfmt + fmtLetter; + pfmt = "%"s + vfmt + fmtLetter; } m_emitDispState.pushFormat(pfmt); if (!ignore) { @@ -691,7 +691,7 @@ string EmitCFunc::emitVarResetRecurse(const AstVar* varp, const string& varNameP } else if (const AstUnpackArrayDType* const adtypep = VN_CAST(dtypep, UnpackArrayDType)) { UASSERT_OBJ(adtypep->hi() >= adtypep->lo(), varp, "Should have swapped msb & lsb earlier."); - const string ivar = string{"__Vi"} + cvtToStr(depth); + const string ivar = "__Vi"s + cvtToStr(depth); const string pre = ("for (int " + ivar + " = " + cvtToStr(0) + "; " + ivar + " < " + cvtToStr(adtypep->elementsConst()) + "; ++" + ivar + ") {\n"); const string below = emitVarResetRecurse(varp, varNameProtected, adtypep->subDTypep(), diff --git a/src/V3EmitCFunc.h b/src/V3EmitCFunc.h index 54355a473..fa2a102c7 100644 --- a/src/V3EmitCFunc.h +++ b/src/V3EmitCFunc.h @@ -620,7 +620,7 @@ public: if (!v3Global.opt.protectIds()) return; } if (!(nodep->protect() && v3Global.opt.protectIds())) { - putsDecoration(nodep, string{"// "} + nodep->name() + at + "\n"); + putsDecoration(nodep, "// "s + nodep->name() + at + "\n"); } iterateChildrenConst(nodep); } @@ -1458,7 +1458,7 @@ public: // Default void visit(AstNode* nodep) override { - putns(nodep, string{"\n???? // "} + nodep->prettyTypeName() + "\n"); + putns(nodep, "\n???? // "s + nodep->prettyTypeName() + "\n"); iterateChildrenConst(nodep); // LCOV_EXCL_START if (!v3Global.opt.lintOnly()) { // An internal problem, so suppress diff --git a/src/V3EmitCImp.cpp b/src/V3EmitCImp.cpp index 19ba599f4..2023785e7 100644 --- a/src/V3EmitCImp.cpp +++ b/src/V3EmitCImp.cpp @@ -398,7 +398,7 @@ class EmitCImp final : EmitCFunc { const int vecnum = vects++; UASSERT_OBJ(arrayp->hi() >= arrayp->lo(), varp, "Should have swapped msb & lsb earlier."); - const string ivar = string{"__Vi"} + cvtToStr(vecnum); + const string ivar = "__Vi"s + cvtToStr(vecnum); puts("for (int __Vi" + cvtToStr(vecnum) + " = " + cvtToStr(0)); puts("; " + ivar + " < " + cvtToStr(arrayp->elementsConst())); puts("; ++" + ivar + ") {\n"); @@ -412,7 +412,7 @@ class EmitCImp final : EmitCFunc { if (elementp->isWide() && !(basicp && basicp->keyword() == VBasicDTypeKwd::STRING)) { const int vecnum = vects++; - const string ivar = string{"__Vi"} + cvtToStr(vecnum); + const string ivar = "__Vi"s + cvtToStr(vecnum); puts("for (int __Vi" + cvtToStr(vecnum) + " = " + cvtToStr(0)); puts("; " + ivar + " < " + cvtToStr(elementp->widthWords())); puts("; ++" + ivar + ") {\n"); diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 61b555ef2..704e0ca92 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -537,7 +537,7 @@ void EmitCSyms::emitSymHdr() { puts("\n// CONSTRUCTORS\n"); puts(symClassName() + "(VerilatedContext* contextp, const char* namep, " + topClassName() + "* modelp);\n"); - puts(string{"~"} + symClassName() + "();\n"); + puts("~"s + symClassName() + "();\n"); for (const auto& i : m_usesVfinal) { puts("void " + symClassName() + "_" + cvtToStr(i.first) + "("); diff --git a/src/V3EmitMk.cpp b/src/V3EmitMk.cpp index 3d388b455..82c2b88a5 100644 --- a/src/V3EmitMk.cpp +++ b/src/V3EmitMk.cpp @@ -157,9 +157,9 @@ public: of.puts("VERILATOR_ROOT = " + V3OutFormatter::quoteNameControls(V3Options::getenvVERILATOR_ROOT()) + "\n"); of.puts("# SystemC include directory with systemc.h (from $SYSTEMC_INCLUDE)\n"); - of.puts(string{"SYSTEMC_INCLUDE ?= "} + V3Options::getenvSYSTEMC_INCLUDE() + "\n"); + of.puts("SYSTEMC_INCLUDE ?= "s + V3Options::getenvSYSTEMC_INCLUDE() + "\n"); of.puts("# SystemC library directory with libsystemc.a (from $SYSTEMC_LIBDIR)\n"); - of.puts(string{"SYSTEMC_LIBDIR ?= "} + V3Options::getenvSYSTEMC_LIBDIR() + "\n"); + of.puts("SYSTEMC_LIBDIR ?= "s + V3Options::getenvSYSTEMC_LIBDIR() + "\n"); // Only check it if we really need the value if (v3Global.opt.systemC() && !V3Options::systemCFound()) { @@ -170,22 +170,22 @@ public: of.puts("\n### Switches...\n"); of.puts("# C++ code coverage 0/1 (from --prof-c)\n"); - of.puts(string{"VM_PROFC = "} + ((v3Global.opt.profC()) ? "1" : "0") + "\n"); + of.puts("VM_PROFC = "s + ((v3Global.opt.profC()) ? "1" : "0") + "\n"); of.puts("# SystemC output mode? 0/1 (from --sc)\n"); - of.puts(string{"VM_SC = "} + ((v3Global.opt.systemC()) ? "1" : "0") + "\n"); + of.puts("VM_SC = "s + ((v3Global.opt.systemC()) ? "1" : "0") + "\n"); of.puts("# Legacy or SystemC output mode? 0/1 (from --sc)\n"); - of.puts(string{"VM_SP_OR_SC = $(VM_SC)\n"}); + of.puts("VM_SP_OR_SC = $(VM_SC)\n"); of.puts("# Deprecated\n"); - of.puts(string{"VM_PCLI = "} + (v3Global.opt.systemC() ? "0" : "1") + "\n"); + of.puts("VM_PCLI = "s + (v3Global.opt.systemC() ? "0" : "1") + "\n"); of.puts( "# Deprecated: SystemC architecture to find link library path (from $SYSTEMC_ARCH)\n"); - of.puts(string{"VM_SC_TARGET_ARCH = "} + V3Options::getenvSYSTEMC_ARCH() + "\n"); + of.puts("VM_SC_TARGET_ARCH = "s + V3Options::getenvSYSTEMC_ARCH() + "\n"); of.puts("\n### Vars...\n"); of.puts("# Design prefix (from --prefix)\n"); - of.puts(string{"VM_PREFIX = "} + v3Global.opt.prefix() + "\n"); + of.puts("VM_PREFIX = "s + v3Global.opt.prefix() + "\n"); of.puts("# Module prefix (from --prefix)\n"); - of.puts(string{"VM_MODPREFIX = "} + v3Global.opt.modPrefix() + "\n"); + of.puts("VM_MODPREFIX = "s + v3Global.opt.modPrefix() + "\n"); of.puts("# User CFLAGS (from -CFLAGS on Verilator command line)\n"); of.puts("VM_USER_CFLAGS = \\\n"); diff --git a/src/V3LinkInc.cpp b/src/V3LinkInc.cpp index 92ee6d4ed..fdc6aa9b5 100644 --- a/src/V3LinkInc.cpp +++ b/src/V3LinkInc.cpp @@ -246,7 +246,7 @@ class LinkIncVisitor final : public VNVisitor { // Prepare a temporary variable FileLine* const fl = nodep->fileline(); - const string name = string{"__Vincrement"} + cvtToStr(++m_modIncrementsNum); + const string name = "__Vincrement"s + cvtToStr(++m_modIncrementsNum); AstVar* const varp = new AstVar{ fl, VVarType::BLOCKTEMP, name, VFlagChildDType{}, new AstRefDType{fl, AstRefDType::FlagTypeOfExpr{}, readp->cloneTree(true)}}; diff --git a/src/V3LinkJump.cpp b/src/V3LinkJump.cpp index b8eedb473..2bc85cab3 100644 --- a/src/V3LinkJump.cpp +++ b/src/V3LinkJump.cpp @@ -201,7 +201,7 @@ class LinkJumpVisitor final : public VNVisitor { // REPEAT(count,body) -> loop=count,WHILE(loop>0) { body, loop-- } // Note var can be signed or unsigned based on original number. AstNodeExpr* const countp = nodep->countp()->unlinkFrBackWithNext(); - const string name = string{"__Vrepeat"} + cvtToStr(m_modRepeatNum++); + const string name = "__Vrepeat"s + cvtToStr(m_modRepeatNum++); // Spec says value is integral, if negative is ignored AstVar* const varp = new AstVar{nodep->fileline(), VVarType::BLOCKTEMP, name, nodep->findSigned32DType()}; diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 38787946c..3457add27 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -1223,8 +1223,8 @@ int V3PreProcImp::getStateToken() { if (VString::removeWhitespace(string{yyourtext(), yyourleng()}).empty()) { return tok; } else { - error(std::string{"Syntax error in `ifdef () expression; unexpected: '"} - + tokenName(tok) + "'\n"); + error("Syntax error in `ifdef () expression; unexpected: '"s + tokenName(tok) + + "'\n"); } goto next_tok; } diff --git a/src/V3Split.cpp b/src/V3Split.cpp index ca6ef099a..587a057fb 100644 --- a/src/V3Split.cpp +++ b/src/V3Split.cpp @@ -146,7 +146,7 @@ public: SplitVarPostVertex(V3Graph* graphp, AstNode* nodep) : SplitNodeVertex{graphp, nodep} {} ~SplitVarPostVertex() override = default; - string name() const override { return string{"POST "} + SplitNodeVertex::name(); } + string name() const override { return "POST "s + SplitNodeVertex::name(); } string dotColor() const override { return "CadetBlue"; } }; diff --git a/src/V3Task.cpp b/src/V3Task.cpp index 4baa98adb..ceea85b75 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -560,7 +560,7 @@ class TaskVisitor final : public VNVisitor { AstNode* const newbodysp = refp->taskp()->stmtsp() ? refp->taskp()->stmtsp()->cloneTree(true) : nullptr; AstNode* const beginp - = new AstComment{refp->fileline(), string{"Function: "} + refp->name(), true}; + = new AstComment{refp->fileline(), "Function: "s + refp->name(), true}; if (newbodysp) beginp->addNext(newbodysp); if (debug() >= 9) beginp->dumpTreeAndNext(cout, "- newbegi: "); // @@ -612,7 +612,7 @@ class TaskVisitor final : public VNVisitor { UASSERT_OBJ(cfuncp, refp, "No non-inline task associated with this task call?"); // AstNode* const beginp - = new AstComment{refp->fileline(), string{"Function: "} + refp->name(), true}; + = new AstComment{refp->fileline(), "Function: "s + refp->name(), true}; AstNodeCCall* ccallp; if (VN_IS(refp, New)) { AstCNew* const cnewp = new AstCNew{refp->fileline(), cfuncp};