From 22687a6901ce22cccdc8d6ea0ea45c4c7c093f8b Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 28 Jan 2024 20:24:28 -0500 Subject: [PATCH] Internals: Use C++14 quoted literal std::string --- include/verilated.cpp | 22 ++++++++++------------ include/verilated_cov.cpp | 8 ++++---- include/verilated_imp.h | 2 +- include/verilated_save.cpp | 3 +-- include/verilated_types.h | 4 ++-- include/verilated_vcd_c.cpp | 3 +-- include/verilated_vpi.cpp | 3 +-- src/V3Ast.h | 2 +- src/V3Common.cpp | 2 +- src/V3Coverage.cpp | 18 ++++++++---------- src/V3EmitCModel.cpp | 2 +- src/V3EmitV.cpp | 4 ++-- src/V3Error.cpp | 2 +- src/V3File.cpp | 21 ++++++++++----------- src/V3FileLine.cpp | 2 +- src/V3HierBlock.cpp | 2 +- src/V3Inline.cpp | 6 ++---- src/V3Name.cpp | 4 ++-- src/V3Number.cpp | 2 +- src/V3OptionParser.cpp | 4 +--- src/V3Options.cpp | 4 ++-- src/V3Param.cpp | 2 +- src/V3ParseSym.h | 2 +- src/V3PartitionGraph.h | 4 ++-- src/V3PreProc.cpp | 26 ++++++++++++-------------- src/V3PreShell.cpp | 4 ++-- src/V3ProtectLib.cpp | 12 +++++------- src/V3Scope.cpp | 2 +- src/V3Simulate.h | 4 ++-- src/V3Stats.cpp | 2 +- src/V3String.h | 2 +- src/V3Trace.cpp | 4 ++-- src/V3TraceDecl.cpp | 2 +- src/V3Unroll.cpp | 2 +- src/config_build.h | 1 + src/verilog.y | 2 +- test_regress/t/t_dpi_var.cpp | 6 +++--- test_regress/t/t_vpi_zero_time_cb.cpp | 2 +- 38 files changed, 92 insertions(+), 107 deletions(-) diff --git a/include/verilated.cpp b/include/verilated.cpp index 948e1ca57..68dfc00eb 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -943,7 +943,7 @@ void _vl_vsformat(std::string& output, const std::string& format, va_list ap) VL if (VL_SIGN_E(lbits, lwp[VL_WORDS_I(lbits) - 1])) { VlWide neg; VL_NEGATE_W(VL_WORDS_I(lbits), neg, lwp); - append = std::string{"-"} + VL_DECIMAL_NW(lbits, neg); + append = "-"s + VL_DECIMAL_NW(lbits, neg); } else { append = VL_DECIMAL_NW(lbits, lwp); } @@ -1085,7 +1085,7 @@ void _vl_vsformat(std::string& output, const std::string& format, va_list ap) VL } break; default: { // LCOV_EXCL_START - const std::string msg = std::string{"Unknown _vl_vsformat code: "} + pos[0]; + const std::string msg = "Unknown _vl_vsformat code: "s + pos[0]; VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); break; } // LCOV_EXCL_STOP @@ -1367,7 +1367,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf break; } default: { // LCOV_EXCL_START - const std::string msg = std::string{"Unknown _vl_vsscanf code: "} + pos[0]; + const std::string msg = "Unknown _vl_vsscanf code: "s + pos[0]; VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); break; } // LCOV_EXCL_STOP @@ -1727,7 +1727,7 @@ std::string VL_STACKTRACE_N() VL_MT_SAFE { if (!strings) return "Unable to backtrace\n"; std::string result = "Backtrace:\n"; - for (int j = 0; j < nptrs; j++) result += std::string{strings[j]} + std::string{"\n"}; + for (int j = 0; j < nptrs; j++) result += std::string{strings[j]} + "\n"s; free(strings); return result; } @@ -2990,7 +2990,7 @@ void Verilated::nullPointerError(const char* filename, int linenum) VL_MT_SAFE { void Verilated::overWidthError(const char* signame) VL_MT_SAFE { // Slowpath - Called only when signal sets too high of a bit - const std::string msg = (std::string{"Testbench C set input '"} + signame + const std::string msg = ("Testbench C set input '"s + signame + "' to value that overflows what the signal's width can fit"); VL_FATAL_MT("unknown", 0, "", msg.c_str()); VL_UNREACHABLE; @@ -3212,8 +3212,7 @@ void VerilatedScope::varInsert(int finalize, const char* namep, void* datap, boo } else { // We could have a linked list of ranges, but really this whole thing needs // to be generalized to support structs and unions, etc. - const std::string msg - = std::string{"Unsupported multi-dimensional public varInsert: "} + namep; + const std::string msg = "Unsupported multi-dimensional public varInsert: "s + namep; VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); } } @@ -3233,10 +3232,9 @@ VerilatedVar* VerilatedScope::varFind(const char* namep) const VL_MT_SAFE_POSTIN void* VerilatedScope::exportFindNullError(int funcnum) VL_MT_SAFE { // Slowpath - Called only when find has failed - const std::string msg - = (std::string{"Testbench C called '"} + VerilatedImp::exportName(funcnum) - + "' but scope wasn't set, perhaps due to dpi import call without " - + "'context', or missing svSetScope. See IEEE 1800-2017 35.5.3."); + const std::string msg = ("Testbench C called '"s + VerilatedImp::exportName(funcnum) + + "' but scope wasn't set, perhaps due to dpi import call without " + + "'context', or missing svSetScope. See IEEE 1800-2017 35.5.3."); VL_FATAL_MT("unknown", 0, "", msg.c_str()); return nullptr; } @@ -3244,7 +3242,7 @@ void* VerilatedScope::exportFindNullError(int funcnum) VL_MT_SAFE { void* VerilatedScope::exportFindError(int funcnum) const VL_MT_SAFE { // Slowpath - Called only when find has failed const std::string msg - = (std::string{"Testbench C called '"} + VerilatedImp::exportName(funcnum) + = ("Testbench C called '"s + VerilatedImp::exportName(funcnum) + "' but this DPI export function exists only in other scopes, not scope '" + name() + "'"); VL_FATAL_MT("unknown", 0, "", msg.c_str()); diff --git a/include/verilated_cov.cpp b/include/verilated_cov.cpp index 269597508..ad6ca97d9 100644 --- a/include/verilated_cov.cpp +++ b/include/verilated_cov.cpp @@ -168,11 +168,11 @@ private: const std::string& value) VL_PURE { std::string name; if (key.length() == 1 && std::isalpha(key[0])) { - name += std::string{"\001"} + key; + name += "\001"s + key; } else { - name += std::string{"\001"} + dequote(key); + name += "\001"s + dequote(key); } - name += std::string{"\002"} + dequote(value); + name += "\002"s + dequote(value); return name; } static std::string combineHier(const std::string& old, const std::string& add) VL_PURE { @@ -364,7 +364,7 @@ public: std::ofstream os{filename}; if (os.fail()) { - const std::string msg = std::string{"%Error: Can't write '"} + filename + "'"; + const std::string msg = "%Error: Can't write '"s + filename + "'"; VL_FATAL_MT("", 0, "", msg.c_str()); return; } diff --git a/include/verilated_imp.h b/include/verilated_imp.h index 3066ba44d..c3e369e17 100644 --- a/include/verilated_imp.h +++ b/include/verilated_imp.h @@ -552,7 +552,7 @@ public: const VerilatedLockGuard lock{s().m_exportMutex}; const auto& it = s().m_exportMap.find(namep); if (VL_LIKELY(it != s().m_exportMap.end())) return it->second; - const std::string msg = (std::string{"%Error: Testbench C called "} + namep + const std::string msg = ("%Error: Testbench C called "s + namep + " but no such DPI export function name exists in ANY model"); VL_FATAL_MT("unknown", 0, "", msg.c_str()); return -1; diff --git a/include/verilated_save.cpp b/include/verilated_save.cpp index 53518278e..361f80091 100644 --- a/include/verilated_save.cpp +++ b/include/verilated_save.cpp @@ -114,8 +114,7 @@ void VerilatedDeserialize::trailer() VL_MT_UNSAFE_ONE { if (VL_UNLIKELY(os.readDiffers(VLTSAVE_TRAILER_STR, std::strlen(VLTSAVE_TRAILER_STR)))) { const std::string fn = filename(); const std::string msg - = std::string{"Can't deserialize; file has wrong end-of-file signature: "} - + filename(); + = "Can't deserialize; file has wrong end-of-file signature: "s + filename(); VL_FATAL_MT(fn.c_str(), 0, "", msg.c_str()); // Die before we close() as close would infinite loop } diff --git a/include/verilated_types.h b/include/verilated_types.h index 5f33d9869..6ee53a26a 100644 --- a/include/verilated_types.h +++ b/include/verilated_types.h @@ -263,7 +263,7 @@ public: inline std::string VL_TO_STRING(const VlEventBase& e); inline std::string VL_TO_STRING(const VlEvent& e) { - return std::string{"triggered="} + (e.isTriggered() ? "true" : "false"); + return "triggered="s + (e.isTriggered() ? "true" : "false"); } inline std::string VL_TO_STRING(const VlAssignableEvent& e) { @@ -274,7 +274,7 @@ inline std::string VL_TO_STRING(const VlEventBase& e) { if (const VlAssignableEvent& assignable = dynamic_cast(e)) { return VL_TO_STRING(assignable); } - return std::string{"triggered="} + (e.isTriggered() ? "true" : "false"); + return "triggered="s + (e.isTriggered() ? "true" : "false"); } //=================================================================== diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 4de1aa9af..4f6e10854 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -282,8 +282,7 @@ void VerilatedVcd::bufferFlush() VL_MT_UNSAFE_ONE { if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) { // LCOV_EXCL_START // write failed, presume error (perhaps out of disk space) - const std::string msg - = std::string{"VerilatedVcd::bufferFlush: "} + std::strerror(errno); + const std::string msg = "VerilatedVcd::bufferFlush: "s + std::strerror(errno); VL_FATAL_MT("", 0, "", msg.c_str()); closeErr(); break; diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 789065e8b..a129cdf3c 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -1402,8 +1402,7 @@ const char* VerilatedVpiError::strFromVpiConstType(PLI_INT32 constType) VL_PURE #define SELF_CHECK_RESULT_CSTR(got, exp) \ if (0 != std::strcmp((got), (exp))) { \ - const std::string msg \ - = std::string{"%Error: "} + "GOT = '" + (got) + "'" + " EXP = '" + (exp) + "'"; \ + const std::string msg = "%Error: GOT = '"s + (got) + "'" + " EXP = '" + (exp) + "'"; \ VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); \ } diff --git a/src/V3Ast.h b/src/V3Ast.h index f40cd3774..29f7b4151 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1972,7 +1972,7 @@ public: static string prettyName(const string& namein) VL_PURE; // Name for printing out to the user static string vpiName(const string& namein); // Name for vpi access static string prettyNameQ(const string& namein) { // Quoted pretty name (for errors) - return std::string{"'"} + prettyName(namein) + "'"; + return "'"s + prettyName(namein) + "'"; } // Encode user name into internal C representation static string encodeName(const string& namein); diff --git a/src/V3Common.cpp b/src/V3Common.cpp index 47a5451ec..57a489487 100644 --- a/src/V3Common.cpp +++ b/src/V3Common.cpp @@ -98,7 +98,7 @@ static void makeToString(AstClass* nodep) { funcp->isStatic(false); funcp->protect(false); AstCExpr* const exprp - = new AstCExpr{nodep->fileline(), R"(std::string{"'{"} + to_string_middle() + "}")", 0}; + = new AstCExpr{nodep->fileline(), R"("'{"s + to_string_middle() + "}")", 0}; exprp->dtypeSetString(); funcp->addStmtsp(new AstCReturn{nodep->fileline(), exprp}); nodep->addStmtsp(funcp); diff --git a/src/V3Coverage.cpp b/src/V3Coverage.cpp index 9b9e119ed..34b2c8595 100644 --- a/src/V3Coverage.cpp +++ b/src/V3Coverage.cpp @@ -273,7 +273,7 @@ class CoverageVisitor final : public VNVisitor { // We'll do this, and make the if(...) coverinc later. // Add signal to hold the old value - const string newvarname = std::string{"__Vtogcov__"} + nodep->shortName(); + const string newvarname = "__Vtogcov__"s + nodep->shortName(); FileLine* const fl_nowarn = new FileLine{nodep->fileline()}; fl_nowarn->modifyWarnOff(V3ErrorCode::UNUSEDSIGNAL, true); AstVar* const chgVarp @@ -284,7 +284,7 @@ class CoverageVisitor final : public VNVisitor { // This is necessarily an O(n^2) expansion, which is why // we limit coverage to signals with < 256 bits. - ToggleEnt newvec{std::string{""}, new AstVarRef{fl_nowarn, nodep, VAccess::READ}, + ToggleEnt newvec{""s, new AstVarRef{fl_nowarn, nodep, VAccess::READ}, new AstVarRef{fl_nowarn, chgVarp, VAccess::WRITE}}; toggleVarRecurse(nodep->dtypeSkipRefp(), 0, newvec, nodep, chgVarp); newvec.cleanup(); @@ -308,8 +308,7 @@ class CoverageVisitor final : public VNVisitor { for (int index_docs = bdtypep->lo(); index_docs < bdtypep->hi() + 1; ++index_docs) { const int index_code = index_docs - bdtypep->lo(); - ToggleEnt newent{above.m_comment + std::string{"["} + cvtToStr(index_docs) - + "]", + ToggleEnt newent{above.m_comment + "["s + cvtToStr(index_docs) + "]", new AstSel{varp->fileline(), above.m_varRefp->cloneTree(true), index_code, 1}, new AstSel{varp->fileline(), above.m_chgRefp->cloneTree(true), @@ -323,7 +322,7 @@ class CoverageVisitor final : public VNVisitor { } else if (const AstUnpackArrayDType* const adtypep = VN_CAST(dtypep, UnpackArrayDType)) { for (int index_docs = adtypep->lo(); index_docs <= adtypep->hi(); ++index_docs) { const int index_code = index_docs - adtypep->lo(); - ToggleEnt newent{above.m_comment + std::string{"["} + cvtToStr(index_docs) + "]", + ToggleEnt newent{above.m_comment + "["s + cvtToStr(index_docs) + "]", new AstArraySel{varp->fileline(), above.m_varRefp->cloneTree(true), index_code}, new AstArraySel{varp->fileline(), @@ -336,7 +335,7 @@ class CoverageVisitor final : public VNVisitor { for (int index_docs = adtypep->lo(); index_docs <= adtypep->hi(); ++index_docs) { const AstNodeDType* const subtypep = adtypep->subDTypep()->skipRefp(); const int index_code = index_docs - adtypep->lo(); - ToggleEnt newent{above.m_comment + std::string{"["} + cvtToStr(index_docs) + "]", + ToggleEnt newent{above.m_comment + "["s + cvtToStr(index_docs) + "]", new AstSel{varp->fileline(), above.m_varRefp->cloneTree(true), index_code * subtypep->width(), subtypep->width()}, new AstSel{varp->fileline(), above.m_chgRefp->cloneTree(true), @@ -351,7 +350,7 @@ class CoverageVisitor final : public VNVisitor { itemp = VN_AS(itemp->nextp(), MemberDType)) { AstNodeDType* const subtypep = itemp->subDTypep()->skipRefp(); const int index_code = itemp->lsb(); - ToggleEnt newent{above.m_comment + std::string{"."} + itemp->name(), + ToggleEnt newent{above.m_comment + "."s + itemp->name(), new AstSel{varp->fileline(), above.m_varRefp->cloneTree(true), index_code, subtypep->width()}, new AstSel{varp->fileline(), above.m_chgRefp->cloneTree(true), @@ -369,8 +368,7 @@ class CoverageVisitor final : public VNVisitor { varp->fileline(), above.m_varRefp->cloneTree(true), itemp->name()}; varRefp->dtypep(subtypep); chgRefp->dtypep(subtypep); - ToggleEnt newent{above.m_comment + std::string{"."} + itemp->name(), varRefp, - chgRefp}; + ToggleEnt newent{above.m_comment + "."s + itemp->name(), varRefp, chgRefp}; toggleVarRecurse(subtypep, depth + 1, newent, varp, chgVarp); newent.cleanup(); } @@ -379,7 +377,7 @@ class CoverageVisitor final : public VNVisitor { // Arbitrarily handle only the first member of the union if (const AstMemberDType* const itemp = adtypep->membersp()) { AstNodeDType* const subtypep = itemp->subDTypep()->skipRefp(); - ToggleEnt newent{above.m_comment + std::string{"."} + itemp->name(), + ToggleEnt newent{above.m_comment + "."s + itemp->name(), above.m_varRefp->cloneTree(true), above.m_chgRefp->cloneTree(true)}; toggleVarRecurse(subtypep, depth + 1, newent, varp, chgVarp); diff --git a/src/V3EmitCModel.cpp b/src/V3EmitCModel.cpp index c4334fd21..8ed37cbbc 100644 --- a/src/V3EmitCModel.cpp +++ b/src/V3EmitCModel.cpp @@ -309,7 +309,7 @@ class EmitCModel final : public EmitCFunc { const int vecnum = vects++; UASSERT_OBJ(arrayp->hi() >= arrayp->lo(), varp, "Should have swapped msb & lsb earlier."); - const string ivar = std::string{"__Vi"} + cvtToStr(vecnum); + const string ivar = "__Vi"s + cvtToStr(vecnum); putns(varp, "for (int __Vi" + cvtToStr(vecnum) + " = " + cvtToStr(arrayp->lo())); puts("; " + ivar + " <= " + cvtToStr(arrayp->hi())); diff --git a/src/V3EmitV.cpp b/src/V3EmitV.cpp index d3486d0c1..af875dbe5 100644 --- a/src/V3EmitV.cpp +++ b/src/V3EmitV.cpp @@ -205,7 +205,7 @@ class EmitVBaseVisitorConst VL_NOT_FINAL : public EmitCBaseVisitorConst { putqs(nodep, "end\n"); } void visit(AstComment* nodep) override { - puts(std::string{"// "} + nodep->name() + "\n"); + puts("// "s + nodep->name() + "\n"); iterateChildrenConst(nodep); } void visit(AstContinue*) override { @@ -747,7 +747,7 @@ class EmitVBaseVisitorConst VL_NOT_FINAL : public EmitCBaseVisitorConst { void visit(AstCell*) override {} // Handled outside the Visit class // Default void visit(AstNode* nodep) override { - puts(std::string{"\n???? // "} + nodep->prettyTypeName() + "\n"); + puts("\n???? // "s + nodep->prettyTypeName() + "\n"); iterateChildrenConst(nodep); // Not v3fatalSrc so we keep processing if (!m_suppressUnknown) { diff --git a/src/V3Error.cpp b/src/V3Error.cpp index 8c0eb6935..ed1cdc6c7 100644 --- a/src/V3Error.cpp +++ b/src/V3Error.cpp @@ -111,7 +111,7 @@ string V3ErrorGuarded::warnMore() VL_REQUIRES(m_mutex) { return string(msgPrefix void V3ErrorGuarded::suppressThisWarning() VL_REQUIRES(m_mutex) { #ifndef V3ERROR_NO_GLOBAL_ - V3Stats::addStatSum(std::string{"Warnings, Suppressed "} + errorCode().ascii(), 1); + V3Stats::addStatSum("Warnings, Suppressed "s + errorCode().ascii(), 1); #endif errorSuppressed(true); } diff --git a/src/V3File.cpp b/src/V3File.cpp index 8f2446c15..a597b704e 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -877,26 +877,26 @@ string V3OutFormatter::quoteNameControls(const string& namein, // Encode chars into XML string for (const char c : namein) { if (c == '"') { - out += std::string{"""}; + out += """s; } else if (c == '\'') { - out += std::string{"'"}; + out += "'"s; } else if (c == '<') { - out += std::string{"<"}; + out += "<"s; } else if (c == '>') { - out += std::string{">"}; + out += ">"s; } else if (c == '&') { - out += std::string{"&"}; + out += "&"s; } else if (std::isprint(c)) { out += c; } else { - out += std::string{"&#"} + cvtToStr((unsigned int)(c & 0xff)) + ";"; + out += "&#"s + cvtToStr((unsigned int)(c & 0xff)) + ";"; } } } else { // Encode control chars into C style escapes for (const char c : namein) { if (c == '\\' || c == '"') { - out += std::string{"\\"} + c; + out += "\\"s + c; } else if (c == '\n') { out += "\\n"; } else if (c == '\r') { @@ -907,8 +907,8 @@ string V3OutFormatter::quoteNameControls(const string& namein, out += c; } else { // This will also cover \a etc - const string octal = std::string{"\\"} + cvtToStr((c >> 6) & 3) - + cvtToStr((c >> 3) & 7) + cvtToStr(c & 7); + const string octal + = "\\"s + cvtToStr((c >> 6) & 3) + cvtToStr((c >> 3) & 7) + cvtToStr(c & 7); out += octal; } } @@ -955,8 +955,7 @@ void V3OutFile::putsForceIncs() { void V3OutCFile::putsGuard() { UASSERT(!m_guard, "Already called putsGuard in emit file"); m_guard = true; - string var - = VString::upcase(std::string{"VERILATED_"} + V3Os::filenameNonDir(filename()) + "_"); + string var = VString::upcase("VERILATED_"s + V3Os::filenameNonDir(filename()) + "_"); for (char& c : var) { if (!std::isalnum(c)) c = '_'; } diff --git a/src/V3FileLine.cpp b/src/V3FileLine.cpp index d3ab82d47..ba4fd33cc 100644 --- a/src/V3FileLine.cpp +++ b/src/V3FileLine.cpp @@ -203,7 +203,7 @@ string FileLine::xmlDetailedLocation() const { } string FileLine::lineDirectiveStrg(int enterExit) const { - return std::string{"`line "} + cvtToStr(lastLineno()) + " \"" + return "`line "s + cvtToStr(lastLineno()) + " \"" + V3OutFormatter::quoteNameControls(filename()) + "\" " + cvtToStr(enterExit) + "\n"; } diff --git a/src/V3HierBlock.cpp b/src/V3HierBlock.cpp index cffa77359..26aa791d4 100644 --- a/src/V3HierBlock.cpp +++ b/src/V3HierBlock.cpp @@ -253,7 +253,7 @@ class HierBlockUsageCollectVisitor final : public VNVisitorConst { // Don't visit twice if (nodep->user1SetOnce()) return; UINFO(5, "Checking " << nodep->prettyNameQ() << " from " - << (m_hierBlockp ? m_hierBlockp->prettyNameQ() : std::string{"null"}) + << (m_hierBlockp ? m_hierBlockp->prettyNameQ() : "null"s) << std::endl); VL_RESTORER(m_modp); AstModule* const prevHierBlockp = m_hierBlockp; diff --git a/src/V3Inline.cpp b/src/V3Inline.cpp index b7152fa80..f38865a43 100644 --- a/src/V3Inline.cpp +++ b/src/V3Inline.cpp @@ -421,13 +421,11 @@ class InlineRelinkVisitor final : public VNVisitor { // To keep correct visual order, must add before other Text's AstText* afterp = nodep->scopeAttrp(); if (afterp) afterp->unlinkFrBackWithNext(); - nodep->addScopeAttrp( - new AstText{nodep->fileline(), std::string{"__DOT__"} + m_cellp->name()}); + nodep->addScopeAttrp(new AstText{nodep->fileline(), "__DOT__"s + m_cellp->name()}); if (afterp) nodep->addScopeAttrp(afterp); afterp = nodep->scopeEntrp(); if (afterp) afterp->unlinkFrBackWithNext(); - nodep->addScopeEntrp( - new AstText{nodep->fileline(), std::string{"__DOT__"} + m_cellp->name()}); + nodep->addScopeEntrp(new AstText{nodep->fileline(), "__DOT__"s + m_cellp->name()}); if (afterp) nodep->addScopeEntrp(afterp); iterateChildren(nodep); } diff --git a/src/V3Name.cpp b/src/V3Name.cpp index 4631c145e..ac0579c3d 100644 --- a/src/V3Name.cpp +++ b/src/V3Name.cpp @@ -45,7 +45,7 @@ class NameVisitor final : public VNVisitorConst { void rename(AstNode* nodep, bool addPvt) { if (!nodep->user1()) { // Not already done if (addPvt) { - const string newname = std::string{"__PVT__"} + nodep->name(); + const string newname = "__PVT__"s + nodep->name(); nodep->name(newname); nodep->editCountInc(); } else if (VN_IS(nodep, CFunc) && VN_AS(nodep, CFunc)->isConstructor()) { @@ -54,7 +54,7 @@ class NameVisitor final : public VNVisitorConst { if (rsvd != "") { nodep->v3warn(SYMRSVDWORD, "Symbol matches " + rsvd + ": " << nodep->prettyNameQ()); - const string newname = std::string{"__SYM__"} + nodep->name(); + const string newname = "__SYM__"s + nodep->name(); nodep->name(newname); nodep->editCountInc(); } diff --git a/src/V3Number.cpp b/src/V3Number.cpp index 21d4a1e9d..4b4430a60 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -851,7 +851,7 @@ string V3Number::toDecimalS() const VL_MT_STABLE { if (isNegative()) { V3Number lhsNoSign = *this; lhsNoSign.opNegate(*this); - return std::string{"-"} + lhsNoSign.toDecimalU(); + return "-"s + lhsNoSign.toDecimalU(); } else { return toDecimalU(); } diff --git a/src/V3OptionParser.cpp b/src/V3OptionParser.cpp index caec1c707..b1855c462 100644 --- a/src/V3OptionParser.cpp +++ b/src/V3OptionParser.cpp @@ -145,9 +145,7 @@ V3OptionParser::ActionIfs* V3OptionParser::find(const char* optp) { if (act.second->isOnOffAllowed()) { // Find starts with "-no" if (const char* const nop = VString::startsWith(optp, "-no") ? (optp + std::strlen("-no")) : nullptr) { - if (act.first == nop || act.first == (std::string{"-"} + nop)) { - return act.second.get(); - } + if (act.first == nop || act.first == ("-"s + nop)) { return act.second.get(); } } } else if (act.second->isPartialMatchAllowed()) { if (VString::startsWith(optp, act.first)) return act.second.get(); diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 4f3b3d9f4..0d589364c 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -1584,7 +1584,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, }); DECL_OPTION("-Wno-", CbPartialMatch, [fl, &parser](const char* optp) VL_MT_DISABLED { if (!FileLine::globalWarnOff(optp, true)) { - const string fullopt = std::string{"-Wno-"} + optp; + const string fullopt = "-Wno-"s + optp; fl->v3fatal("Unknown warning specified: " << fullopt << parser.getSuggestion(fullopt.c_str())); } @@ -1606,7 +1606,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, const V3ErrorCode code{optp}; if (code == V3ErrorCode::EC_ERROR) { if (!isFuture(optp)) { - const string fullopt = std::string{"-Wwarn-"} + optp; + const string fullopt = "-Wwarn-"s + optp; fl->v3fatal("Unknown warning specified: " << fullopt << parser.getSuggestion(fullopt.c_str())); } diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 57de34d20..8bcb1d2d6 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -367,7 +367,7 @@ class ParamProcessor final { const auto pair = m_valueMap.emplace(hash, 0); if (pair.second) pair.first->second = m_nextValue++; num = pair.first->second; - return std::string{"z"} + cvtToStr(num); + return "z"s + cvtToStr(num); } string moduleCalcName(const AstNodeModule* srcModp, const string& longname) { string newname = longname; diff --git a/src/V3ParseSym.h b/src/V3ParseSym.h index a0a31ee60..9342c2b8a 100644 --- a/src/V3ParseSym.h +++ b/src/V3ParseSym.h @@ -91,7 +91,7 @@ public: void reinsert(AstNode* nodep, VSymEnt* parentp, string name) { if (!parentp) parentp = symCurrentp(); if (name == "") { // New name with space in name so can't collide with users - name = std::string{" anon"} + nodep->type().ascii() + cvtToStr(++s_anonNum); + name = " anon"s + nodep->type().ascii() + cvtToStr(++s_anonNum); } parentp->reinsert(name, findNewTable(nodep)); } diff --git a/src/V3PartitionGraph.h b/src/V3PartitionGraph.h index 2f55cc10e..dd41f2618 100644 --- a/src/V3PartitionGraph.h +++ b/src/V3PartitionGraph.h @@ -84,9 +84,9 @@ public: uint64_t profilerId() const { return m_profilerId; } string cFuncName() const { // If this MTask maps to a C function, this should be the name - return std::string{"__Vmtask"} + "__" + cvtToStr(m_id); + return "__Vmtask"s + "__" + cvtToStr(m_id); } - string name() const override VL_MT_STABLE { return std::string{"mt"} + cvtToStr(id()); } + string name() const override VL_MT_STABLE { return "mt"s + cvtToStr(id()); } string hashName() const { return m_hashName; } void hashName(const string& name) { m_hashName = name; } void dump(std::ostream& str) const { diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 4a8c103f3..5582c2f8f 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -329,7 +329,7 @@ FileLine* V3PreProcImp::defFileline(const string& name) { void V3PreProcImp::define(FileLine* fl, const string& name, const string& value, const string& params, bool cmdline) { UINFO(4, "DEFINE '" << name << "' as '" << value << "' params '" << params << "'" << endl); - if (!V3LanguageWords::isKeyword(std::string{"`"} + name).empty()) { + if (!V3LanguageWords::isKeyword("`"s + name).empty()) { fl->v3error("Attempting to define built-in directive: '`" << name << "' (IEEE 1800-2017 22.5.1)"); } else { @@ -887,7 +887,7 @@ void V3PreProcImp::dumpDefines(std::ostream& os) { void V3PreProcImp::candidateDefines(VSpellCheck* spellerp) { for (DefinesMap::const_iterator it = m_defines.begin(); it != m_defines.end(); ++it) { - spellerp->pushCandidate(std::string{"`"} + it->first); + spellerp->pushCandidate("`"s + it->first); } } @@ -1107,7 +1107,7 @@ int V3PreProcImp::getStateToken() { // IE, `ifdef `MACRO(x): Substitute and come back here when state pops. break; } else { - error(std::string{"Expecting define name. Found: "} + tokenName(tok) + "\n"); + error("Expecting define name. Found: "s + tokenName(tok) + "\n"); goto next_tok; } } @@ -1128,8 +1128,7 @@ int V3PreProcImp::getStateToken() { goto next_tok; } } else { - error(std::string{"Expecting define formal arguments. Found: "} + tokenName(tok) - + "\n"); + error("Expecting define formal arguments. Found: "s + tokenName(tok) + "\n"); goto next_tok; } } @@ -1165,8 +1164,7 @@ int V3PreProcImp::getStateToken() { define(fileline(), m_lastSym, value, formals, false); } } else { - const string msg - = std::string{"Bad define text, unexpected "} + tokenName(tok) + "\n"; + const string msg = "Bad define text, unexpected "s + tokenName(tok) + "\n"; v3fatalSrc(msg); } statePop(); @@ -1182,8 +1180,8 @@ int V3PreProcImp::getStateToken() { } else { UASSERT(!m_defRefs.empty(), "Shouldn't be in DEFPAREN w/o active defref"); const VDefineRef* const refp = &(m_defRefs.top()); - error(std::string{"Expecting ( to begin argument list for define reference `"} - + refp->name() + "\n"); + error("Expecting ( to begin argument list for define reference `"s + refp->name() + + "\n"); statePop(); goto next_tok; } @@ -1282,7 +1280,7 @@ int V3PreProcImp::getStateToken() { break; } else { statePop(); - error(std::string{"Expecting include filename. Found: "} + tokenName(tok) + "\n"); + error("Expecting include filename. Found: "s + tokenName(tok) + "\n"); goto next_tok; } } @@ -1295,7 +1293,7 @@ int V3PreProcImp::getStateToken() { statePop(); goto next_tok; } else { - error(std::string{"Expecting `error string. Found: "} + tokenName(tok) + "\n"); + error("Expecting `error string. Found: "s + tokenName(tok) + "\n"); statePop(); goto next_tok; } @@ -1338,7 +1336,7 @@ int V3PreProcImp::getStateToken() { // multiline "..." without \ escapes. // The spec is silent about this either way; simulators vary std::replace(out.begin(), out.end(), '\n', ' '); - unputString(std::string{"\""} + out + "\""); + unputString("\""s + out + "\""); statePop(); goto next_tok; } else if (tok == VP_EOF) { @@ -1422,7 +1420,7 @@ int V3PreProcImp::getStateToken() { } else { // We want final text of `name, but that would cause // recursion, so use a special character to get it through - unputDefrefString(std::string{"`\032"} + name); + unputDefrefString("`\032"s + name); goto next_tok; } } else { @@ -1510,7 +1508,7 @@ int V3PreProcImp::getStateToken() { case VP_DEFFORM: // Handled by state=ps_DEFFORM; case VP_DEFVALUE: // Handled by state=ps_DEFVALUE; default: // LCOV_EXCL_LINE - v3fatalSrc(std::string{"Internal error: Unexpected token "} + tokenName(tok) + "\n"); + v3fatalSrc("Internal error: Unexpected token "s + tokenName(tok) + "\n"); break; // LCOV_EXCL_LINE } return tok; diff --git a/src/V3PreShell.cpp b/src/V3PreShell.cpp index 44d6a8ff8..fba2ea6ed 100644 --- a/src/V3PreShell.cpp +++ b/src/V3PreShell.cpp @@ -102,8 +102,8 @@ protected: // intervening +ext+ options since it was first encountered. FileLine* const modfileline = new FileLine{modfilename}; modfileline->language(v3Global.opt.fileLanguage(modfilename)); - V3Parse::ppPushText(parsep, (std::string{"`begin_keywords \""} - + modfileline->language().ascii() + "\"\n")); + V3Parse::ppPushText( + parsep, ("`begin_keywords \""s + modfileline->language().ascii() + "\"\n")); // FileLine tracks and frees modfileline } diff --git a/src/V3ProtectLib.cpp b/src/V3ProtectLib.cpp index 9d1efe086..1c43b9658 100644 --- a/src/V3ProtectLib.cpp +++ b/src/V3ProtectLib.cpp @@ -149,18 +149,16 @@ class ProtectVisitor final : public VNVisitor { // Timescale if (v3Global.opt.hierChild() && v3Global.rootp()->timescaleSpecified()) { // Emit timescale for hierarchical Verilation if input HDL specifies timespec - txtp->addText(fl, std::string{"timeunit "} + modp->timeunit().ascii() + ";\n"); - txtp->addText(fl, std::string{"timeprecision "} - + +v3Global.rootp()->timeprecision().ascii() + ";\n"); + txtp->addText(fl, "timeunit "s + modp->timeunit().ascii() + ";\n"); + txtp->addText(fl, + "timeprecision "s + +v3Global.rootp()->timeprecision().ascii() + ";\n"); } else { addComment(txtp, fl, "Precision of submodule" " (commented out to avoid requiring timescale on all modules)"); + addComment(txtp, fl, "timeunit "s + v3Global.rootp()->timeunit().ascii() + ";"); addComment(txtp, fl, - std::string{"timeunit "} + v3Global.rootp()->timeunit().ascii() + ";"); - addComment(txtp, fl, - std::string{"timeprecision "} + v3Global.rootp()->timeprecision().ascii() - + ";\n"); + "timeprecision "s + v3Global.rootp()->timeprecision().ascii() + ";\n"); } // DPI declarations diff --git a/src/V3Scope.cpp b/src/V3Scope.cpp index 6436b9932..0d597cb42 100644 --- a/src/V3Scope.cpp +++ b/src/V3Scope.cpp @@ -303,7 +303,7 @@ class ScopeVisitor final : public VNVisitor { } void visit(AstScopeName* nodep) override { // If there's a %m in the display text, we add a special node that will contain the name() - const string prefix = std::string{"__DOT__"} + m_scopep->name(); + const string prefix = "__DOT__"s + m_scopep->name(); // TOP and above will be the user's name(). // Note 'TOP.' is stripped by scopePrettyName // To keep correct visual order, must add before other Text's diff --git a/src/V3Simulate.h b/src/V3Simulate.h index 10de98e53..35f0077a6 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -366,7 +366,7 @@ private: // Call for node types we know we can't handle checkNodeInfo(nodep); if (optimizable()) { - clearOptimizable(nodep, std::string{"Known unhandled node type "} + nodep->typeName()); + clearOptimizable(nodep, "Known unhandled node type "s + nodep->typeName()); } } void badNodeType(AstNode* nodep) { @@ -1130,7 +1130,7 @@ private: nodep, "Argument for $display like statement is not constant"); break; } - const string pformat = std::string{"%"} + width + pos[0]; + const string pformat = "%"s + width + pos[0]; result += constp->num().displayed(nodep, pformat); } else { switch (std::tolower(pos[0])) { diff --git a/src/V3Stats.cpp b/src/V3Stats.cpp index f133f6776..0312c6458 100644 --- a/src/V3Stats.cpp +++ b/src/V3Stats.cpp @@ -156,7 +156,7 @@ public: // Branch predictions for (int t = 0; t < VBranchPred::_ENUM_END; ++t) { if (const uint64_t c = m_counters.m_statPred[t]) { - addStat(std::string{"Branch prediction, "} + VBranchPred{t}.ascii(), c); + addStat("Branch prediction, "s + VBranchPred{t}.ascii(), c); } } } diff --git a/src/V3String.h b/src/V3String.h index 0fc795399..5c2f007de 100644 --- a/src/V3String.h +++ b/src/V3String.h @@ -250,7 +250,7 @@ public: if (candidate.empty()) { return ""; } else { - return std::string{"... Suggested alternative: '"} + candidate + "'"; + return "... Suggested alternative: '"s + candidate + "'"; } } static void selfTest(); diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index 44d7e807d..5fc03e40a 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -714,8 +714,8 @@ class TraceVisitor final : public VNVisitor { m_regFuncp->addStmtsp(new AstText{fl, ", vlSelf);\n", true}); // Clear global activity flag - cleanupFuncp->addStmtsp(new AstCStmt{m_topScopep->fileline(), - std::string{"vlSymsp->__Vm_activity = false;\n"}}); + cleanupFuncp->addStmtsp( + new AstCStmt{m_topScopep->fileline(), "vlSymsp->__Vm_activity = false;\n"s}); // Clear fine grained activity flags for (uint32_t i = 0; i < m_activityNumber; ++i) { diff --git a/src/V3TraceDecl.cpp b/src/V3TraceDecl.cpp index 088573c84..1ccba54aa 100644 --- a/src/V3TraceDecl.cpp +++ b/src/V3TraceDecl.cpp @@ -240,7 +240,7 @@ class TraceDeclVisitor final : public VNVisitor { void addIgnore(const char* why) { ++m_statIgnSigs; - std::string cmt = std::string{"Tracing: "} + m_traName + " // Ignored: " + why; + std::string cmt = "Tracing: "s + m_traName + " // Ignored: " + why; if (debug() > 3 && m_traVscp) std::cout << "- " << m_traVscp->fileline() << cmt << endl; } diff --git a/src/V3Unroll.cpp b/src/V3Unroll.cpp index b7bc3ab9c..b19fec241 100644 --- a/src/V3Unroll.cpp +++ b/src/V3Unroll.cpp @@ -59,7 +59,7 @@ class UnrollVisitor final : public VNVisitor { nodep->v3warn(E_UNSUPPORTED, "Unsupported: Can't unroll generate for; " << reason); UINFO(3, " Can't Unroll: " << reason << " :" << nodep << endl); // if (debug() >= 9) nodep->dumpTree("- cant: "); - V3Stats::addStatSum(std::string{"Unrolling gave up, "} + reason, 1); + V3Stats::addStatSum("Unrolling gave up, "s + reason, 1); return false; } diff --git a/src/config_build.h b/src/config_build.h index ca5c9bd7e..770ad2c95 100644 --- a/src/config_build.h +++ b/src/config_build.h @@ -67,6 +67,7 @@ using string = std::string; using std::cout; using std::endl; +using namespace std::literals; // ""s; see SF.7 core guideline //********************************************************************** //**** OS and compiler specifics diff --git a/src/verilog.y b/src/verilog.y index 2fe59b719..877da1b5e 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -384,7 +384,7 @@ int V3ParseGrammar::s_modTypeImpNum = 0; static void ERRSVKWD(FileLine* fileline, const string& tokname) { static int toldonce = 0; fileline->v3error( - std::string{"Unexpected '"} + tokname + "': '" + tokname + "Unexpected '"s + tokname + "': '" + tokname + "' is a SystemVerilog keyword misused as an identifier." + (!toldonce++ ? "\n" + fileline->warnMore() + "... Suggest modify the Verilog-2001 code to avoid SV keywords," diff --git a/test_regress/t/t_dpi_var.cpp b/test_regress/t/t_dpi_var.cpp index 13c3020e0..6da1a12e6 100644 --- a/test_regress/t/t_dpi_var.cpp +++ b/test_regress/t/t_dpi_var.cpp @@ -51,7 +51,7 @@ void mon_class_name(const char* namep) { #endif // Check the C's calling name of "" doesn't lead to extra dots in the name() if (namep && namep[0] == '.') - vl_fatal(__FILE__, __LINE__, "", (std::string{"Unexp class name "} + namep).c_str()); + vl_fatal(__FILE__, __LINE__, "", ("Unexp class name "s + namep).c_str()); } extern "C" void mon_scope_name(const char* namep); @@ -61,9 +61,9 @@ void mon_scope_name(const char* namep) { VL_PRINTF("- mon_scope_name('%s', \"%s\");\n", modp, namep); #endif if (std::strcmp(namep, "t.sub")) - vl_fatal(__FILE__, __LINE__, "", (std::string{"Unexp scope name "} + namep).c_str()); + vl_fatal(__FILE__, __LINE__, "", ("Unexp scope name "s + namep).c_str()); if (std::strcmp(modp, "t.sub")) - vl_fatal(__FILE__, __LINE__, "", (std::string{"Unexp dpiscope name "} + modp).c_str()); + vl_fatal(__FILE__, __LINE__, "", ("Unexp dpiscope name "s + modp).c_str()); } extern "C" void mon_register_b(const char* namep, int isOut); diff --git a/test_regress/t/t_vpi_zero_time_cb.cpp b/test_regress/t/t_vpi_zero_time_cb.cpp index 32cf2fe6a..e19bd7f38 100644 --- a/test_regress/t/t_vpi_zero_time_cb.cpp +++ b/test_regress/t/t_vpi_zero_time_cb.cpp @@ -138,7 +138,7 @@ int main(int argc, char** argv) { void* lib = dlopen(filenamep, RTLD_LAZY); void* bootstrap = dlsym(lib, "vpi_compat_bootstrap"); if (!bootstrap) { - const std::string msg = std::string{"%Error: Could not dlopen "} + filenamep; + const std::string msg = "%Error: Could not dlopen "s + filenamep; vl_fatal(__FILE__, __LINE__, "main", msg.c_str()); } ((void (*)(void))bootstrap)();