diff --git a/include/verilated.cpp b/include/verilated.cpp index cbe5655fd..6d2dbcb21 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -61,7 +61,7 @@ typedef union { // Global variables // Slow path variables -VerilatedMutex Verilated::m_mutex; +VerilatedMutex Verilated::s_mutex; // Keep below together in one cache line Verilated::Serialized Verilated::s_s; @@ -685,7 +685,7 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA // Note uses a single buffer internally; presumes only one usage per printf // Note also assumes variables < 64 are not wide, this assumption is // sometimes not true in low-level routines written here in verilated.cpp - static VL_THREAD_LOCAL char tmp[VL_VALUE_STRING_MAX_WIDTH]; + static VL_THREAD_LOCAL char t_tmp[VL_VALUE_STRING_MAX_WIDTH]; const char* pctp = nullptr; // Most recent %##.##g format bool inPct = false; bool widthSet = false; @@ -763,11 +763,11 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA if (lbits) {} // UNUSED - always 64 if (fmt == '^') { // Realtime if (!widthSet) width = VerilatedImp::timeFormatWidth(); - output += _vl_vsformat_time(tmp, d, left, width); + output += _vl_vsformat_time(t_tmp, d, left, width); } else { std::string fmts(pctp, pos - pctp + 1); - sprintf(tmp, fmts.c_str(), d); - output += tmp; + sprintf(t_tmp, fmts.c_str(), d); + output += t_tmp; } break; } @@ -811,9 +811,9 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA int digits = 0; std::string append; if (lbits <= VL_QUADSIZE) { - digits = sprintf(tmp, "%" VL_PRI64 "d", + digits = sprintf(t_tmp, "%" VL_PRI64 "d", static_cast(VL_EXTENDS_QQ(lbits, lbits, ld))); - append = tmp; + append = t_tmp; } else { if (VL_SIGN_E(lbits, lwp[VL_WORDS_I(lbits) - 1])) { WData neg[VL_VALUE_STRING_MAX_WIDTH / 4 + 2]; @@ -840,8 +840,8 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA int digits = 0; std::string append; if (lbits <= VL_QUADSIZE) { - digits = sprintf(tmp, "%" VL_PRI64 "u", ld); - append = tmp; + digits = sprintf(t_tmp, "%" VL_PRI64 "u", ld); + append = t_tmp; } else { append = VL_DECIMAL_NW(lbits, lwp); digits = append.length(); @@ -860,7 +860,7 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA } case 't': { // Time if (!widthSet) width = VerilatedImp::timeFormatWidth(); - output += _vl_vsformat_time(tmp, static_cast(ld), left, width); + output += _vl_vsformat_time(t_tmp, static_cast(ld), left, width); break; } case 'b': @@ -1034,7 +1034,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf // Read a Verilog $sscanf/$fscanf style format into the output list // The format must be pre-processed (and lower cased) by Verilator // Arguments are in "width, arg-value (or WDataIn* if wide)" form - static VL_THREAD_LOCAL char tmp[VL_VALUE_STRING_MAX_WIDTH]; + static VL_THREAD_LOCAL char t_tmp[VL_VALUE_STRING_MAX_WIDTH]; int floc = fbits - 1; IData got = 0; bool inPct = false; @@ -1098,13 +1098,13 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf } case 's': { _vl_vsss_skipspace(fp, floc, fromp, fstr); - _vl_vsss_read_str(fp, floc, fromp, fstr, tmp, nullptr); - if (!tmp[0]) goto done; + _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, nullptr); + if (!t_tmp[0]) goto done; if (owp) { - int lpos = (static_cast(strlen(tmp))) - 1; + int lpos = (static_cast(strlen(t_tmp))) - 1; int lsb = 0; for (int i = 0; i < obits && lpos >= 0; --lpos) { - _vl_vsss_setbit(owp, obits, lsb, 8, tmp[lpos]); + _vl_vsss_setbit(owp, obits, lsb, 8, t_tmp[lpos]); lsb += 8; } } @@ -1112,10 +1112,10 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf } case 'd': { // Signed decimal _vl_vsss_skipspace(fp, floc, fromp, fstr); - _vl_vsss_read_str(fp, floc, fromp, fstr, tmp, "0123456789+-xXzZ?_"); - if (!tmp[0]) goto done; + _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "0123456789+-xXzZ?_"); + if (!t_tmp[0]) goto done; vlsint64_t ld = 0; - sscanf(tmp, "%30" VL_PRI64 "d", &ld); + sscanf(t_tmp, "%30" VL_PRI64 "d", &ld); VL_SET_WQ(owp, ld); break; } @@ -1123,46 +1123,47 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf case 'e': case 'g': { // Real number _vl_vsss_skipspace(fp, floc, fromp, fstr); - _vl_vsss_read_str(fp, floc, fromp, fstr, tmp, "+-.0123456789eE"); - if (!tmp[0]) goto done; + _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "+-.0123456789eE"); + if (!t_tmp[0]) goto done; // cppcheck-suppress unusedStructMember // It's used union { double r; vlsint64_t ld; } u; - u.r = strtod(tmp, nullptr); + u.r = strtod(t_tmp, nullptr); VL_SET_WQ(owp, u.ld); break; } case 't': // FALLTHRU // Time case '#': { // Unsigned decimal _vl_vsss_skipspace(fp, floc, fromp, fstr); - _vl_vsss_read_str(fp, floc, fromp, fstr, tmp, "0123456789+-xXzZ?_"); - if (!tmp[0]) goto done; + _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "0123456789+-xXzZ?_"); + if (!t_tmp[0]) goto done; QData ld = 0; - sscanf(tmp, "%30" VL_PRI64 "u", &ld); + sscanf(t_tmp, "%30" VL_PRI64 "u", &ld); VL_SET_WQ(owp, ld); break; } case 'b': { _vl_vsss_skipspace(fp, floc, fromp, fstr); - _vl_vsss_read_str(fp, floc, fromp, fstr, tmp, "01xXzZ?_"); - if (!tmp[0]) goto done; - _vl_vsss_based(owp, obits, 1, tmp, 0, strlen(tmp)); + _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "01xXzZ?_"); + if (!t_tmp[0]) goto done; + _vl_vsss_based(owp, obits, 1, t_tmp, 0, strlen(t_tmp)); break; } case 'o': { _vl_vsss_skipspace(fp, floc, fromp, fstr); - _vl_vsss_read_str(fp, floc, fromp, fstr, tmp, "01234567xXzZ?_"); - if (!tmp[0]) goto done; - _vl_vsss_based(owp, obits, 3, tmp, 0, strlen(tmp)); + _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "01234567xXzZ?_"); + if (!t_tmp[0]) goto done; + _vl_vsss_based(owp, obits, 3, t_tmp, 0, strlen(t_tmp)); break; } case 'x': { _vl_vsss_skipspace(fp, floc, fromp, fstr); - _vl_vsss_read_str(fp, floc, fromp, fstr, tmp, "0123456789abcdefABCDEFxXzZ?_"); - if (!tmp[0]) goto done; - _vl_vsss_based(owp, obits, 4, tmp, 0, strlen(tmp)); + _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, + "0123456789abcdefABCDEFxXzZ?_"); + if (!t_tmp[0]) goto done; + _vl_vsss_based(owp, obits, 4, t_tmp, 0, strlen(t_tmp)); break; } case 'u': { @@ -1205,7 +1206,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf if (obits == 0) { // Due to inIgnore } else if (obits == -1) { // string std::string* p = va_arg(ap, std::string*); - *p = tmp; + *p = t_tmp; } else if (obits <= VL_BYTESIZE) { CData* p = va_arg(ap, CData*); *p = owp[0]; @@ -1329,58 +1330,58 @@ void VL_FCLOSE_I(IData fdi) VL_MT_SAFE { void VL_FFLUSH_ALL() VL_MT_SAFE { fflush(stdout); } void VL_SFORMAT_X(int obits, CData& destr, const char* formatp, ...) VL_MT_SAFE { - static VL_THREAD_LOCAL std::string output; // static only for speed - output = ""; + static VL_THREAD_LOCAL std::string t_output; // static only for speed + t_output = ""; va_list ap; va_start(ap, formatp); - _vl_vsformat(output, formatp, ap); + _vl_vsformat(t_output, formatp, ap); va_end(ap); - _VL_STRING_TO_VINT(obits, &destr, output.length(), output.c_str()); + _VL_STRING_TO_VINT(obits, &destr, t_output.length(), t_output.c_str()); } void VL_SFORMAT_X(int obits, SData& destr, const char* formatp, ...) VL_MT_SAFE { - static VL_THREAD_LOCAL std::string output; // static only for speed - output = ""; + static VL_THREAD_LOCAL std::string t_output; // static only for speed + t_output = ""; va_list ap; va_start(ap, formatp); - _vl_vsformat(output, formatp, ap); + _vl_vsformat(t_output, formatp, ap); va_end(ap); - _VL_STRING_TO_VINT(obits, &destr, output.length(), output.c_str()); + _VL_STRING_TO_VINT(obits, &destr, t_output.length(), t_output.c_str()); } void VL_SFORMAT_X(int obits, IData& destr, const char* formatp, ...) VL_MT_SAFE { - static VL_THREAD_LOCAL std::string output; // static only for speed - output = ""; + static VL_THREAD_LOCAL std::string t_output; // static only for speed + t_output = ""; va_list ap; va_start(ap, formatp); - _vl_vsformat(output, formatp, ap); + _vl_vsformat(t_output, formatp, ap); va_end(ap); - _VL_STRING_TO_VINT(obits, &destr, output.length(), output.c_str()); + _VL_STRING_TO_VINT(obits, &destr, t_output.length(), t_output.c_str()); } void VL_SFORMAT_X(int obits, QData& destr, const char* formatp, ...) VL_MT_SAFE { - static VL_THREAD_LOCAL std::string output; // static only for speed - output = ""; + static VL_THREAD_LOCAL std::string t_output; // static only for speed + t_output = ""; va_list ap; va_start(ap, formatp); - _vl_vsformat(output, formatp, ap); + _vl_vsformat(t_output, formatp, ap); va_end(ap); - _VL_STRING_TO_VINT(obits, &destr, output.length(), output.c_str()); + _VL_STRING_TO_VINT(obits, &destr, t_output.length(), t_output.c_str()); } void VL_SFORMAT_X(int obits, void* destp, const char* formatp, ...) VL_MT_SAFE { - static VL_THREAD_LOCAL std::string output; // static only for speed - output = ""; + static VL_THREAD_LOCAL std::string t_output; // static only for speed + t_output = ""; va_list ap; va_start(ap, formatp); - _vl_vsformat(output, formatp, ap); + _vl_vsformat(t_output, formatp, ap); va_end(ap); - _VL_STRING_TO_VINT(obits, destp, output.length(), output.c_str()); + _VL_STRING_TO_VINT(obits, destp, t_output.length(), t_output.c_str()); } void VL_SFORMAT_X(int obits_ignored, std::string& output, const char* formatp, ...) VL_MT_SAFE { @@ -1393,38 +1394,38 @@ void VL_SFORMAT_X(int obits_ignored, std::string& output, const char* formatp, . } std::string VL_SFORMATF_NX(const char* formatp, ...) VL_MT_SAFE { - static VL_THREAD_LOCAL std::string output; // static only for speed - output = ""; + static VL_THREAD_LOCAL std::string t_output; // static only for speed + t_output = ""; va_list ap; va_start(ap, formatp); - _vl_vsformat(output, formatp, ap); + _vl_vsformat(t_output, formatp, ap); va_end(ap); - return output; + return t_output; } void VL_WRITEF(const char* formatp, ...) VL_MT_SAFE { - static VL_THREAD_LOCAL std::string output; // static only for speed - output = ""; + static VL_THREAD_LOCAL std::string t_output; // static only for speed + t_output = ""; va_list ap; va_start(ap, formatp); - _vl_vsformat(output, formatp, ap); + _vl_vsformat(t_output, formatp, ap); va_end(ap); - VL_PRINTF_MT("%s", output.c_str()); + VL_PRINTF_MT("%s", t_output.c_str()); } void VL_FWRITEF(IData fpi, const char* formatp, ...) VL_MT_SAFE { // While threadsafe, each thread can only access different file handles - static VL_THREAD_LOCAL std::string output; // static only for speed - output = ""; + static VL_THREAD_LOCAL std::string t_output; // static only for speed + t_output = ""; va_list ap; va_start(ap, formatp); - _vl_vsformat(output, formatp, ap); + _vl_vsformat(t_output, formatp, ap); va_end(ap); - VerilatedImp::fdWrite(fpi, output); + VerilatedImp::fdWrite(fpi, t_output); } IData VL_FSCANF_IX(IData fpi, const char* formatp, ...) VL_MT_SAFE { @@ -1645,12 +1646,12 @@ IData VL_VALUEPLUSARGS_INN(int, const std::string& ld, std::string& rdr) VL_MT_S const char* vl_mc_scan_plusargs(const char* prefixp) VL_MT_SAFE { const std::string& match = VerilatedImp::argPlusMatch(prefixp); - static VL_THREAD_LOCAL char outstr[VL_VALUE_STRING_MAX_WIDTH]; + static VL_THREAD_LOCAL char t_outstr[VL_VALUE_STRING_MAX_WIDTH]; if (match.empty()) return nullptr; - outstr[0] = '\0'; - strncat(outstr, match.c_str() + strlen(prefixp) + 1, // +1 to skip the "+" + t_outstr[0] = '\0'; + strncat(t_outstr, match.c_str() + strlen(prefixp) + 1, // +1 to skip the "+" VL_VALUE_STRING_MAX_WIDTH - 1); - return outstr; + return t_outstr; } //=========================================================================== @@ -1756,31 +1757,31 @@ const char* vl_dumpctl_filenamep(bool setit, const std::string& filename) VL_MT_ static const char* memhFormat(int nBits) { assert((nBits >= 1) && (nBits <= 32)); - static VL_THREAD_LOCAL char buf[32]; + static VL_THREAD_LOCAL char t_buf[32]; switch ((nBits - 1) / 4) { - case 0: VL_SNPRINTF(buf, 32, "%%01x"); break; - case 1: VL_SNPRINTF(buf, 32, "%%02x"); break; - case 2: VL_SNPRINTF(buf, 32, "%%03x"); break; - case 3: VL_SNPRINTF(buf, 32, "%%04x"); break; - case 4: VL_SNPRINTF(buf, 32, "%%05x"); break; - case 5: VL_SNPRINTF(buf, 32, "%%06x"); break; - case 6: VL_SNPRINTF(buf, 32, "%%07x"); break; - case 7: VL_SNPRINTF(buf, 32, "%%08x"); break; + case 0: VL_SNPRINTF(t_buf, 32, "%%01x"); break; + case 1: VL_SNPRINTF(t_buf, 32, "%%02x"); break; + case 2: VL_SNPRINTF(t_buf, 32, "%%03x"); break; + case 3: VL_SNPRINTF(t_buf, 32, "%%04x"); break; + case 4: VL_SNPRINTF(t_buf, 32, "%%05x"); break; + case 5: VL_SNPRINTF(t_buf, 32, "%%06x"); break; + case 6: VL_SNPRINTF(t_buf, 32, "%%07x"); break; + case 7: VL_SNPRINTF(t_buf, 32, "%%08x"); break; default: assert(false); break; // LCOV_EXCL_LINE } - return buf; + return t_buf; } static const char* formatBinary(int nBits, vluint32_t bits) { assert((nBits >= 1) && (nBits <= 32)); - static VL_THREAD_LOCAL char buf[64]; + static VL_THREAD_LOCAL char t_buf[64]; for (int i = 0; i < nBits; i++) { bool isOne = bits & (1 << (nBits - 1 - i)); - buf[i] = (isOne ? '1' : '0'); + t_buf[i] = (isOne ? '1' : '0'); } - buf[nBits] = '\0'; - return buf; + t_buf[nBits] = '\0'; + return t_buf; } VlReadMem::VlReadMem(bool hex, int bits, const std::string& filename, QData start, QData end) @@ -2200,7 +2201,7 @@ void VL_TIMEFORMAT_IINI(int units, int precision, const std::string& suffix, // Verilated:: Methods void Verilated::debug(int level) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_debug = level; if (level) { #ifdef VL_DEBUG @@ -2214,11 +2215,11 @@ void Verilated::debug(int level) VL_MT_SAFE { } } void Verilated::randReset(int val) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_randReset = val; } void Verilated::randSeed(int val) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_randSeed = val; vluint64_t newEpoch = s_s.s_randSeedEpoch + 1; if (VL_UNLIKELY(newEpoch == 0)) newEpoch = 1; @@ -2238,41 +2239,41 @@ vluint64_t Verilated::randSeedDefault64() VL_MT_SAFE { } } void Verilated::calcUnusedSigs(bool flag) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_calcUnusedSigs = flag; } void Verilated::errorCount(int val) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_errorCount = val; } void Verilated::errorCountInc() VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); ++s_s.s_errorCount; } void Verilated::errorLimit(int val) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_errorLimit = val; } void Verilated::gotFinish(bool flag) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_gotFinish = flag; } void Verilated::assertOn(bool flag) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_assertOn = flag; } void Verilated::fatalOnVpiError(bool flag) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_fatalOnVpiError = flag; } void Verilated::timeunit(int value) VL_MT_SAFE { if (value < 0) value = -value; // Stored as 0..15 - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_timeunit = value; } void Verilated::timeprecision(int value) VL_MT_SAFE { if (value < 0) value = -value; // Stored as 0..15 - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_s.s_timeprecision = value; #ifdef SYSTEMC_VERSION sc_time sc_res = sc_get_time_resolution(); @@ -2303,15 +2304,15 @@ void Verilated::timeprecision(int value) VL_MT_SAFE { #endif } void Verilated::profThreadsStart(vluint64_t flag) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_ns.s_profThreadsStart = flag; } void Verilated::profThreadsWindow(vluint64_t flag) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); s_ns.s_profThreadsWindow = flag; } void Verilated::profThreadsFilenamep(const char* flagp) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); if (s_ns.s_profThreadsFilenamep) free(const_cast(s_ns.s_profThreadsFilenamep)); s_ns.s_profThreadsFilenamep = strdup(flagp); } @@ -2319,18 +2320,18 @@ void Verilated::profThreadsFilenamep(const char* flagp) VL_MT_SAFE { const char* Verilated::catName(const char* n1, const char* n2, const char* delimiter) VL_MT_SAFE { // Returns new'ed data // Used by symbol table creation to make module names - static VL_THREAD_LOCAL char* strp = nullptr; - static VL_THREAD_LOCAL size_t len = 0; + static VL_THREAD_LOCAL char* t_strp = nullptr; + static VL_THREAD_LOCAL size_t t_len = 0; size_t newlen = strlen(n1) + strlen(n2) + strlen(delimiter) + 1; - if (!strp || newlen > len) { - if (strp) delete[] strp; - strp = new char[newlen]; - len = newlen; + if (!t_strp || newlen > t_len) { + if (t_strp) delete[] t_strp; + t_strp = new char[newlen]; + t_len = newlen; } - strcpy(strp, n1); - if (*n1) strcat(strp, delimiter); - strcat(strp, n2); - return strp; + strcpy(t_strp, n1); + if (*n1) strcat(t_strp, delimiter); + strcat(t_strp, n2); + return t_strp; } //========================================================================= @@ -2356,15 +2357,15 @@ static void runCallbacks(VoidPCbList& cbs) VL_MT_SAFE { } void Verilated::addFlushCb(VoidPCb cb, void* datap) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); addCb(cb, datap, g_flushCbs); } void Verilated::removeFlushCb(VoidPCb cb, void* datap) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); removeCb(cb, datap, g_flushCbs); } void Verilated::runFlushCallbacks() VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); runCallbacks(g_flushCbs); fflush(stderr); fflush(stdout); @@ -2375,15 +2376,15 @@ void Verilated::runFlushCallbacks() VL_MT_SAFE { } void Verilated::addExitCb(VoidPCb cb, void* datap) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); addCb(cb, datap, g_exitCbs); } void Verilated::removeExitCb(VoidPCb cb, void* datap) VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); removeCb(cb, datap, g_exitCbs); } void Verilated::runExitCallbacks() VL_MT_SAFE { - const VerilatedLockGuard lock(m_mutex); + const VerilatedLockGuard lock(s_mutex); runCallbacks(g_exitCbs); } @@ -2399,11 +2400,11 @@ void Verilated::commandArgs(int argc, const char** argv) VL_MT_SAFE { const char* Verilated::commandArgsPlusMatch(const char* prefixp) VL_MT_SAFE { const std::string& match = VerilatedImp::argPlusMatch(prefixp); - static VL_THREAD_LOCAL char outstr[VL_VALUE_STRING_MAX_WIDTH]; + static VL_THREAD_LOCAL char t_outstr[VL_VALUE_STRING_MAX_WIDTH]; if (match.empty()) return ""; - outstr[0] = '\0'; - strncat(outstr, match.c_str(), VL_VALUE_STRING_MAX_WIDTH - 1); - return outstr; + t_outstr[0] = '\0'; + strncat(t_outstr, match.c_str(), VL_VALUE_STRING_MAX_WIDTH - 1); + return t_outstr; } void Verilated::nullPointerError(const char* filename, int linenum) VL_MT_SAFE { diff --git a/include/verilated.h b/include/verilated.h index a9f59436f..d8e8badb0 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -371,7 +371,7 @@ public: class Verilated final { // MEMBERS // Slow path variables - static VerilatedMutex m_mutex; ///< Mutex for s_s/s_ns members, when VL_THREADED + static VerilatedMutex s_mutex; ///< Mutex for s_s/s_ns members, when VL_THREADED static struct Serialized { // All these members serialized/deserialized // Fast path diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 4b47a6c62..fe730dbfa 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -159,9 +159,9 @@ public: const VerilatedScope* scopep() const { return m_scopep; } virtual const char* name() const override { return m_varp->name(); } virtual const char* fullname() const override { - static VL_THREAD_LOCAL std::string out; - out = std::string(m_scopep->name()) + "." + name(); - return out.c_str(); + static VL_THREAD_LOCAL std::string t_out; + t_out = std::string(m_scopep->name()) + "." + name(); + return t_out.c_str(); } }; @@ -252,9 +252,9 @@ public: virtual const VerilatedRange* rangep() const override { return &get_range(); } virtual const char* name() const override { return m_varp->name(); } virtual const char* fullname() const override { - static VL_THREAD_LOCAL std::string out; - out = std::string(m_scopep->name()) + "." + name(); - return out.c_str(); + static VL_THREAD_LOCAL std::string t_out; + t_out = std::string(m_scopep->name()) + "." + name(); + return t_out.c_str(); } void* prevDatap() const { return m_prevDatap; } void* varDatap() const { return m_varDatap; } @@ -282,11 +282,11 @@ public: virtual vluint32_t size() const override { return varp()->packed().elements(); } virtual const VerilatedRange* rangep() const override { return &(varp()->packed()); } virtual const char* fullname() const override { - static VL_THREAD_LOCAL std::string out; + static VL_THREAD_LOCAL std::string t_out; char num[20]; sprintf(num, "%d", m_index); - out = std::string(scopep()->name()) + "." + name() + "[" + num + "]"; - return out.c_str(); + t_out = std::string(scopep()->name()) + "." + name() + "[" + num + "]"; + return t_out.c_str(); } }; @@ -568,14 +568,14 @@ public: } void setMessage(const std::string& file, PLI_INT32 line, const char* message, ...) { // message cannot be a const string& as va_start cannot use a reference - static VL_THREAD_LOCAL std::string filehold; + static VL_THREAD_LOCAL std::string t_filehold; va_list args; va_start(args, message); VL_VSNPRINTF(m_buff, sizeof(m_buff), message, args); va_end(args); m_errorInfo.state = vpiPLI; - filehold = file; - setError((PLI_BYTE8*)m_buff, nullptr, const_cast(filehold.c_str()), line); + t_filehold = file; + setError((PLI_BYTE8*)m_buff, nullptr, const_cast(t_filehold.c_str()), line); } p_vpi_error_info getError() { if (m_flag) return &m_errorInfo; @@ -1419,34 +1419,34 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, const char* fullname) { if (!vl_check_format(varp, valuep, fullname, true)) return; // Maximum required size is for binary string, one byte per bit plus null termination - static VL_THREAD_LOCAL char outStr[1 + VL_MULS_MAX_WORDS * 32]; + static VL_THREAD_LOCAL char t_outStr[1 + VL_MULS_MAX_WORDS * 32]; // cppcheck-suppress variableScope - static VL_THREAD_LOCAL int outStrSz = sizeof(outStr) - 1; + static VL_THREAD_LOCAL int t_outStrSz = sizeof(t_outStr) - 1; // We used to presume vpiValue.format = vpiIntVal or if single bit vpiScalarVal // This may cause backward compatibility issues with older code. if (valuep->format == vpiVectorVal) { // Vector pointer must come from our memory pool // It only needs to persist until the next vpi_get_value - static VL_THREAD_LOCAL t_vpi_vecval out[VL_MULS_MAX_WORDS * 2]; - valuep->value.vector = out; + static VL_THREAD_LOCAL t_vpi_vecval t_out[VL_MULS_MAX_WORDS * 2]; + valuep->value.vector = t_out; if (varp->vltype() == VLVT_UINT8) { - out[0].aval = *(reinterpret_cast(varDatap)); - out[0].bval = 0; + t_out[0].aval = *(reinterpret_cast(varDatap)); + t_out[0].bval = 0; return; } else if (varp->vltype() == VLVT_UINT16) { - out[0].aval = *(reinterpret_cast(varDatap)); - out[0].bval = 0; + t_out[0].aval = *(reinterpret_cast(varDatap)); + t_out[0].bval = 0; return; } else if (varp->vltype() == VLVT_UINT32) { - out[0].aval = *(reinterpret_cast(varDatap)); - out[0].bval = 0; + t_out[0].aval = *(reinterpret_cast(varDatap)); + t_out[0].bval = 0; return; } else if (varp->vltype() == VLVT_UINT64) { QData data = *(reinterpret_cast(varDatap)); - out[1].aval = static_cast(data >> 32ULL); - out[1].bval = 0; - out[0].aval = static_cast(data); - out[0].bval = 0; + t_out[1].aval = static_cast(data >> 32ULL); + t_out[1].bval = 0; + t_out[0].aval = static_cast(data); + t_out[0].bval = 0; return; } else if (varp->vltype() == VLVT_WDATA) { int words = VL_WORDS_I(varp->packed().elements()); @@ -1457,47 +1457,47 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, } WDataInP datap = (reinterpret_cast(varDatap)); for (int i = 0; i < words; ++i) { - out[i].aval = datap[i]; - out[i].bval = 0; + t_out[i].aval = datap[i]; + t_out[i].bval = 0; } return; } } else if (valuep->format == vpiBinStrVal) { - valuep->value.str = outStr; + valuep->value.str = t_outStr; int bits = varp->packed().elements(); CData* datap = (reinterpret_cast(varDatap)); int i; - if (bits > outStrSz) { + if (bits > t_outStrSz) { // limit maximum size of output to size of buffer to prevent overrun. - bits = outStrSz; + bits = t_outStrSz; _VL_VPI_WARNING( __FILE__, __LINE__, "%s: Truncating string value of %s for %s" " as buffer size (%d, VL_MULS_MAX_WORDS=%d) is less than required (%d)", - VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname, outStrSz, + VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname, t_outStrSz, VL_MULS_MAX_WORDS, bits); } for (i = 0; i < bits; ++i) { char val = (datap[i >> 3] >> (i & 7)) & 1; - outStr[bits - i - 1] = val ? '1' : '0'; + t_outStr[bits - i - 1] = val ? '1' : '0'; } - outStr[i] = '\0'; + t_outStr[i] = '\0'; return; } else if (valuep->format == vpiOctStrVal) { - valuep->value.str = outStr; + valuep->value.str = t_outStr; int chars = (varp->packed().elements() + 2) / 3; int bytes = VL_BYTES_I(varp->packed().elements()); CData* datap = (reinterpret_cast(varDatap)); int i; - if (chars > outStrSz) { + if (chars > t_outStrSz) { // limit maximum size of output to size of buffer to prevent overrun. _VL_VPI_WARNING( __FILE__, __LINE__, "%s: Truncating string value of %s for %s" " as buffer size (%d, VL_MULS_MAX_WORDS=%d) is less than required (%d)", - VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname, outStrSz, + VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname, t_outStrSz, VL_MULS_MAX_WORDS, chars); - chars = outStrSz; + chars = t_outStrSz; } for (i = 0; i < chars; ++i) { div_t idx = div(i * 3, 8); @@ -1518,44 +1518,44 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, val &= (1 << rem) - 1; } } - outStr[chars - i - 1] = '0' + (val & 7); + t_outStr[chars - i - 1] = '0' + (val & 7); } - outStr[i] = '\0'; + t_outStr[i] = '\0'; return; } else if (valuep->format == vpiDecStrVal) { - valuep->value.str = outStr; + valuep->value.str = t_outStr; // outStrSz does not include nullptr termination so add one if (varp->vltype() == VLVT_UINT8) { - VL_SNPRINTF(outStr, outStrSz + 1, "%hhu", + VL_SNPRINTF(t_outStr, t_outStrSz + 1, "%hhu", static_cast(*(reinterpret_cast(varDatap)))); return; } else if (varp->vltype() == VLVT_UINT16) { - VL_SNPRINTF(outStr, outStrSz + 1, "%hu", + VL_SNPRINTF(t_outStr, t_outStrSz + 1, "%hu", static_cast(*(reinterpret_cast(varDatap)))); return; } else if (varp->vltype() == VLVT_UINT32) { - VL_SNPRINTF(outStr, outStrSz + 1, "%u", + VL_SNPRINTF(t_outStr, t_outStrSz + 1, "%u", static_cast(*(reinterpret_cast(varDatap)))); return; } else if (varp->vltype() == VLVT_UINT64) { - VL_SNPRINTF(outStr, outStrSz + 1, "%llu", + VL_SNPRINTF(t_outStr, t_outStrSz + 1, "%llu", static_cast(*(reinterpret_cast(varDatap)))); return; } } else if (valuep->format == vpiHexStrVal) { - valuep->value.str = outStr; + valuep->value.str = t_outStr; int chars = (varp->packed().elements() + 3) >> 2; CData* datap = (reinterpret_cast(varDatap)); int i; - if (chars > outStrSz) { + if (chars > t_outStrSz) { // limit maximum size of output to size of buffer to prevent overrun. _VL_VPI_WARNING( __FILE__, __LINE__, "%s: Truncating string value of %s for %s" " as buffer size (%d, VL_MULS_MAX_WORDS=%d) is less than required (%d)", - VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname, outStrSz, + VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname, t_outStrSz, VL_MULS_MAX_WORDS, chars); - chars = outStrSz; + chars = t_outStrSz; } for (i = 0; i < chars; ++i) { char val = (datap[i >> 1] >> ((i & 1) << 2)) & 15; @@ -1568,35 +1568,35 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, val &= (1 << rem) - 1; } } - outStr[chars - i - 1] = "0123456789abcdef"[static_cast(val)]; + t_outStr[chars - i - 1] = "0123456789abcdef"[static_cast(val)]; } - outStr[i] = '\0'; + t_outStr[i] = '\0'; return; } else if (valuep->format == vpiStringVal) { if (varp->vltype() == VLVT_STRING) { valuep->value.str = reinterpret_cast(varDatap); return; } else { - valuep->value.str = outStr; + valuep->value.str = t_outStr; int bytes = VL_BYTES_I(varp->packed().elements()); CData* datap = (reinterpret_cast(varDatap)); int i; - if (bytes > outStrSz) { + if (bytes > t_outStrSz) { // limit maximum size of output to size of buffer to prevent overrun. _VL_VPI_WARNING( __FILE__, __LINE__, "%s: Truncating string value of %s for %s" " as buffer size (%d, VL_MULS_MAX_WORDS=%d) is less than required (%d)", - VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname, outStrSz, - VL_MULS_MAX_WORDS, bytes); - bytes = outStrSz; + VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname, + t_outStrSz, VL_MULS_MAX_WORDS, bytes); + bytes = t_outStrSz; } for (i = 0; i < bytes; ++i) { char val = datap[bytes - i - 1]; // other simulators replace [leading?] zero chars with spaces, replicate here. - outStr[i] = val ? val : ' '; + t_outStr[i] = val ? val : ' '; } - outStr[i] = '\0'; + t_outStr[i] = '\0'; return; } } else if (valuep->format == vpiIntVal) { diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index a2b6f8519..db5a803f5 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -1275,13 +1275,13 @@ class EmitVarTspSorter final : public V3TSP::TspStateBase { private: // MEMBERS const MTaskIdSet& m_mtaskIds; // Mtask we're ordering - static unsigned m_serialNext; // Unique ID to establish serial order + static unsigned s_serialNext; // Unique ID to establish serial order unsigned m_serial; // Serial ordering public: // CONSTRUCTORS explicit EmitVarTspSorter(const MTaskIdSet& mtaskIds) : m_mtaskIds(mtaskIds) { // Cannot be {} or GCC 4.8 false warning - m_serial = ++m_serialNext; // Cannot be ()/{} or GCC 4.8 false warning + m_serial = ++s_serialNext; // Cannot be ()/{} or GCC 4.8 false warning } virtual ~EmitVarTspSorter() = default; // METHODS @@ -1308,7 +1308,7 @@ public: } }; -unsigned EmitVarTspSorter::m_serialNext = 0; +unsigned EmitVarTspSorter::s_serialNext = 0; //###################################################################### // Internal EmitC implementation diff --git a/src/V3TSP.cpp b/src/V3TSP.cpp index 140815c74..95348cbbb 100644 --- a/src/V3TSP.cpp +++ b/src/V3TSP.cpp @@ -499,7 +499,7 @@ public: TspTestState(unsigned xpos, unsigned ypos) : m_xpos{xpos} , m_ypos{ypos} - , m_serial{++m_serialNext} {} + , m_serial{++s_serialNext} {} ~TspTestState() = default; virtual int cost(const TspStateBase* otherp) const override { return cost(dynamic_cast(otherp)); @@ -530,10 +530,10 @@ private: unsigned m_xpos; unsigned m_ypos; unsigned m_serial; - static unsigned m_serialNext; + static unsigned s_serialNext; }; -unsigned TspTestState::m_serialNext = 0; +unsigned TspTestState::s_serialNext = 0; void V3TSP::selfTestStates() { // Linear test -- coords all along the x-axis