Internals: Add some std::'s. No functional change intended.

This commit is contained in:
Wilson Snyder 2021-03-26 21:23:18 -04:00
parent ee25114a00
commit ca01d6f18d
17 changed files with 156 additions and 152 deletions

View File

@ -105,7 +105,7 @@ void vl_finish(const char* filename, int linenum, const char* hier) VL_MT_UNSAFE
"- %s:%d: Second verilog $finish, exiting\n", filename, linenum); "- %s:%d: Second verilog $finish, exiting\n", filename, linenum);
Verilated::runFlushCallbacks(); Verilated::runFlushCallbacks();
Verilated::runExitCallbacks(); Verilated::runExitCallbacks();
exit(0); std::exit(0);
} }
Verilated::threadContextp()->gotFinish(true); Verilated::threadContextp()->gotFinish(true);
} }
@ -150,7 +150,7 @@ void vl_fatal(const char* filename, int linenum, const char* hier, const char* m
// Callbacks prior to termination // Callbacks prior to termination
Verilated::runExitCallbacks(); Verilated::runExitCallbacks();
abort(); std::abort();
} }
#endif #endif
@ -279,7 +279,7 @@ static vluint32_t vl_sys_rand32() VL_MT_UNSAFE {
const VerilatedLockGuard lock(s_mutex); // Otherwise rand is unsafe const VerilatedLockGuard lock(s_mutex); // Otherwise rand is unsafe
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
// Windows doesn't have lrand48(), although Cygwin does. // Windows doesn't have lrand48(), although Cygwin does.
return (rand() << 16) ^ rand(); return (std::rand() << 16) ^ std::rand();
#else #else
return (lrand48() << 16) ^ lrand48(); return (lrand48() << 16) ^ lrand48();
#endif #endif
@ -581,10 +581,10 @@ double VL_ITOR_D_W(int lbits, WDataInP lwp) VL_PURE {
EData ihi = lwp[ms_word]; EData ihi = lwp[ms_word];
EData imid = lwp[ms_word - 1]; EData imid = lwp[ms_word - 1];
EData ilo = lwp[ms_word - 2]; EData ilo = lwp[ms_word - 2];
double hi = static_cast<double>(ihi) * exp2(2 * VL_EDATASIZE); double hi = static_cast<double>(ihi) * std::exp2(2 * VL_EDATASIZE);
double mid = static_cast<double>(imid) * exp2(VL_EDATASIZE); double mid = static_cast<double>(imid) * std::exp2(VL_EDATASIZE);
double lo = static_cast<double>(ilo); double lo = static_cast<double>(ilo);
double d = (hi + mid + lo) * exp2(VL_EDATASIZE * (ms_word - 2)); double d = (hi + mid + lo) * std::exp2(VL_EDATASIZE * (ms_word - 2));
return d; return d;
} }
double VL_ISTOR_D_W(int lbits, WDataInP lwp) VL_PURE { double VL_ISTOR_D_W(int lbits, WDataInP lwp) VL_PURE {
@ -915,14 +915,14 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA
static inline bool _vl_vsss_eof(FILE* fp, int floc) VL_MT_SAFE { static inline bool _vl_vsss_eof(FILE* fp, int floc) VL_MT_SAFE {
if (fp) { if (fp) {
return feof(fp) ? true : false; // true : false to prevent MSVC++ warning return std::feof(fp) ? true : false; // true : false to prevent MSVC++ warning
} else { } else {
return floc < 0; return floc < 0;
} }
} }
static inline void _vl_vsss_advance(FILE* fp, int& floc) VL_MT_SAFE { static inline void _vl_vsss_advance(FILE* fp, int& floc) VL_MT_SAFE {
if (fp) { if (fp) {
fgetc(fp); std::fgetc(fp);
} else { } else {
floc -= 8; floc -= 8;
} }
@ -931,7 +931,7 @@ static inline int _vl_vsss_peek(FILE* fp, int& floc, WDataInP fromp,
const std::string& fstr) VL_MT_SAFE { const std::string& fstr) VL_MT_SAFE {
// Get a character without advancing // Get a character without advancing
if (fp) { if (fp) {
int data = fgetc(fp); int data = std::fgetc(fp);
if (data == EOF) return EOF; if (data == EOF) return EOF;
ungetc(data, fp); ungetc(data, fp);
return data; return data;
@ -949,7 +949,7 @@ static inline void _vl_vsss_skipspace(FILE* fp, int& floc, WDataInP fromp,
const std::string& fstr) VL_MT_SAFE { const std::string& fstr) VL_MT_SAFE {
while (true) { while (true) {
int c = _vl_vsss_peek(fp, floc, fromp, fstr); int c = _vl_vsss_peek(fp, floc, fromp, fstr);
if (c == EOF || !isspace(c)) return; if (c == EOF || !std::isspace(c)) return;
_vl_vsss_advance(fp, floc); _vl_vsss_advance(fp, floc);
} }
} }
@ -959,9 +959,9 @@ static inline void _vl_vsss_read_str(FILE* fp, int& floc, WDataInP fromp, const
char* cp = tmpp; char* cp = tmpp;
while (true) { while (true) {
int c = _vl_vsss_peek(fp, floc, fromp, fstr); int c = _vl_vsss_peek(fp, floc, fromp, fstr);
if (c == EOF || isspace(c)) break; if (c == EOF || std::isspace(c)) break;
if (acceptp && nullptr == strchr(acceptp, c)) break; // String - allow anything if (acceptp && nullptr == std::strchr(acceptp, c)) break; // String - allow anything
if (acceptp) c = tolower(c); // Non-strings we'll simplify if (acceptp) c = std::tolower(c); // Non-strings we'll simplify
*cp++ = c; *cp++ = c;
_vl_vsss_advance(fp, floc); _vl_vsss_advance(fp, floc);
} }
@ -1037,8 +1037,8 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
if (!inPct && pos[0] == '%') { if (!inPct && pos[0] == '%') {
inPct = true; inPct = true;
inIgnore = false; inIgnore = false;
} else if (!inPct && isspace(pos[0])) { // Format spaces } else if (!inPct && std::isspace(pos[0])) { // Format spaces
while (isspace(pos[1])) pos++; while (std::isspace(pos[1])) pos++;
_vl_vsss_skipspace(fp, floc, fromp, fstr); _vl_vsss_skipspace(fp, floc, fromp, fstr);
} else if (!inPct) { // Expected Format } else if (!inPct) { // Expected Format
_vl_vsss_skipspace(fp, floc, fromp, fstr); _vl_vsss_skipspace(fp, floc, fromp, fstr);
@ -1092,7 +1092,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
_vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, nullptr); _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, nullptr);
if (!t_tmp[0]) goto done; if (!t_tmp[0]) goto done;
if (owp) { if (owp) {
int lpos = (static_cast<int>(strlen(t_tmp))) - 1; int lpos = (static_cast<int>(std::strlen(t_tmp))) - 1;
int lsb = 0; int lsb = 0;
for (int i = 0; i < obits && lpos >= 0; --lpos) { for (int i = 0; i < obits && lpos >= 0; --lpos) {
_vl_vsss_setbit(owp, obits, lsb, 8, t_tmp[lpos]); _vl_vsss_setbit(owp, obits, lsb, 8, t_tmp[lpos]);
@ -1106,7 +1106,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
_vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "0123456789+-xXzZ?_"); _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "0123456789+-xXzZ?_");
if (!t_tmp[0]) goto done; if (!t_tmp[0]) goto done;
vlsint64_t ld = 0; vlsint64_t ld = 0;
sscanf(t_tmp, "%30" VL_PRI64 "d", &ld); std::sscanf(t_tmp, "%30" VL_PRI64 "d", &ld);
VL_SET_WQ(owp, ld); VL_SET_WQ(owp, ld);
break; break;
} }
@ -1121,7 +1121,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
double r; double r;
vlsint64_t ld; vlsint64_t ld;
} u; } u;
u.r = strtod(t_tmp, nullptr); u.r = std::strtod(t_tmp, nullptr);
VL_SET_WQ(owp, u.ld); VL_SET_WQ(owp, u.ld);
break; break;
} }
@ -1131,7 +1131,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
_vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "0123456789+-xXzZ?_"); _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "0123456789+-xXzZ?_");
if (!t_tmp[0]) goto done; if (!t_tmp[0]) goto done;
QData ld = 0; QData ld = 0;
sscanf(t_tmp, "%30" VL_PRI64 "u", &ld); std::sscanf(t_tmp, "%30" VL_PRI64 "u", &ld);
VL_SET_WQ(owp, ld); VL_SET_WQ(owp, ld);
break; break;
} }
@ -1139,14 +1139,14 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
_vl_vsss_skipspace(fp, floc, fromp, fstr); _vl_vsss_skipspace(fp, floc, fromp, fstr);
_vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "01xXzZ?_"); _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "01xXzZ?_");
if (!t_tmp[0]) goto done; if (!t_tmp[0]) goto done;
_vl_vsss_based(owp, obits, 1, t_tmp, 0, strlen(t_tmp)); _vl_vsss_based(owp, obits, 1, t_tmp, 0, std::strlen(t_tmp));
break; break;
} }
case 'o': { case 'o': {
_vl_vsss_skipspace(fp, floc, fromp, fstr); _vl_vsss_skipspace(fp, floc, fromp, fstr);
_vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "01234567xXzZ?_"); _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, "01234567xXzZ?_");
if (!t_tmp[0]) goto done; if (!t_tmp[0]) goto done;
_vl_vsss_based(owp, obits, 3, t_tmp, 0, strlen(t_tmp)); _vl_vsss_based(owp, obits, 3, t_tmp, 0, std::strlen(t_tmp));
break; break;
} }
case 'x': { case 'x': {
@ -1154,7 +1154,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf
_vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp, _vl_vsss_read_str(fp, floc, fromp, fstr, t_tmp,
"0123456789abcdefABCDEFxXzZ?_"); "0123456789abcdefABCDEFxXzZ?_");
if (!t_tmp[0]) goto done; if (!t_tmp[0]) goto done;
_vl_vsss_based(owp, obits, 4, t_tmp, 0, strlen(t_tmp)); _vl_vsss_based(owp, obits, 4, t_tmp, 0, std::strlen(t_tmp));
break; break;
} }
case 'u': { case 'u': {
@ -1242,7 +1242,7 @@ void _vl_vint_to_string(int obits, char* destoutp, WDataInP sourcep) VL_MT_SAFE
} }
*destp = '\0'; // Terminate *destp = '\0'; // Terminate
if (!start) { // Drop trailing spaces if (!start) { // Drop trailing spaces
while (isspace(*(destp - 1)) && destp > destoutp) *--destp = '\0'; while (std::isspace(*(destp - 1)) && destp > destoutp) *--destp = '\0';
} }
} }
@ -1297,7 +1297,7 @@ IData VL_FGETS_NI(std::string& dest, IData fpi) VL_MT_SAFE {
IData VL_FERROR_IN(IData, std::string& outputr) VL_MT_SAFE { IData VL_FERROR_IN(IData, std::string& outputr) VL_MT_SAFE {
// We ignore lhs/fpi - IEEE says "most recent error" so probably good enough // We ignore lhs/fpi - IEEE says "most recent error" so probably good enough
IData ret = errno; IData ret = errno;
outputr = std::string(::strerror(ret)); outputr = std::string(::std::strerror(ret));
return ret; return ret;
} }
@ -1479,7 +1479,7 @@ IData VL_FREAD_I(int width, int array_lsb, int array_size, void* memp, IData fpi
// We process a character at a time, as then we don't need to deal // We process a character at a time, as then we don't need to deal
// with changing buffer sizes dynamically, etc. // with changing buffer sizes dynamically, etc.
while (true) { while (true) {
int c = fgetc(fp); int c = std::fgetc(fp);
if (VL_UNLIKELY(c == EOF)) break; if (VL_UNLIKELY(c == EOF)) break;
// Shift value in // Shift value in
IData entry = read_elements + start - array_lsb; IData entry = read_elements + start - array_lsb;
@ -1524,7 +1524,7 @@ IData VL_SYSTEM_IQ(QData lhs) VL_MT_SAFE {
IData VL_SYSTEM_IW(int lhswords, WDataInP lhsp) VL_MT_SAFE { IData VL_SYSTEM_IW(int lhswords, WDataInP lhsp) VL_MT_SAFE {
char filenamez[VL_TO_STRING_MAX_WORDS * VL_EDATASIZE + 1]; char filenamez[VL_TO_STRING_MAX_WORDS * VL_EDATASIZE + 1];
_vl_vint_to_string(lhswords * VL_EDATASIZE, filenamez, lhsp); _vl_vint_to_string(lhswords * VL_EDATASIZE, filenamez, lhsp);
int code = system(filenamez); // Yes, system() is threadsafe int code = std::system(filenamez); // Yes, std::system() is threadsafe
return code >> 8; // Want exit status return code >> 8; // Want exit status
} }
@ -1544,7 +1544,7 @@ IData VL_VALUEPLUSARGS_INW(int rbits, const std::string& ld, WDataOutP rwp) VL_M
} else if (!inPct) { // Normal text } else if (!inPct) { // Normal text
prefix += *posp; prefix += *posp;
} else { // Format character } else { // Format character
switch (tolower(*posp)) { switch (std::tolower(*posp)) {
case '%': case '%':
prefix += *posp; prefix += *posp;
inPct = false; inPct = false;
@ -1562,20 +1562,20 @@ IData VL_VALUEPLUSARGS_INW(int rbits, const std::string& ld, WDataOutP rwp) VL_M
if (match.empty()) return 0; if (match.empty()) return 0;
VL_ZERO_RESET_W(rbits, rwp); VL_ZERO_RESET_W(rbits, rwp);
switch (tolower(fmt)) { switch (std::tolower(fmt)) {
case 'd': { case 'd': {
vlsint64_t lld = 0; vlsint64_t lld = 0;
sscanf(dp, "%30" VL_PRI64 "d", &lld); std::sscanf(dp, "%30" VL_PRI64 "d", &lld);
VL_SET_WQ(rwp, lld); VL_SET_WQ(rwp, lld);
break; break;
} }
case 'b': _vl_vsss_based(rwp, rbits, 1, dp, 0, strlen(dp)); break; case 'b': _vl_vsss_based(rwp, rbits, 1, dp, 0, std::strlen(dp)); break;
case 'o': _vl_vsss_based(rwp, rbits, 3, dp, 0, strlen(dp)); break; case 'o': _vl_vsss_based(rwp, rbits, 3, dp, 0, std::strlen(dp)); break;
case 'h': // FALLTHRU case 'h': // FALLTHRU
case 'x': _vl_vsss_based(rwp, rbits, 4, dp, 0, strlen(dp)); break; case 'x': _vl_vsss_based(rwp, rbits, 4, dp, 0, std::strlen(dp)); break;
case 's': { // string/no conversion case 's': { // string/no conversion
for (int i = 0, lsb = 0, posp = static_cast<int>(strlen(dp)) - 1; i < rbits && posp >= 0; for (int i = 0, lsb = 0, posp = static_cast<int>(std::strlen(dp)) - 1;
--posp) { i < rbits && posp >= 0; --posp) {
_vl_vsss_setbit(rwp, rbits, lsb, 8, dp[posp]); _vl_vsss_setbit(rwp, rbits, lsb, 8, dp[posp]);
lsb += 8; lsb += 8;
} }
@ -1583,19 +1583,19 @@ IData VL_VALUEPLUSARGS_INW(int rbits, const std::string& ld, WDataOutP rwp) VL_M
} }
case 'e': { case 'e': {
double temp = 0.F; double temp = 0.F;
sscanf(dp, "%le", &temp); std::sscanf(dp, "%le", &temp);
VL_SET_WQ(rwp, VL_CVT_Q_D(temp)); VL_SET_WQ(rwp, VL_CVT_Q_D(temp));
break; break;
} }
case 'f': { case 'f': {
double temp = 0.F; double temp = 0.F;
sscanf(dp, "%lf", &temp); std::sscanf(dp, "%lf", &temp);
VL_SET_WQ(rwp, VL_CVT_Q_D(temp)); VL_SET_WQ(rwp, VL_CVT_Q_D(temp));
break; break;
} }
case 'g': { case 'g': {
double temp = 0.F; double temp = 0.F;
sscanf(dp, "%lg", &temp); std::sscanf(dp, "%lg", &temp);
VL_SET_WQ(rwp, VL_CVT_Q_D(temp)); VL_SET_WQ(rwp, VL_CVT_Q_D(temp));
break; break;
} }
@ -1615,7 +1615,7 @@ IData VL_VALUEPLUSARGS_INN(int, const std::string& ld, std::string& rdr) VL_MT_S
} else if (!inPct) { // Normal text } else if (!inPct) { // Normal text
prefix += *posp; prefix += *posp;
} else { // Format character } else { // Format character
switch (tolower(*posp)) { switch (std::tolower(*posp)) {
case '%': case '%':
prefix += *posp; prefix += *posp;
inPct = false; inPct = false;
@ -1638,7 +1638,7 @@ const char* vl_mc_scan_plusargs(const char* prefixp) VL_MT_SAFE {
static VL_THREAD_LOCAL char t_outstr[VL_VALUE_STRING_MAX_WIDTH]; static VL_THREAD_LOCAL char t_outstr[VL_VALUE_STRING_MAX_WIDTH];
if (match.empty()) return nullptr; if (match.empty()) return nullptr;
char* dp = t_outstr; char* dp = t_outstr;
for (const char* sp = match.c_str() + strlen(prefixp) + 1; // +1 to skip the "+" for (const char* sp = match.c_str() + std::strlen(prefixp) + 1; // +1 to skip the "+"
*sp && (dp - t_outstr) < (VL_VALUE_STRING_MAX_WIDTH - 2);) *sp && (dp - t_outstr) < (VL_VALUE_STRING_MAX_WIDTH - 2);)
*dp++ = *sp++; *dp++ = *sp++;
*dp++ = '\0'; *dp++ = '\0';
@ -1658,12 +1658,12 @@ std::string VL_TO_STRING_W(int words, WDataInP obj) {
std::string VL_TOLOWER_NN(const std::string& ld) VL_MT_SAFE { std::string VL_TOLOWER_NN(const std::string& ld) VL_MT_SAFE {
std::string out = ld; std::string out = ld;
for (auto& cr : out) cr = tolower(cr); for (auto& cr : out) cr = std::tolower(cr);
return out; return out;
} }
std::string VL_TOUPPER_NN(const std::string& ld) VL_MT_SAFE { std::string VL_TOUPPER_NN(const std::string& ld) VL_MT_SAFE {
std::string out = ld; std::string out = ld;
for (auto& cr : out) cr = toupper(cr); for (auto& cr : out) cr = std::toupper(cr);
return out; return out;
} }
@ -1763,7 +1763,7 @@ VlReadMem::VlReadMem(bool hex, int bits, const std::string& filename, QData star
, m_end{end} , m_end{end}
, m_addr{start} , m_addr{start}
, m_linenum{0} { , m_linenum{0} {
m_fp = fopen(filename.c_str(), "r"); m_fp = std::fopen(filename.c_str(), "r");
if (VL_UNLIKELY(!m_fp)) { if (VL_UNLIKELY(!m_fp)) {
// We don't report the Verilog source filename as it slow to have to pass it down // We don't report the Verilog source filename as it slow to have to pass it down
VL_FATAL_MT(filename.c_str(), 0, "", "$readmem file not found"); VL_FATAL_MT(filename.c_str(), 0, "", "$readmem file not found");
@ -1773,7 +1773,7 @@ VlReadMem::VlReadMem(bool hex, int bits, const std::string& filename, QData star
} }
VlReadMem::~VlReadMem() { VlReadMem::~VlReadMem() {
if (m_fp) { if (m_fp) {
fclose(m_fp); std::fclose(m_fp);
m_fp = nullptr; m_fp = nullptr;
} }
} }
@ -1790,13 +1790,13 @@ bool VlReadMem::get(QData& addrr, std::string& valuer) {
// We process a character at a time, as then we don't need to deal // We process a character at a time, as then we don't need to deal
// with changing buffer sizes dynamically, etc. // with changing buffer sizes dynamically, etc.
while (true) { while (true) {
int c = fgetc(m_fp); int c = std::fgetc(m_fp);
if (VL_UNLIKELY(c == EOF)) break; if (VL_UNLIKELY(c == EOF)) break;
// printf("%d: Got '%c' Addr%lx IN%d IgE%d IgC%d\n", // printf("%d: Got '%c' Addr%lx IN%d IgE%d IgC%d\n",
// m_linenum, c, m_addr, indata, ignore_to_eol, ignore_to_cmt); // m_linenum, c, m_addr, indata, ignore_to_eol, ignore_to_cmt);
// See if previous data value has completed, and if so return // See if previous data value has completed, and if so return
if (c == '_') continue; // Ignore _ e.g. inside a number if (c == '_') continue; // Ignore _ e.g. inside a number
if (indata && !isxdigit(c) && c != 'x' && c != 'X') { if (indata && !std::isxdigit(c) && c != 'x' && c != 'X') {
// printf("Got data @%lx = %s\n", m_addr, valuer.c_str()); // printf("Got data @%lx = %s\n", m_addr, valuer.c_str());
ungetc(c, m_fp); ungetc(c, m_fp);
addrr = m_addr; addrr = m_addr;
@ -1828,8 +1828,8 @@ bool VlReadMem::get(QData& addrr, std::string& valuer) {
m_addr = 0; m_addr = 0;
} }
// Check for hex or binary digits as file format requests // Check for hex or binary digits as file format requests
else if (isxdigit(c) || (!reading_addr && (c == 'x' || c == 'X'))) { else if (std::isxdigit(c) || (!reading_addr && (c == 'x' || c == 'X'))) {
c = tolower(c); c = std::tolower(c);
int value int value
= (c >= 'a' ? (c == 'x' ? VL_RAND_RESET_I(4) : (c - 'a' + 10)) : (c - '0')); = (c >= 'a' ? (c == 'x' ? VL_RAND_RESET_I(4) : (c - 'a' + 10)) : (c - '0'));
if (reading_addr) { if (reading_addr) {
@ -1863,7 +1863,7 @@ void VlReadMem::setData(void* valuep, const std::string& rhs) {
bool innum = false; bool innum = false;
// Shift value in // Shift value in
for (const auto& i : rhs) { for (const auto& i : rhs) {
char c = tolower(i); char c = std::tolower(i);
int value = (c >= 'a' ? (c == 'x' ? VL_RAND_RESET_I(4) : (c - 'a' + 10)) : (c - '0')); int value = (c >= 'a' ? (c == 'x' ? VL_RAND_RESET_I(4) : (c - 'a' + 10)) : (c - '0'));
if (m_bits <= 8) { if (m_bits <= 8) {
CData* datap = reinterpret_cast<CData*>(valuep); CData* datap = reinterpret_cast<CData*>(valuep);
@ -1901,7 +1901,7 @@ VlWriteMem::VlWriteMem(bool hex, int bits, const std::string& filename, QData st
return; return;
} }
m_fp = fopen(filename.c_str(), "w"); m_fp = std::fopen(filename.c_str(), "w");
if (VL_UNLIKELY(!m_fp)) { if (VL_UNLIKELY(!m_fp)) {
VL_FATAL_MT(filename.c_str(), 0, "", "$writemem file not found"); VL_FATAL_MT(filename.c_str(), 0, "", "$writemem file not found");
// cppcheck-suppress resourceLeak // m_fp is nullptr - bug in cppcheck // cppcheck-suppress resourceLeak // m_fp is nullptr - bug in cppcheck
@ -1910,7 +1910,7 @@ VlWriteMem::VlWriteMem(bool hex, int bits, const std::string& filename, QData st
} }
VlWriteMem::~VlWriteMem() { VlWriteMem::~VlWriteMem() {
if (m_fp) { if (m_fp) {
fclose(m_fp); std::fclose(m_fp);
m_fp = nullptr; m_fp = nullptr;
} }
} }
@ -2355,7 +2355,7 @@ std::string VerilatedContextImp::argPlusMatch(const char* prefixp)
VL_MT_SAFE_EXCLUDES(m_argMutex) { VL_MT_SAFE_EXCLUDES(m_argMutex) {
const VerilatedLockGuard lock(m_argMutex); const VerilatedLockGuard lock(m_argMutex);
// Note prefixp does not include the leading "+" // Note prefixp does not include the leading "+"
size_t len = strlen(prefixp); size_t len = std::strlen(prefixp);
if (VL_UNLIKELY(!m_args.m_argVecLoaded)) { if (VL_UNLIKELY(!m_args.m_argVecLoaded)) {
m_args.m_argVecLoaded = true; // Complain only once m_args.m_argVecLoaded = true; // Complain only once
VL_FATAL_MT("unknown", 0, "", VL_FATAL_MT("unknown", 0, "",
@ -2364,7 +2364,7 @@ std::string VerilatedContextImp::argPlusMatch(const char* prefixp)
} }
for (const auto& i : m_args.m_argVec) { for (const auto& i : m_args.m_argVec) {
if (i[0] == '+') { if (i[0] == '+') {
if (0 == strncmp(prefixp, i.c_str() + 1, len)) return i; if (0 == std::strncmp(prefixp, i.c_str() + 1, len)) return i;
} }
} }
return ""; return "";
@ -2383,7 +2383,7 @@ std::pair<int, char**> VerilatedContextImp::argc_argv() VL_MT_SAFE_EXCLUDES(m_ar
int in = 0; int in = 0;
for (const auto& i : m_args.m_argVec) { for (const auto& i : m_args.m_argVec) {
s_argvp[in] = new char[i.length() + 1]; s_argvp[in] = new char[i.length() + 1];
strcpy(s_argvp[in], i.c_str()); std::strcpy(s_argvp[in], i.c_str());
++in; ++in;
} }
s_argvp[s_argc] = nullptr; s_argvp[s_argc] = nullptr;
@ -2392,14 +2392,14 @@ std::pair<int, char**> VerilatedContextImp::argc_argv() VL_MT_SAFE_EXCLUDES(m_ar
} }
void VerilatedContextImp::commandArgVl(const std::string& arg) { void VerilatedContextImp::commandArgVl(const std::string& arg) {
if (0 == strncmp(arg.c_str(), "+verilator+", strlen("+verilator+"))) { if (0 == std::strncmp(arg.c_str(), "+verilator+", std::strlen("+verilator+"))) {
std::string value; std::string value;
if (arg == "+verilator+debug") { if (arg == "+verilator+debug") {
Verilated::debug(4); Verilated::debug(4);
} else if (commandArgVlValue(arg, "+verilator+debugi+", value /*ref*/)) { } else if (commandArgVlValue(arg, "+verilator+debugi+", value /*ref*/)) {
Verilated::debug(atoi(value.c_str())); Verilated::debug(std::atoi(value.c_str()));
} else if (commandArgVlValue(arg, "+verilator+error+limit+", value /*ref*/)) { } else if (commandArgVlValue(arg, "+verilator+error+limit+", value /*ref*/)) {
errorLimit(atoi(value.c_str())); errorLimit(std::atoi(value.c_str()));
} else if (arg == "+verilator+help") { } else if (arg == "+verilator+help") {
VerilatedImp::versionDump(); VerilatedImp::versionDump();
VL_PRINTF_MT("For help, please see 'verilator --help'\n"); VL_PRINTF_MT("For help, please see 'verilator --help'\n");
@ -2408,15 +2408,15 @@ void VerilatedContextImp::commandArgVl(const std::string& arg) {
} else if (arg == "+verilator+noassert") { } else if (arg == "+verilator+noassert") {
assertOn(false); assertOn(false);
} else if (commandArgVlValue(arg, "+verilator+prof+threads+start+", value /*ref*/)) { } else if (commandArgVlValue(arg, "+verilator+prof+threads+start+", value /*ref*/)) {
profThreadsStart(atoll(value.c_str())); profThreadsStart(std::atoll(value.c_str()));
} else if (commandArgVlValue(arg, "+verilator+prof+threads+window+", value /*ref*/)) { } else if (commandArgVlValue(arg, "+verilator+prof+threads+window+", value /*ref*/)) {
profThreadsWindow(atol(value.c_str())); profThreadsWindow(std::atol(value.c_str()));
} else if (commandArgVlValue(arg, "+verilator+prof+threads+file+", value /*ref*/)) { } else if (commandArgVlValue(arg, "+verilator+prof+threads+file+", value /*ref*/)) {
profThreadsFilename(value); profThreadsFilename(value);
} else if (commandArgVlValue(arg, "+verilator+rand+reset+", value /*ref*/)) { } else if (commandArgVlValue(arg, "+verilator+rand+reset+", value /*ref*/)) {
randReset(atoi(value.c_str())); randReset(std::atoi(value.c_str()));
} else if (commandArgVlValue(arg, "+verilator+seed+", value /*ref*/)) { } else if (commandArgVlValue(arg, "+verilator+seed+", value /*ref*/)) {
randSeed(atoi(value.c_str())); randSeed(std::atoi(value.c_str()));
} else if (arg == "+verilator+V") { } else if (arg == "+verilator+V") {
VerilatedImp::versionDump(); // Someday more info too VerilatedImp::versionDump(); // Someday more info too
VL_FATAL_MT("COMMAND_LINE", 0, "", VL_FATAL_MT("COMMAND_LINE", 0, "",
@ -2433,7 +2433,7 @@ void VerilatedContextImp::commandArgVl(const std::string& arg) {
bool VerilatedContextImp::commandArgVlValue(const std::string& arg, const std::string& prefix, bool VerilatedContextImp::commandArgVlValue(const std::string& arg, const std::string& prefix,
std::string& valuer) { std::string& valuer) {
size_t len = prefix.length(); size_t len = prefix.length();
if (0 == strncmp(prefix.c_str(), arg.c_str(), len)) { if (0 == std::strncmp(prefix.c_str(), arg.c_str(), len)) {
valuer = arg.substr(len); valuer = arg.substr(len);
return true; return true;
} else { } else {
@ -2543,7 +2543,7 @@ const char* Verilated::catName(const char* n1, const char* n2, const char* delim
// Used by symbol table creation to make module names // Used by symbol table creation to make module names
static VL_THREAD_LOCAL char* t_strp = nullptr; static VL_THREAD_LOCAL char* t_strp = nullptr;
static VL_THREAD_LOCAL size_t t_len = 0; static VL_THREAD_LOCAL size_t t_len = 0;
size_t newlen = strlen(n1) + strlen(n2) + strlen(delimiter) + 1; size_t newlen = std::strlen(n1) + std::strlen(n2) + std::strlen(delimiter) + 1;
if (VL_UNLIKELY(!t_strp || newlen > t_len)) { if (VL_UNLIKELY(!t_strp || newlen > t_len)) {
if (t_strp) delete[] t_strp; if (t_strp) delete[] t_strp;
t_strp = new char[newlen]; t_strp = new char[newlen];
@ -2603,8 +2603,8 @@ void Verilated::runFlushCallbacks() VL_MT_SAFE {
runCallbacks(VlCbStatic.s_flushCbs); runCallbacks(VlCbStatic.s_flushCbs);
} }
--s_recursing; --s_recursing;
fflush(stderr); std::fflush(stderr);
fflush(stdout); std::fflush(stdout);
// When running internal code coverage (gcc --coverage, as opposed to // When running internal code coverage (gcc --coverage, as opposed to
// verilator --coverage), dump coverage data to properly cover failing // verilator --coverage), dump coverage data to properly cover failing
// tests. // tests.
@ -2760,7 +2760,7 @@ void VerilatedScope::configure(VerilatedSyms* symsp, const char* prefixp, const
m_type = type; m_type = type;
m_timeunit = timeunit; m_timeunit = timeunit;
{ {
char* namep = new char[strlen(prefixp) + strlen(suffixp) + 2]; char* namep = new char[std::strlen(prefixp) + std::strlen(suffixp) + 2];
char* dp = namep; char* dp = namep;
for (const char* sp = prefixp; *sp;) *dp++ = *sp++; for (const char* sp = prefixp; *sp;) *dp++ = *sp++;
if (*prefixp && *suffixp) *dp++ = '.'; if (*prefixp && *suffixp) *dp++ = '.';
@ -2787,7 +2787,7 @@ void VerilatedScope::exportInsert(int finalize, const char* namep, void* cb) VL_
} }
if (VL_UNLIKELY(!m_callbacksp)) { // First allocation if (VL_UNLIKELY(!m_callbacksp)) { // First allocation
m_callbacksp = new void*[m_funcnumMax]; m_callbacksp = new void*[m_funcnumMax];
memset(m_callbacksp, 0, m_funcnumMax * sizeof(void*)); std::memset(m_callbacksp, 0, m_funcnumMax * sizeof(void*));
} }
m_callbacksp[funcnum] = cb; m_callbacksp[funcnum] = cb;
} }

View File

@ -142,7 +142,7 @@ private:
// Quote any special characters // Quote any special characters
std::string rtn; std::string rtn;
for (const char* pos = text.c_str(); *pos; ++pos) { for (const char* pos = text.c_str(); *pos; ++pos) {
if (!isprint(*pos) || *pos == '%' || *pos == '"') { if (!std::isprint(*pos) || *pos == '%' || *pos == '"') {
char hex[10]; char hex[10];
VL_SNPRINTF(hex, 10, "%%%02X", pos[0]); VL_SNPRINTF(hex, 10, "%%%02X", pos[0]);
rtn += hex; rtn += hex;
@ -158,13 +158,13 @@ private:
// a letter differently, nor want them to rely on our compression... // a letter differently, nor want them to rely on our compression...
// (Considered using numeric keys, but will remain back compatible.) // (Considered using numeric keys, but will remain back compatible.)
if (key.length() < 2) return false; if (key.length() < 2) return false;
if (key.length() == 2 && isdigit(key[1])) return false; if (key.length() == 2 && std::isdigit(key[1])) return false;
return true; return true;
} }
static std::string keyValueFormatter(const std::string& key, static std::string keyValueFormatter(const std::string& key,
const std::string& value) VL_PURE { const std::string& value) VL_PURE {
std::string name; std::string name;
if (key.length() == 1 && isalpha(key[0])) { if (key.length() == 1 && std::isalpha(key[0])) {
name += std::string("\001") + key; name += std::string("\001") + key;
} else { } else {
name += std::string("\001") + dequote(key); name += std::string("\001") + dequote(key);
@ -196,8 +196,8 @@ private:
std::string prefix = std::string(a, apre - a); std::string prefix = std::string(a, apre - a);
// Scan backward to last mismatch // Scan backward to last mismatch
const char* apost = a + strlen(a) - 1; const char* apost = a + std::strlen(a) - 1;
const char* bpost = b + strlen(b) - 1; const char* bpost = b + std::strlen(b) - 1;
while (*apost == *bpost && apost > apre && bpost > bpre) { while (*apost == *bpost && apost > apre && bpost > bpre) {
apost--; apost--;
bpost--; bpost--;
@ -305,7 +305,7 @@ public:
valps[1] = linestr.c_str(); valps[1] = linestr.c_str();
// Default page if not specified // Default page if not specified
const char* fnstartp = m_insertFilenamep; const char* fnstartp = m_insertFilenamep;
while (const char* foundp = strchr(fnstartp, '/')) fnstartp = foundp + 1; while (const char* foundp = std::strchr(fnstartp, '/')) fnstartp = foundp + 1;
const char* fnendp = fnstartp; const char* fnendp = fnstartp;
for (; *fnendp && *fnendp != '.'; fnendp++) {} for (; *fnendp && *fnendp != '.'; fnendp++) {}
std::string page_default = "sp_user/" + std::string(fnstartp, fnendp - fnstartp); std::string page_default = "sp_user/" + std::string(fnstartp, fnendp - fnstartp);

View File

@ -280,12 +280,12 @@ public: // But only for verilated*.cpp
if (m_fdFreeMct.empty()) return 0; if (m_fdFreeMct.empty()) return 0;
IData idx = m_fdFreeMct.back(); IData idx = m_fdFreeMct.back();
m_fdFreeMct.pop_back(); m_fdFreeMct.pop_back();
m_fdps[idx] = fopen(filenamep, "w"); m_fdps[idx] = std::fopen(filenamep, "w");
if (VL_UNLIKELY(!m_fdps[idx])) return 0; if (VL_UNLIKELY(!m_fdps[idx])) return 0;
return (1 << idx); return (1 << idx);
} }
IData fdNew(const char* filenamep, const char* modep) VL_MT_SAFE_EXCLUDES(m_fdMutex) { IData fdNew(const char* filenamep, const char* modep) VL_MT_SAFE_EXCLUDES(m_fdMutex) {
FILE* fp = fopen(filenamep, modep); FILE* fp = std::fopen(filenamep, modep);
if (VL_UNLIKELY(!fp)) return 0; if (VL_UNLIKELY(!fp)) return 0;
// Bit 31 indicates it's a descriptor not a MCD // Bit 31 indicates it's a descriptor not a MCD
const VerilatedLockGuard lock(m_fdMutex); const VerilatedLockGuard lock(m_fdMutex);
@ -308,20 +308,20 @@ public: // But only for verilated*.cpp
void fdFlush(IData fdi) VL_MT_SAFE_EXCLUDES(m_fdMutex) { void fdFlush(IData fdi) VL_MT_SAFE_EXCLUDES(m_fdMutex) {
const VerilatedLockGuard lock(m_fdMutex); const VerilatedLockGuard lock(m_fdMutex);
const VerilatedFpList fdlist = fdToFpList(fdi); const VerilatedFpList fdlist = fdToFpList(fdi);
for (const auto& i : fdlist) fflush(i); for (const auto& i : fdlist) std::fflush(i);
} }
IData fdSeek(IData fdi, IData offset, IData origin) VL_MT_SAFE_EXCLUDES(m_fdMutex) { IData fdSeek(IData fdi, IData offset, IData origin) VL_MT_SAFE_EXCLUDES(m_fdMutex) {
const VerilatedLockGuard lock(m_fdMutex); const VerilatedLockGuard lock(m_fdMutex);
const VerilatedFpList fdlist = fdToFpList(fdi); const VerilatedFpList fdlist = fdToFpList(fdi);
if (VL_UNLIKELY(fdlist.size() != 1)) return 0; if (VL_UNLIKELY(fdlist.size() != 1)) return 0;
return static_cast<IData>( return static_cast<IData>(
fseek(*fdlist.begin(), static_cast<long>(offset), static_cast<int>(origin))); std::fseek(*fdlist.begin(), static_cast<long>(offset), static_cast<int>(origin)));
} }
IData fdTell(IData fdi) VL_MT_SAFE_EXCLUDES(m_fdMutex) { IData fdTell(IData fdi) VL_MT_SAFE_EXCLUDES(m_fdMutex) {
const VerilatedLockGuard lock(m_fdMutex); const VerilatedLockGuard lock(m_fdMutex);
const VerilatedFpList fdlist = fdToFpList(fdi); const VerilatedFpList fdlist = fdToFpList(fdi);
if (VL_UNLIKELY(fdlist.size() != 1)) return 0; if (VL_UNLIKELY(fdlist.size() != 1)) return 0;
return static_cast<IData>(ftell(*fdlist.begin())); return static_cast<IData>(std::ftell(*fdlist.begin()));
} }
void fdWrite(IData fdi, const std::string& output) VL_MT_SAFE_EXCLUDES(m_fdMutex) { void fdWrite(IData fdi, const std::string& output) VL_MT_SAFE_EXCLUDES(m_fdMutex) {
const VerilatedLockGuard lock(m_fdMutex); const VerilatedLockGuard lock(m_fdMutex);
@ -338,14 +338,14 @@ public: // But only for verilated*.cpp
IData idx = VL_MASK_I(31) & fdi; IData idx = VL_MASK_I(31) & fdi;
if (VL_UNLIKELY(idx >= m_fdps.size())) return; if (VL_UNLIKELY(idx >= m_fdps.size())) return;
if (VL_UNLIKELY(!m_fdps[idx])) return; // Already free if (VL_UNLIKELY(!m_fdps[idx])) return; // Already free
fclose(m_fdps[idx]); std::fclose(m_fdps[idx]);
m_fdps[idx] = (FILE*)0; m_fdps[idx] = (FILE*)0;
m_fdFree.push_back(idx); m_fdFree.push_back(idx);
} else { } else {
// MCD case // MCD case
for (int i = 0; (fdi != 0) && (i < 31); i++, fdi >>= 1) { for (int i = 0; (fdi != 0) && (i < 31); i++, fdi >>= 1) {
if (fdi & VL_MASK_I(1)) { if (fdi & VL_MASK_I(1)) {
fclose(m_fdps[i]); std::fclose(m_fdps[i]);
m_fdps[i] = nullptr; m_fdps[i] = nullptr;
m_fdFreeMct.push_back(i); m_fdFreeMct.push_back(i);
} }

View File

@ -83,13 +83,13 @@ VerilatedDeserialize& VerilatedDeserialize::readAssert(const void* __restrict da
void VerilatedSerialize::header() VL_MT_UNSAFE_ONE { void VerilatedSerialize::header() VL_MT_UNSAFE_ONE {
VerilatedSerialize& os = *this; // So can cut and paste standard << code below VerilatedSerialize& os = *this; // So can cut and paste standard << code below
assert((strlen(VLTSAVE_HEADER_STR) & 7) == 0); // Keep aligned assert((std::strlen(VLTSAVE_HEADER_STR) & 7) == 0); // Keep aligned
os.write(VLTSAVE_HEADER_STR, strlen(VLTSAVE_HEADER_STR)); os.write(VLTSAVE_HEADER_STR, std::strlen(VLTSAVE_HEADER_STR));
} }
void VerilatedDeserialize::header() VL_MT_UNSAFE_ONE { void VerilatedDeserialize::header() VL_MT_UNSAFE_ONE {
VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below
if (VL_UNLIKELY(os.readDiffers(VLTSAVE_HEADER_STR, strlen(VLTSAVE_HEADER_STR)))) { if (VL_UNLIKELY(os.readDiffers(VLTSAVE_HEADER_STR, std::strlen(VLTSAVE_HEADER_STR)))) {
std::string fn = filename(); std::string fn = filename();
std::string msg std::string msg
= std::string( = std::string(
@ -102,13 +102,13 @@ void VerilatedDeserialize::header() VL_MT_UNSAFE_ONE {
void VerilatedSerialize::trailer() VL_MT_UNSAFE_ONE { void VerilatedSerialize::trailer() VL_MT_UNSAFE_ONE {
VerilatedSerialize& os = *this; // So can cut and paste standard << code below VerilatedSerialize& os = *this; // So can cut and paste standard << code below
assert((strlen(VLTSAVE_TRAILER_STR) & 7) == 0); // Keep aligned assert((std::strlen(VLTSAVE_TRAILER_STR) & 7) == 0); // Keep aligned
os.write(VLTSAVE_TRAILER_STR, strlen(VLTSAVE_TRAILER_STR)); os.write(VLTSAVE_TRAILER_STR, std::strlen(VLTSAVE_TRAILER_STR));
} }
void VerilatedDeserialize::trailer() VL_MT_UNSAFE_ONE { void VerilatedDeserialize::trailer() VL_MT_UNSAFE_ONE {
VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below
if (VL_UNLIKELY(os.readDiffers(VLTSAVE_TRAILER_STR, strlen(VLTSAVE_TRAILER_STR)))) { if (VL_UNLIKELY(os.readDiffers(VLTSAVE_TRAILER_STR, std::strlen(VLTSAVE_TRAILER_STR)))) {
std::string fn = filename(); std::string fn = filename();
std::string msg = std::string("Can't deserialize; file has wrong end-of-file signature: ") std::string msg = std::string("Can't deserialize; file has wrong end-of-file signature: ")
+ filename(); + filename();
@ -202,7 +202,7 @@ void VerilatedSave::flush() VL_MT_UNSAFE_ONE {
if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) { if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) {
// LCOV_EXCL_START // LCOV_EXCL_START
// write failed, presume error (perhaps out of disk space) // write failed, presume error (perhaps out of disk space)
std::string msg = std::string(__FUNCTION__) + ": " + strerror(errno); std::string msg = std::string(__FUNCTION__) + ": " + std::strerror(errno);
VL_FATAL_MT("", 0, "", msg.c_str()); VL_FATAL_MT("", 0, "", msg.c_str());
close(); close();
break; break;
@ -233,7 +233,7 @@ void VerilatedRestore::fill() VL_MT_UNSAFE_ONE {
if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) { if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) {
// LCOV_EXCL_START // LCOV_EXCL_START
// write failed, presume error (perhaps out of disk space) // write failed, presume error (perhaps out of disk space)
std::string msg = std::string(__FUNCTION__) + ": " + strerror(errno); std::string msg = std::string(__FUNCTION__) + ": " + std::strerror(errno);
VL_FATAL_MT("", 0, "", msg.c_str()); VL_FATAL_MT("", 0, "", msg.c_str());
close(); close();
break; break;

View File

@ -149,7 +149,7 @@ void VlThreadPool::profileDump(const char* filenamep, vluint64_t ticksElapsed)
const VerilatedLockGuard lk(m_mutex); const VerilatedLockGuard lk(m_mutex);
VL_DEBUG_IF(VL_DBG_MSGF("+prof+threads writing to '%s'\n", filenamep);); VL_DEBUG_IF(VL_DBG_MSGF("+prof+threads writing to '%s'\n", filenamep););
FILE* fp = fopen(filenamep, "w"); FILE* fp = std::fopen(filenamep, "w");
if (VL_UNLIKELY(!fp)) { if (VL_UNLIKELY(!fp)) {
VL_FATAL_MT(filenamep, 0, "", "+prof+threads+file file not writable"); VL_FATAL_MT(filenamep, 0, "", "+prof+threads+file file not writable");
// cppcheck-suppress resourceLeak // bug, doesn't realize fp is nullptr // cppcheck-suppress resourceLeak // bug, doesn't realize fp is nullptr
@ -191,5 +191,5 @@ void VlThreadPool::profileDump(const char* filenamep, vluint64_t ticksElapsed)
} }
fprintf(fp, "VLPROF stat ticks %" VL_PRI64 "u\n", ticksElapsed); fprintf(fp, "VLPROF stat ticks %" VL_PRI64 "u\n", ticksElapsed);
fclose(fp); std::fclose(fp);
} }

View File

@ -225,7 +225,7 @@ protected:
void declCode(vluint32_t code, vluint32_t bits, bool tri); void declCode(vluint32_t code, vluint32_t bits, bool tri);
// Is this an escape? // Is this an escape?
bool isScopeEscape(char c) { return c != '\f' && (isspace(c) || c == m_scopeEscape); } bool isScopeEscape(char c) { return c != '\f' && (std::isspace(c) || c == m_scopeEscape); }
// Character that splits scopes. Note whitespace are ALWAYS escapes. // Character that splits scopes. Note whitespace are ALWAYS escapes.
char scopeEscape() { return m_scopeEscape; } char scopeEscape() { return m_scopeEscape; }

View File

@ -45,11 +45,11 @@
static double timescaleToDouble(const char* unitp) { static double timescaleToDouble(const char* unitp) {
char* endp = nullptr; char* endp = nullptr;
double value = strtod(unitp, &endp); double value = std::strtod(unitp, &endp);
// On error so we allow just "ns" to return 1e-9. // On error so we allow just "ns" to return 1e-9.
if (value == 0.0 && endp == unitp) value = 1; if (value == 0.0 && endp == unitp) value = 1;
unitp = endp; unitp = endp;
for (; *unitp && isspace(*unitp); unitp++) {} for (; *unitp && std::isspace(*unitp); unitp++) {}
switch (*unitp) { switch (*unitp) {
case 's': value *= 1e0; break; case 's': value *= 1e0; break;
case 'm': value *= 1e-3; break; case 'm': value *= 1e-3; break;

View File

@ -52,7 +52,7 @@
// This size comes form VCD allowing use of printable ASCII characters between // This size comes form VCD allowing use of printable ASCII characters between
// '!' and '~' inclusive, which are a total of 94 different values. Encoding a // '!' and '~' inclusive, which are a total of 94 different values. Encoding a
// 32 bit code hence needs a maximum of ceil(log94(2**32-1)) == 5 bytes. // 32 bit code hence needs a maximum of std::ceil(log94(2**32-1)) == 5 bytes.
constexpr unsigned VL_TRACE_MAX_VCD_CODE_SIZE = 5; // Maximum length of a VCD string code constexpr unsigned VL_TRACE_MAX_VCD_CODE_SIZE = 5; // Maximum length of a VCD string code
// We use 8 bytes per code in a suffix buffer array. // We use 8 bytes per code in a suffix buffer array.
@ -134,9 +134,9 @@ void VerilatedVcd::openNextImp(bool incFilename) {
// Find _0000.{ext} in filename // Find _0000.{ext} in filename
std::string name = m_filename; std::string name = m_filename;
size_t pos = name.rfind('.'); size_t pos = name.rfind('.');
if (pos > 8 && 0 == strncmp("_cat", name.c_str() + pos - 8, 4) if (pos > 8 && 0 == std::strncmp("_cat", name.c_str() + pos - 8, 4)
&& isdigit(name.c_str()[pos - 4]) && isdigit(name.c_str()[pos - 3]) && std::isdigit(name.c_str()[pos - 4]) && std::isdigit(name.c_str()[pos - 3])
&& isdigit(name.c_str()[pos - 2]) && isdigit(name.c_str()[pos - 1])) { && std::isdigit(name.c_str()[pos - 2]) && std::isdigit(name.c_str()[pos - 1])) {
// Increment code. // Increment code.
if ((++(name[pos - 1])) > '9') { if ((++(name[pos - 1])) > '9') {
name[pos - 1] = '0'; name[pos - 1] = '0';
@ -287,7 +287,7 @@ void VerilatedVcd::bufferResize(vluint64_t minsize) {
char* oldbufp = m_wrBufp; char* oldbufp = m_wrBufp;
m_wrChunkSize = minsize * 2; m_wrChunkSize = minsize * 2;
m_wrBufp = new char[m_wrChunkSize * 8]; m_wrBufp = new char[m_wrChunkSize * 8];
memcpy(m_wrBufp, oldbufp, m_writep - oldbufp); std::memcpy(m_wrBufp, oldbufp, m_writep - oldbufp);
m_writep = m_wrBufp + (m_writep - oldbufp); m_writep = m_wrBufp + (m_writep - oldbufp);
m_wrFlushp = m_wrBufp + m_wrChunkSize * 6; m_wrFlushp = m_wrBufp + m_wrChunkSize * 6;
VL_DO_CLEAR(delete[] oldbufp, oldbufp = nullptr); VL_DO_CLEAR(delete[] oldbufp, oldbufp = nullptr);
@ -314,7 +314,8 @@ void VerilatedVcd::bufferFlush() VL_MT_UNSAFE_ONE {
if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) { if (VL_UNCOVERABLE(errno != EAGAIN && errno != EINTR)) {
// LCOV_EXCL_START // LCOV_EXCL_START
// write failed, presume error (perhaps out of disk space) // write failed, presume error (perhaps out of disk space)
std::string msg = std::string("VerilatedVcd::bufferFlush: ") + strerror(errno); std::string msg
= std::string("VerilatedVcd::bufferFlush: ") + std::strerror(errno);
VL_FATAL_MT("", 0, "", msg.c_str()); VL_FATAL_MT("", 0, "", msg.c_str());
closeErr(); closeErr();
break; break;
@ -360,7 +361,7 @@ void VerilatedVcd::dumpHeader() {
VL_LOCALTIME_R(&tick, &ticktm); VL_LOCALTIME_R(&tick, &ticktm);
constexpr int bufsize = 50; constexpr int bufsize = 50;
char buf[bufsize]; char buf[bufsize];
strftime(buf, bufsize, "%c", &ticktm); std::strftime(buf, bufsize, "%c", &ticktm);
printStr(buf); printStr(buf);
} }
printStr(" $end\n"); printStr(" $end\n");
@ -520,7 +521,8 @@ void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep,
const bool isBit = bits == 1; const bool isBit = bits == 1;
entryp[0] = ' '; // Separator entryp[0] = ' '; // Separator
// Use memcpy as we checked size above, and strcpy is flagged unsafe // Use memcpy as we checked size above, and strcpy is flagged unsafe
std::memcpy(entryp + !isBit, buf, strlen(buf)); // Code (overwrite separator if isBit) std::memcpy(entryp + !isBit, buf,
std::strlen(buf)); // Code (overwrite separator if isBit)
entryp[length + !isBit] = '\n'; // Replace '\0' with line termination '\n' entryp[length + !isBit] = '\n'; // Replace '\0' with line termination '\n'
// Set length of suffix (used to increment write pointer) // Set length of suffix (used to increment write pointer)
entryp[VL_TRACE_SUFFIX_ENTRY_SIZE - 1] = !isBit + length + 1; entryp[VL_TRACE_SUFFIX_ENTRY_SIZE - 1] = !isBit + length + 1;
@ -673,7 +675,7 @@ void VerilatedVcd::emitDouble(vluint32_t code, double newval) {
char* wp = m_writep; char* wp = m_writep;
// Buffer can't overflow before VL_SNPRINTF; we sized during declaration // Buffer can't overflow before VL_SNPRINTF; we sized during declaration
VL_SNPRINTF(wp, m_wrChunkSize, "r%.16g", newval); VL_SNPRINTF(wp, m_wrChunkSize, "r%.16g", newval);
wp += strlen(wp); wp += std::strlen(wp);
finishLine(code, wp); finishLine(code, wp);
} }
@ -787,7 +789,7 @@ void VerilatedVcd::fullDouble(vluint32_t code, const double newval) {
(*(reinterpret_cast<double*>(oldp(code)))) = newval; (*(reinterpret_cast<double*>(oldp(code)))) = newval;
// Buffer can't overflow before VL_SNPRINTF; we sized during declaration // Buffer can't overflow before VL_SNPRINTF; we sized during declaration
VL_SNPRINTF(m_writep, m_wrChunkSize, "r%.16g", newval); VL_SNPRINTF(m_writep, m_wrChunkSize, "r%.16g", newval);
m_writep += strlen(m_writep); m_writep += std::strlen(m_writep);
*m_writep++ = ' '; *m_writep++ = ' ';
m_writep = writeCode(m_writep, code); m_writep = writeCode(m_writep, code);
*m_writep++ = '\n'; *m_writep++ = '\n';

View File

@ -317,7 +317,7 @@ public:
void createPrevDatap() { void createPrevDatap() {
if (VL_UNLIKELY(!m_prevDatap)) { if (VL_UNLIKELY(!m_prevDatap)) {
m_prevDatap = new vluint8_t[entSize()]; m_prevDatap = new vluint8_t[entSize()];
memcpy(prevDatap(), varp()->datap(), entSize()); std::memcpy(prevDatap(), varp()->datap(), entSize());
} }
} }
}; };
@ -422,7 +422,7 @@ public:
explicit VerilatedVpioModule(const VerilatedScope* modulep) explicit VerilatedVpioModule(const VerilatedScope* modulep)
: VerilatedVpioScope{modulep} { : VerilatedVpioScope{modulep} {
m_fullname = m_scopep->name(); m_fullname = m_scopep->name();
if (strncmp(m_fullname, "TOP.", 4) == 0) m_fullname += 4; if (std::strncmp(m_fullname, "TOP.", 4) == 0) m_fullname += 4;
m_name = m_scopep->identifier(); m_name = m_scopep->identifier();
} }
static VerilatedVpioModule* castp(vpiHandle h) { static VerilatedVpioModule* castp(vpiHandle h) {
@ -628,7 +628,7 @@ public:
VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: value_test %s v[0]=%d/%d %p %p\n", VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: value_test %s v[0]=%d/%d %p %p\n",
varop->fullname(), *((CData*)newDatap), varop->fullname(), *((CData*)newDatap),
*((CData*)prevDatap), newDatap, prevDatap);); *((CData*)prevDatap), newDatap, prevDatap););
if (memcmp(prevDatap, newDatap, varop->entSize()) != 0) { if (std::memcmp(prevDatap, newDatap, varop->entSize()) != 0) {
VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: value_callback %" VL_PRI64 VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: value_callback %" VL_PRI64
"d %s v[0]=%d\n", "d %s v[0]=%d\n",
ho.id(), varop->fullname(), *((CData*)newDatap));); ho.id(), varop->fullname(), *((CData*)newDatap)););
@ -640,7 +640,9 @@ public:
} }
if (was_last) break; if (was_last) break;
} }
for (const auto& ip : update) { memcpy(ip->prevDatap(), ip->varDatap(), ip->entSize()); } for (const auto& ip : update) {
std::memcpy(ip->prevDatap(), ip->varDatap(), ip->entSize());
}
return called; return called;
} }
@ -1099,7 +1101,7 @@ const char* VerilatedVpiError::strFromVpiProp(PLI_INT32 vpiVal) VL_MT_SAFE {
} }
#define SELF_CHECK_RESULT_CSTR(got, exp) \ #define SELF_CHECK_RESULT_CSTR(got, exp) \
if (0 != strcmp((got), (exp))) { \ if (0 != std::strcmp((got), (exp))) { \
std::string msg \ std::string msg \
= std::string("%Error: ") + "GOT = '" + got + "'" + " EXP = '" + exp + "'"; \ = std::string("%Error: ") + "GOT = '" + got + "'" + " EXP = '" + exp + "'"; \
VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); \ VL_FATAL_MT(__FILE__, __LINE__, "", msg.c_str()); \
@ -1236,7 +1238,7 @@ vpiHandle vpi_handle_by_name(PLI_BYTE8* namep, vpiHandle scope) {
} }
const char* baseNamep = scopeAndName.c_str(); const char* baseNamep = scopeAndName.c_str();
std::string scopename; std::string scopename;
const char* dotp = strrchr(namep, '.'); const char* dotp = std::strrchr(namep, '.');
if (VL_LIKELY(dotp)) { if (VL_LIKELY(dotp)) {
baseNamep = dotp + 1; baseNamep = dotp + 1;
scopename = std::string(namep, dotp - namep); scopename = std::string(namep, dotp - namep);
@ -1826,7 +1828,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_
} }
} else if (valuep->format == vpiBinStrVal) { } else if (valuep->format == vpiBinStrVal) {
int bits = vop->varp()->packed().elements(); int bits = vop->varp()->packed().elements();
int len = strlen(valuep->value.str); int len = std::strlen(valuep->value.str);
CData* datap = (reinterpret_cast<CData*>(vop->varDatap())); CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
for (int i = 0; i < bits; ++i) { for (int i = 0; i < bits; ++i) {
char set = (i < len) ? (valuep->value.str[len - i - 1] == '1') : 0; char set = (i < len) ? (valuep->value.str[len - i - 1] == '1') : 0;
@ -1842,7 +1844,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_
} else if (valuep->format == vpiOctStrVal) { } else if (valuep->format == vpiOctStrVal) {
int chars = (vop->varp()->packed().elements() + 2) / 3; int chars = (vop->varp()->packed().elements() + 2) / 3;
int bytes = VL_BYTES_I(vop->varp()->packed().elements()); int bytes = VL_BYTES_I(vop->varp()->packed().elements());
int len = strlen(valuep->value.str); int len = std::strlen(valuep->value.str);
CData* datap = (reinterpret_cast<CData*>(vop->varDatap())); CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
div_t idx; div_t idx;
datap[0] = 0; // reset zero'th byte datap[0] = 0; // reset zero'th byte
@ -1892,7 +1894,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_
} else if (valuep->format == vpiDecStrVal) { } else if (valuep->format == vpiDecStrVal) {
char remainder[16]; char remainder[16];
unsigned long long val; unsigned long long val;
int success = sscanf(valuep->value.str, "%30llu%15s", &val, remainder); int success = std::sscanf(valuep->value.str, "%30llu%15s", &val, remainder);
if (success < 1) { if (success < 1) {
VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Parsing failed for '%s' as value %s for %s", VL_VPI_ERROR_(__FILE__, __LINE__, "%s: Parsing failed for '%s' as value %s for %s",
VL_FUNC, valuep->value.str, VL_FUNC, valuep->value.str,
@ -1925,7 +1927,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_
char* val = valuep->value.str; char* val = valuep->value.str;
// skip hex ident if one is detected at the start of the string // skip hex ident if one is detected at the start of the string
if (val[0] == '0' && (val[1] == 'x' || val[1] == 'X')) val += 2; if (val[0] == '0' && (val[1] == 'x' || val[1] == 'X')) val += 2;
int len = strlen(val); int len = std::strlen(val);
for (int i = 0; i < chars; ++i) { for (int i = 0; i < chars; ++i) {
char hex; char hex;
// compute hex digit value // compute hex digit value
@ -1961,7 +1963,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_
return object; return object;
} else if (valuep->format == vpiStringVal) { } else if (valuep->format == vpiStringVal) {
int bytes = VL_BYTES_I(vop->varp()->packed().elements()); int bytes = VL_BYTES_I(vop->varp()->packed().elements());
int len = strlen(valuep->value.str); int len = std::strlen(valuep->value.str);
CData* datap = (reinterpret_cast<CData*>(vop->varDatap())); CData* datap = (reinterpret_cast<CData*>(vop->varDatap()));
for (int i = 0; i < bytes; ++i) { for (int i = 0; i < bytes; ++i) {
// prepend with 0 values before placing string the least significant bytes // prepend with 0 values before placing string the least significant bytes
@ -2104,7 +2106,7 @@ PLI_INT32 vpi_mcd_flush(PLI_UINT32 mcd) {
FILE* fp = VL_CVT_I_FP(mcd); FILE* fp = VL_CVT_I_FP(mcd);
VL_VPI_ERROR_RESET_(); VL_VPI_ERROR_RESET_();
if (VL_UNLIKELY(!fp)) return 1; if (VL_UNLIKELY(!fp)) return 1;
fflush(fp); std::fflush(fp);
return 0; return 0;
} }

View File

@ -240,7 +240,7 @@
extern "C" { extern "C" {
void __gcov_flush(); // gcc sources gcc/gcov-io.h has the prototype void __gcov_flush(); // gcc sources gcc/gcov-io.h has the prototype
} }
/// Flush internal code coverage data before e.g. abort() /// Flush internal code coverage data before e.g. std::abort()
# define VL_GCOV_FLUSH() \ # define VL_GCOV_FLUSH() \
__gcov_flush() __gcov_flush()
#else #else
@ -446,11 +446,11 @@ typedef unsigned long long vluint64_t; ///< 64-bit unsigned type
// #defines, to avoid requiring math.h on all compile runs // #defines, to avoid requiring math.h on all compile runs
#ifdef _MSC_VER #ifdef _MSC_VER
# define VL_TRUNC(n) (((n) < 0) ? ceil((n)) : floor((n))) # define VL_TRUNC(n) (((n) < 0) ? std::ceil((n)) : std::floor((n)))
# define VL_ROUND(n) (((n) < 0) ? ceil((n)-0.5) : floor((n) + 0.5)) # define VL_ROUND(n) (((n) < 0) ? std::ceil((n)-0.5) : std::floor((n) + 0.5))
#else #else
# define VL_TRUNC(n) trunc(n) # define VL_TRUNC(n) std::trunc(n)
# define VL_ROUND(n) round(n) # define VL_ROUND(n) std::round(n)
#endif #endif
//========================================================================= //=========================================================================

View File

@ -6315,7 +6315,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(LogD) ASTNODE_NODE_FUNCS(LogD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(log(lhs.toDouble())); out.setDouble(std::log(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$ln(%l)"; } virtual string emitVerilog() override { return "%f$ln(%l)"; }
virtual string emitC() override { return "log(%li)"; } virtual string emitC() override { return "log(%li)"; }
@ -6326,7 +6326,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(Log10D) ASTNODE_NODE_FUNCS(Log10D)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(log10(lhs.toDouble())); out.setDouble(std::log10(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$log10(%l)"; } virtual string emitVerilog() override { return "%f$log10(%l)"; }
virtual string emitC() override { return "log10(%li)"; } virtual string emitC() override { return "log10(%li)"; }
@ -6338,7 +6338,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(ExpD) ASTNODE_NODE_FUNCS(ExpD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(exp(lhs.toDouble())); out.setDouble(std::exp(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$exp(%l)"; } virtual string emitVerilog() override { return "%f$exp(%l)"; }
virtual string emitC() override { return "exp(%li)"; } virtual string emitC() override { return "exp(%li)"; }
@ -6350,7 +6350,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(SqrtD) ASTNODE_NODE_FUNCS(SqrtD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(sqrt(lhs.toDouble())); out.setDouble(std::sqrt(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$sqrt(%l)"; } virtual string emitVerilog() override { return "%f$sqrt(%l)"; }
virtual string emitC() override { return "sqrt(%li)"; } virtual string emitC() override { return "sqrt(%li)"; }
@ -6362,7 +6362,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(FloorD) ASTNODE_NODE_FUNCS(FloorD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(floor(lhs.toDouble())); out.setDouble(std::floor(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$floor(%l)"; } virtual string emitVerilog() override { return "%f$floor(%l)"; }
virtual string emitC() override { return "floor(%li)"; } virtual string emitC() override { return "floor(%li)"; }
@ -6374,7 +6374,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(CeilD) ASTNODE_NODE_FUNCS(CeilD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(ceil(lhs.toDouble())); out.setDouble(std::ceil(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$ceil(%l)"; } virtual string emitVerilog() override { return "%f$ceil(%l)"; }
virtual string emitC() override { return "ceil(%li)"; } virtual string emitC() override { return "ceil(%li)"; }
@ -6386,7 +6386,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(SinD) ASTNODE_NODE_FUNCS(SinD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(sin(lhs.toDouble())); out.setDouble(std::sin(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$sin(%l)"; } virtual string emitVerilog() override { return "%f$sin(%l)"; }
virtual string emitC() override { return "sin(%li)"; } virtual string emitC() override { return "sin(%li)"; }
@ -6398,7 +6398,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(CosD) ASTNODE_NODE_FUNCS(CosD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(cos(lhs.toDouble())); out.setDouble(std::cos(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$cos(%l)"; } virtual string emitVerilog() override { return "%f$cos(%l)"; }
virtual string emitC() override { return "cos(%li)"; } virtual string emitC() override { return "cos(%li)"; }
@ -6410,7 +6410,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(TanD) ASTNODE_NODE_FUNCS(TanD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(tan(lhs.toDouble())); out.setDouble(std::tan(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$tan(%l)"; } virtual string emitVerilog() override { return "%f$tan(%l)"; }
virtual string emitC() override { return "tan(%li)"; } virtual string emitC() override { return "tan(%li)"; }
@ -6422,7 +6422,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(AsinD) ASTNODE_NODE_FUNCS(AsinD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(asin(lhs.toDouble())); out.setDouble(std::asin(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$asin(%l)"; } virtual string emitVerilog() override { return "%f$asin(%l)"; }
virtual string emitC() override { return "asin(%li)"; } virtual string emitC() override { return "asin(%li)"; }
@ -6434,7 +6434,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(AcosD) ASTNODE_NODE_FUNCS(AcosD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(acos(lhs.toDouble())); out.setDouble(std::acos(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$acos(%l)"; } virtual string emitVerilog() override { return "%f$acos(%l)"; }
virtual string emitC() override { return "acos(%li)"; } virtual string emitC() override { return "acos(%li)"; }
@ -6446,7 +6446,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(AtanD) ASTNODE_NODE_FUNCS(AtanD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(atan(lhs.toDouble())); out.setDouble(std::atan(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$atan(%l)"; } virtual string emitVerilog() override { return "%f$atan(%l)"; }
virtual string emitC() override { return "atan(%li)"; } virtual string emitC() override { return "atan(%li)"; }
@ -6458,7 +6458,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(SinhD) ASTNODE_NODE_FUNCS(SinhD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(sinh(lhs.toDouble())); out.setDouble(std::sinh(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$sinh(%l)"; } virtual string emitVerilog() override { return "%f$sinh(%l)"; }
virtual string emitC() override { return "sinh(%li)"; } virtual string emitC() override { return "sinh(%li)"; }
@ -6470,7 +6470,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(CoshD) ASTNODE_NODE_FUNCS(CoshD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(cosh(lhs.toDouble())); out.setDouble(std::cosh(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$cosh(%l)"; } virtual string emitVerilog() override { return "%f$cosh(%l)"; }
virtual string emitC() override { return "cosh(%li)"; } virtual string emitC() override { return "cosh(%li)"; }
@ -6482,7 +6482,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(TanhD) ASTNODE_NODE_FUNCS(TanhD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(tanh(lhs.toDouble())); out.setDouble(std::tanh(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$tanh(%l)"; } virtual string emitVerilog() override { return "%f$tanh(%l)"; }
virtual string emitC() override { return "tanh(%li)"; } virtual string emitC() override { return "tanh(%li)"; }
@ -6494,7 +6494,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(AsinhD) ASTNODE_NODE_FUNCS(AsinhD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(asinh(lhs.toDouble())); out.setDouble(std::asinh(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$asinh(%l)"; } virtual string emitVerilog() override { return "%f$asinh(%l)"; }
virtual string emitC() override { return "asinh(%li)"; } virtual string emitC() override { return "asinh(%li)"; }
@ -6506,7 +6506,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(AcoshD) ASTNODE_NODE_FUNCS(AcoshD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(acosh(lhs.toDouble())); out.setDouble(std::acosh(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$acosh(%l)"; } virtual string emitVerilog() override { return "%f$acosh(%l)"; }
virtual string emitC() override { return "acosh(%li)"; } virtual string emitC() override { return "acosh(%li)"; }
@ -6518,7 +6518,7 @@ public:
: ASTGEN_SUPER(fl, lhsp) {} : ASTGEN_SUPER(fl, lhsp) {}
ASTNODE_NODE_FUNCS(AtanhD) ASTNODE_NODE_FUNCS(AtanhD)
virtual void numberOperate(V3Number& out, const V3Number& lhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs) override {
out.setDouble(atanh(lhs.toDouble())); out.setDouble(std::atanh(lhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$atanh(%l)"; } virtual string emitVerilog() override { return "%f$atanh(%l)"; }
virtual string emitC() override { return "atanh(%li)"; } virtual string emitC() override { return "atanh(%li)"; }
@ -8190,7 +8190,7 @@ public:
return new AstAtan2D(this->fileline(), lhsp, rhsp); return new AstAtan2D(this->fileline(), lhsp, rhsp);
} }
virtual void numberOperate(V3Number& out, const V3Number& lhs, const V3Number& rhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs, const V3Number& rhs) override {
out.setDouble(atan2(lhs.toDouble(), rhs.toDouble())); out.setDouble(std::atan2(lhs.toDouble(), rhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$atan2(%l,%r)"; } virtual string emitVerilog() override { return "%f$atan2(%l,%r)"; }
virtual string emitC() override { return "atan2(%li,%ri)"; } virtual string emitC() override { return "atan2(%li,%ri)"; }
@ -8205,7 +8205,7 @@ public:
return new AstHypotD(this->fileline(), lhsp, rhsp); return new AstHypotD(this->fileline(), lhsp, rhsp);
} }
virtual void numberOperate(V3Number& out, const V3Number& lhs, const V3Number& rhs) override { virtual void numberOperate(V3Number& out, const V3Number& lhs, const V3Number& rhs) override {
out.setDouble(hypot(lhs.toDouble(), rhs.toDouble())); out.setDouble(std::hypot(lhs.toDouble(), rhs.toDouble()));
} }
virtual string emitVerilog() override { return "%f$hypot(%l,%r)"; } virtual string emitVerilog() override { return "%f$hypot(%l,%r)"; }
virtual string emitC() override { return "hypot(%li,%ri)"; } virtual string emitC() override { return "hypot(%li,%ri)"; }

View File

@ -161,7 +161,7 @@ void V3Error::vlAbortOrExit() {
std::cerr << msgPrefix() << "Aborting since under --debug" << endl; std::cerr << msgPrefix() << "Aborting since under --debug" << endl;
V3Error::vlAbort(); V3Error::vlAbort();
} else { } else {
exit(1); std::exit(1);
} }
} }

View File

@ -1295,11 +1295,11 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
DECL_OPTION("-gdbbt", CbCall, []() {}); // Processed only in bin/verilator shell DECL_OPTION("-gdbbt", CbCall, []() {}); // Processed only in bin/verilator shell
DECL_OPTION("-generate-key", CbCall, [this]() { DECL_OPTION("-generate-key", CbCall, [this]() {
cout << protectKeyDefaulted() << endl; cout << protectKeyDefaulted() << endl;
exit(0); std::exit(0);
}); });
DECL_OPTION("-getenv", CbVal, [](const char* valp) { DECL_OPTION("-getenv", CbVal, [](const char* valp) {
cout << V3Options::getenvBuiltins(valp) << endl; cout << V3Options::getenvBuiltins(valp) << endl;
exit(0); std::exit(0);
}); });
DECL_OPTION("-hierarchical", OnOff, &m_hierarchical); DECL_OPTION("-hierarchical", OnOff, &m_hierarchical);
@ -1562,7 +1562,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
DECL_OPTION("-V", CbCall, [this]() { DECL_OPTION("-V", CbCall, [this]() {
showVersion(true); showVersion(true);
exit(0); std::exit(0);
}); });
DECL_OPTION("-v", CbVal, [this, &optdir](const char* valp) { DECL_OPTION("-v", CbVal, [this, &optdir](const char* valp) {
V3Options::addLibraryFile(parseFileArg(optdir, valp)); V3Options::addLibraryFile(parseFileArg(optdir, valp));
@ -1570,7 +1570,7 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
DECL_OPTION("-verilate", OnOff, &m_verilate); DECL_OPTION("-verilate", OnOff, &m_verilate);
DECL_OPTION("-version", CbCall, [this]() { DECL_OPTION("-version", CbCall, [this]() {
showVersion(false); showVersion(false);
exit(0); std::exit(0);
}); });
DECL_OPTION("-vpi", OnOff, &m_vpi); DECL_OPTION("-vpi", OnOff, &m_vpi);

View File

@ -515,7 +515,7 @@ public:
unsigned yabs; unsigned yabs;
xabs = diff(otherp->m_xpos, m_xpos); xabs = diff(otherp->m_xpos, m_xpos);
yabs = diff(otherp->m_ypos, m_ypos); yabs = diff(otherp->m_ypos, m_ypos);
return lround(sqrt(xabs * xabs + yabs * yabs)); return std::lround(std::sqrt(xabs * xabs + yabs * yabs));
} }
unsigned xpos() const { return m_xpos; } unsigned xpos() const { return m_xpos; }
unsigned ypos() const { return m_ypos; } unsigned ypos() const { return m_ypos; }

View File

@ -3880,7 +3880,7 @@ private:
newp = new AstMul(argp->fileline(), newp = new AstMul(argp->fileline(),
new AstConst(argp->fileline(), new AstConst(argp->fileline(),
AstConst::Unsized64(), AstConst::Unsized64(),
llround(scale)), std::llround(scale)),
argp); argp);
} }
relinkHandle.relink(newp); relinkHandle.relink(newp);

View File

@ -117,7 +117,7 @@ static void process() {
V3Error::abortIfErrors(); V3Error::abortIfErrors();
if (v3Global.opt.debugExitParse()) { if (v3Global.opt.debugExitParse()) {
cout << "--debug-exit-parse: Exiting after parse\n"; cout << "--debug-exit-parse: Exiting after parse\n";
exit(0); std::exit(0);
} }
// Convert parseref's to varrefs, and other directly post parsing fixups // Convert parseref's to varrefs, and other directly post parsing fixups
@ -125,7 +125,7 @@ static void process() {
if (v3Global.opt.debugExitUvm()) { if (v3Global.opt.debugExitUvm()) {
V3Error::abortIfErrors(); V3Error::abortIfErrors();
cout << "--debug-exit-uvm: Exiting after UVM-supported pass\n"; cout << "--debug-exit-uvm: Exiting after UVM-supported pass\n";
exit(0); std::exit(0);
} }
// Cross-link signal names // Cross-link signal names
@ -664,7 +664,7 @@ static void execBuildJob() {
const int exit_code = V3Os::system(cmdStr); const int exit_code = V3Os::system(cmdStr);
if (exit_code != 0) { if (exit_code != 0) {
v3error(cmdStr << " exited with " << exit_code << std::endl); v3error(cmdStr << " exited with " << exit_code << std::endl);
exit(exit_code); std::exit(exit_code);
} }
} }
@ -676,7 +676,7 @@ static void execHierVerilation() {
const int exit_code = V3Os::system(cmdStr); const int exit_code = V3Os::system(cmdStr);
if (exit_code != 0) { if (exit_code != 0) {
v3error(cmdStr << " exited with " << exit_code << std::endl); v3error(cmdStr << " exited with " << exit_code << std::endl);
exit(exit_code); std::exit(exit_code);
} }
} }

View File

@ -101,10 +101,10 @@ void VlcOptions::parseOptsList(int argc, char** argv) {
V3Error::debugDefault(atoi(argv[i])); V3Error::debugDefault(atoi(argv[i]));
} else if (!strcmp(sw, "-V")) { } else if (!strcmp(sw, "-V")) {
showVersion(true); showVersion(true);
exit(0); std::exit(0);
} else if (!strcmp(sw, "-version")) { } else if (!strcmp(sw, "-version")) {
showVersion(false); showVersion(false);
exit(0); std::exit(0);
} else if (!strcmp(sw, "-write") && (i + 1) < argc) { } else if (!strcmp(sw, "-write") && (i + 1) < argc) {
shift; shift;
m_writeFile = argv[i]; m_writeFile = argv[i];