Internals: Favor s string literals. No functional change.

This commit is contained in:
Wilson Snyder 2024-07-14 11:39:45 -04:00
parent 74ae879c2f
commit 131623de34
16 changed files with 35 additions and 37 deletions

View File

@ -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

View File

@ -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");
}

View File

@ -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; }

View File

@ -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) {

View File

@ -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);

View File

@ -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: ");

View File

@ -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(),

View File

@ -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

View File

@ -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");

View File

@ -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) + "(");

View File

@ -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");

View File

@ -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)}};

View File

@ -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()};

View File

@ -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;
}

View File

@ -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"; }
};

View File

@ -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};