From 5b4448de23eae9c6ef49bbd0f69c9bf206548c55 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 26 Mar 2021 23:22:52 -0400 Subject: [PATCH] Internals: Add some std::'s. No functional change intended. --- src/V3Error.cpp | 4 ++-- src/V3Number.h | 3 ++- src/V3Param.cpp | 2 +- src/V3ProtectLib.cpp | 2 +- src/V3Table.cpp | 2 +- src/VlcBucket.h | 2 +- src/VlcPoint.h | 8 ++++---- src/VlcTop.cpp | 15 ++++++++------- 8 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/V3Error.cpp b/src/V3Error.cpp index f9e0701ad..13e506916 100644 --- a/src/V3Error.cpp +++ b/src/V3Error.cpp @@ -77,7 +77,7 @@ void V3Error::init() { string V3Error::lineStr(const char* filename, int lineno) { std::ostringstream out; - const char* fnslashp = strrchr(filename, '/'); + const char* fnslashp = std::strrchr(filename, '/'); if (fnslashp) filename = fnslashp + 1; out << filename << ":" << std::dec << lineno << ":"; const char* const spaces = " "; @@ -167,7 +167,7 @@ void V3Error::vlAbortOrExit() { void V3Error::vlAbort() { VL_GCOV_FLUSH(); - abort(); + std::abort(); } //====================================================================== diff --git a/src/V3Number.h b/src/V3Number.h index 248461947..ab1bc4dd2 100644 --- a/src/V3Number.h +++ b/src/V3Number.h @@ -30,7 +30,8 @@ // Return if two numbers within Epsilon of each other inline bool v3EpsilonEqual(double a, double b) { - return fabs(a - b) <= (std::numeric_limits::epsilon() * std::max(1.0, std::max(a, b))); + return std::fabs(a - b) + <= (std::numeric_limits::epsilon() * std::max(1.0, std::max(a, b))); } //============================================================================ diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 0ff23444c..8b7ba30d6 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -276,7 +276,7 @@ class ParamProcessor final { if (AstVar* varp = VN_CAST(stmtp, Var)) { if (varp->isGParam() || varp->isIfaceRef()) { char ch = varp->name()[0]; - ch = toupper(ch); + ch = std::toupper(ch); if (ch < 'A' || ch > 'Z') ch = 'Z'; varp->user4(usedLetter[static_cast(ch)] * 256 + ch); usedLetter[static_cast(ch)]++; diff --git a/src/V3ProtectLib.cpp b/src/V3ProtectLib.cpp index b7327c2be..ec267187c 100644 --- a/src/V3ProtectLib.cpp +++ b/src/V3ProtectLib.cpp @@ -321,7 +321,7 @@ private: + " library, " "Verliog (%u) and library (%u) hash values do not " "agree\\n\", protectlib_hash__V, expected_hash__V);\n"); - txtp->addText(fl, "exit(EXIT_FAILURE);\n"); + txtp->addText(fl, "std::exit(EXIT_FAILURE);\n"); txtp->addText(fl, "}\n"); txtp->addText(fl, "}\n\n"); diff --git a/src/V3Table.cpp b/src/V3Table.cpp index 6e35b8d10..c31adb692 100644 --- a/src/V3Table.cpp +++ b/src/V3Table.cpp @@ -116,7 +116,7 @@ private: // Calc data storage in bytes size_t chgWidth = m_outVarps.size(); // Width of one change-it-vector if (chgWidth < 8) chgWidth = 8; - double space = (pow(static_cast(2.0), static_cast(m_inWidth)) + double space = (std::pow(static_cast(2.0), static_cast(m_inWidth)) * static_cast(m_outWidth + chgWidth)); // Instruction count bytes (ok, it's space also not time :) double bytesPerInst = 4; diff --git a/src/VlcBucket.h b/src/VlcBucket.h index e68483af2..3add0dd46 100644 --- a/src/VlcBucket.h +++ b/src/VlcBucket.h @@ -39,7 +39,7 @@ private: if (m_dataSize < point) m_dataSize = (point + 64) & ~63ULL; // Keep power of two m_dataSize *= 2; // UINFO(9, "Realloc "<(realloc(m_datap, allocSize())); + vluint64_t* newp = static_cast(std::realloc(m_datap, allocSize())); if (VL_UNCOVERABLE(!newp)) { // cppcheck-suppress doubleFree // cppcheck 1.90 bug - realloc doesn't free on fail free(m_datap); // LCOV_EXCL_LINE diff --git a/src/VlcPoint.h b/src/VlcPoint.h index 8be685d2c..8e20f999d 100644 --- a/src/VlcPoint.h +++ b/src/VlcPoint.h @@ -56,16 +56,16 @@ public: string type() const { return keyExtract(VL_CIK_TYPE); } string thresh() const { return keyExtract(VL_CIK_THRESH); } // string as maybe "" string linescov() const { return keyExtract(VL_CIK_LINESCOV); } - int lineno() const { return atoi(keyExtract(VL_CIK_LINENO).c_str()); } - int column() const { return atoi(keyExtract(VL_CIK_COLUMN).c_str()); } + int lineno() const { return std::atoi(keyExtract(VL_CIK_LINENO).c_str()); } + int column() const { return std::atoi(keyExtract(VL_CIK_COLUMN).c_str()); } // METHODS string keyExtract(const char* shortKey) const { // Hot function - size_t shortLen = strlen(shortKey); + size_t shortLen = std::strlen(shortKey); const string namestr = name(); for (const char* cp = namestr.c_str(); *cp; ++cp) { if (*cp == '\001') { - if (0 == strncmp(cp + 1, shortKey, shortLen) && cp[shortLen + 1] == '\002') { + if (0 == std::strncmp(cp + 1, shortKey, shortLen) && cp[shortLen + 1] == '\002') { cp += shortLen + 2; // Skip \001+short+\002 const char* ep = cp; while (*ep && *ep != '\001') ++ep; diff --git a/src/VlcTop.cpp b/src/VlcTop.cpp index 021e875c4..5999e8ba3 100644 --- a/src/VlcTop.cpp +++ b/src/VlcTop.cpp @@ -45,7 +45,7 @@ void VlcTop::readCoverage(const string& filename, bool nonfatal) { if (line[secspace] == '\'' && line[secspace + 1] == ' ') break; } string point = line.substr(3, secspace - 3); - vluint64_t hits = atoll(line.c_str() + secspace + 1); + vluint64_t hits = std::atoll(line.c_str() + secspace + 1); // UINFO(9," point '"<= thresh); UINFO(9, "AnnoCalc count " << filename << ":" << lineno << ":" << point.column() << " " << point.count() << " " << point.linescov() << '\n'); @@ -225,12 +226,12 @@ void VlcTop::annotateCalc() { range = false; } else if (*covp == '-') { range = true; - } else if (isdigit(*covp)) { + } else if (std::isdigit(*covp)) { const char* digitsp = covp; - while (isdigit(*covp)) ++covp; + while (std::isdigit(*covp)) ++covp; --covp; // Will inc in for loop - if (!range) start = atoi(digitsp); - end = atoi(digitsp); + if (!range) start = std::atoi(digitsp); + end = std::atoi(digitsp); } } } @@ -314,7 +315,7 @@ void VlcTop::annotateOutputFiles(const string& dirname) { // Multiple columns on same line; print line just once string indent; for (string::const_iterator pos = line.begin(); - pos != line.end() && isspace(*pos); ++pos) { + pos != line.end() && std::isspace(*pos); ++pos) { indent += *pos; } line = indent + "verilator_coverage: (next point on previous line)\n";