diff --git a/include/verilated.cpp b/include/verilated.cpp index 471d0a4cc..d44b50beb 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -467,7 +467,8 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) { } break; case 'd': { // Signed decimal - int digits=sprintf(tmp,"%" VL_PRI64 "d",(vlsint64_t)(VL_EXTENDS_QQ(lbits,lbits,ld))); + int digits = sprintf(tmp,"%" VL_PRI64 "d", + static_cast(VL_EXTENDS_QQ(lbits,lbits,ld))); int needmore = width-digits; if (needmore>0) { if (pctp && pctp[0] && pctp[1]=='0') { //%0 @@ -498,8 +499,8 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) { digits=sprintf(tmp,"%" VL_PRI64 "u",ld); } else if (VL_TIME_MULTIPLIER==1000) { digits=sprintf(tmp,"%" VL_PRI64 "u.%03" VL_PRI64 "u", - (QData)(ld/VL_TIME_MULTIPLIER), - (QData)(ld%VL_TIME_MULTIPLIER)); + static_cast(ld/VL_TIME_MULTIPLIER), + static_cast(ld%VL_TIME_MULTIPLIER)); } else { vl_fatal(__FILE__,__LINE__,"","Unsupported VL_TIME_MULTIPLIER"); } @@ -529,20 +530,20 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) { case 'u': // Packed 2-state output.reserve(output.size() + 4*VL_WORDS_I(lbits)); for (int i=0; i> 8) & 0xff); - output += (char)((lwp[i] >> 16) & 0xff); - output += (char)((lwp[i] >> 24) & 0xff); + output += static_cast((lwp[i] ) & 0xff); + output += static_cast((lwp[i] >> 8) & 0xff); + output += static_cast((lwp[i] >> 16) & 0xff); + output += static_cast((lwp[i] >> 24) & 0xff); } break; case 'z': // Packed 4-state output.reserve(output.size() + 8*VL_WORDS_I(lbits)); for (int i=0; i> 8) & 0xff); - output += (char)((lwp[i] >> 16) & 0xff); - output += (char)((lwp[i] >> 24) & 0xff); - output += "\0\0\0\0"; // No tristate + output += static_cast((lwp[i] ) & 0xff); + output += static_cast((lwp[i] >> 8) & 0xff); + output += static_cast((lwp[i] >> 16) & 0xff); + output += static_cast((lwp[i] >> 24) & 0xff); + output += "\0\0\0\0"; // No tristate } break; case 'v': // Strength; assume always strong @@ -622,10 +623,10 @@ static inline void _vl_vsss_setbit(WDataOutP owp, int obits, int lsb, int nbits, VL_ASSIGNBIT_WI(0, lsb, owp, ld & 1); } } -static inline void _vl_vsss_based(WDataOutP owp, int obits, int baseLog2, const char* strp, int posstart, int posend) { +static inline void _vl_vsss_based(WDataOutP owp, int obits, int baseLog2, const char* strp, size_t posstart, size_t posend) { // Read in base "2^^baseLog2" digits from strp[posstart..posend-1] into owp of size obits. int lsb = 0; - for (int i=0, pos=posend-1; i=posstart; --pos) { + for (int i=0, pos=static_cast(posend)-1; i=static_cast(posstart); --pos) { switch (tolower (strp[pos])) { case 'x': case 'z': case '?': //FALLTHRU case '0': lsb += baseLog2; break; @@ -706,7 +707,7 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf _vl_vsss_skipspace(fp,floc,fromp,fstr); _vl_vsss_read(fp,floc,fromp,fstr, tmp, NULL); if (!tmp[0]) goto done; - int lpos = ((int)strlen(tmp))-1; + int lpos = (static_cast(strlen(tmp)))-1; int lsb = 0; for (int i=0; i=0; --lpos) { _vl_vsss_setbit(owp,obits,lsb, 8, tmp[lpos]); lsb+=8; @@ -748,21 +749,21 @@ IData _vl_vsscanf(FILE* fp, // If a fscanf _vl_vsss_skipspace(fp,floc,fromp,fstr); _vl_vsss_read(fp,floc,fromp,fstr, tmp, "01xXzZ?_"); if (!tmp[0]) goto done; - _vl_vsss_based(owp,obits, 1, tmp, 0, (int)strlen(tmp)); + _vl_vsss_based(owp,obits, 1, tmp, 0, strlen(tmp)); break; } case 'o': { _vl_vsss_skipspace(fp,floc,fromp,fstr); _vl_vsss_read(fp,floc,fromp,fstr, tmp, "01234567xXzZ?_"); if (!tmp[0]) goto done; - _vl_vsss_based(owp,obits, 3, tmp, 0, (int)strlen(tmp)); + _vl_vsss_based(owp,obits, 3, tmp, 0, strlen(tmp)); break; } case 'x': { _vl_vsss_skipspace(fp,floc,fromp,fstr); _vl_vsss_read(fp,floc,fromp,fstr, tmp, "0123456789abcdefABCDEFxXzZ?_"); if (!tmp[0]) goto done; - _vl_vsss_based(owp,obits, 4, tmp, 0, (int)strlen(tmp)); + _vl_vsss_based(owp,obits, 4, tmp, 0, strlen(tmp)); break; } default: @@ -814,12 +815,12 @@ void _VL_VINT_TO_STRING(int obits, char* destoutp, WDataInP sourcep) { if (!start) while (isspace(*(destp-1)) && destp>destoutp) *--destp = '\0'; // Drop trailing spaces } -void _VL_STRING_TO_VINT(int obits, void* destp, int srclen, const char* srcp) { +void _VL_STRING_TO_VINT(int obits, void* destp, size_t srclen, const char* srcp) { // Convert C string to Verilog format int bytes = VL_BYTES_I(obits); - char* op = ((char*)(destp)); + char* op = reinterpret_cast(destp); if (srclen > bytes) srclen = bytes; // Don't overflow destination - int i; + size_t i; for (i=0; i= (IData)(depth+array_lsb) || addr < (IData)(array_lsb))) { + if (VL_UNLIKELY(addr >= static_cast(depth+array_lsb) + || addr < static_cast(array_lsb))) { vl_fatal (ofilenamep.c_str(), linenum, "", "$readmem file address beyond bounds of array"); } else { int entry = addr - array_lsb; QData shift = hex ? VL_ULL(4) : VL_ULL(1); // Shift value in if (width<=8) { - CData* datap = &((CData*)(memp))[entry]; + CData* datap = &(reinterpret_cast(memp))[entry]; if (!innum) { *datap = 0; } *datap = ((*datap << shift) + value) & VL_MASK_I(width); } else if (width<=16) { - SData* datap = &((SData*)(memp))[entry]; + SData* datap = &(reinterpret_cast(memp))[entry]; if (!innum) { *datap = 0; } *datap = ((*datap << shift) + value) & VL_MASK_I(width); } else if (width<=VL_WORDSIZE) { - IData* datap = &((IData*)(memp))[entry]; + IData* datap = &(reinterpret_cast(memp))[entry]; if (!innum) { *datap = 0; } *datap = ((*datap << shift) + value) & VL_MASK_I(width); } else if (width<=VL_QUADSIZE) { - QData* datap = &((QData*)(memp))[entry]; + QData* datap = &(reinterpret_cast(memp))[entry]; if (!innum) { *datap = 0; } - *datap = ((*datap << (QData)(shift)) + (QData)(value)) & VL_MASK_Q(width); + *datap = ((*datap << static_cast(shift)) + + static_cast(value)) & VL_MASK_Q(width); } else { - WDataOutP datap = &((WDataOutP)(memp))[ entry*VL_WORDS_I(width) ]; + WDataOutP datap = &(reinterpret_cast(memp))[ entry*VL_WORDS_I(width) ]; if (!innum) { VL_ZERO_RESET_W(width, datap); } - _VL_SHIFTL_INPLACE_W(width, datap, (IData)shift); + _VL_SHIFTL_INPLACE_W(width, datap, static_cast(shift)); datap[0] |= value; } if (VL_UNLIKELY(value>=(1<=0; --posp) { + for (int i=0, lsb=0, posp=static_cast(strlen(dp))-1; i=0; --posp) { _vl_vsss_setbit(rwp,rbits,lsb, 8, dp[posp]); lsb+=8; } break; diff --git a/include/verilated.h b/include/verilated.h index a696ea8a3..73b931c5d 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -286,7 +286,7 @@ public: /// Record command line arguments, for retrieval by $test$plusargs/$value$plusargs static void commandArgs(int argc, const char** argv); - static void commandArgs(int argc, char** argv) { commandArgs(argc,(const char**)argv); } + static void commandArgs(int argc, char** argv) { commandArgs(argc, const_cast(argv)); } static void commandArgsAdd(int argc, const char** argv); static CommandArgValues* getCommandArgs() {return &s_args;} /// Match plusargs with a given prefix. Returns static char* valid only for a single call @@ -404,10 +404,10 @@ extern const char* vl_mc_scan_plusargs(const char* prefixp); // PLIish /// Create two 32-bit words from quadword /// WData is always at least 2 words; does not clean upper bits -#define VL_SET_WQ(owp,data) { owp[0]=(IData)(data); owp[1]=(IData)((data)>>VL_WORDSIZE); } -#define VL_SET_WI(owp,data) { owp[0]=(IData)(data); owp[1]=0; } -#define VL_SET_QW(lwp) ( ((QData)(lwp[0])) | ((QData)(lwp[1])<<((QData)(VL_WORDSIZE)) )) -#define _VL_SET_QII(ld,rd) ( ((QData)(ld)<(data); owp[1]=static_cast((data)>>VL_WORDSIZE); } +#define VL_SET_WI(owp,data) { owp[0]=static_cast(data); owp[1]=0; } +#define VL_SET_QW(lwp) ( (static_cast(lwp[0])) | (static_cast(lwp[1])<<(static_cast(VL_WORDSIZE)) )) +#define _VL_SET_QII(ld,rd) ( (static_cast(ld)<(rd) ) /// Return FILE* from IData extern FILE* VL_CVT_I_FP(IData lhs); @@ -422,11 +422,11 @@ static inline double VL_CVT_D_Q(QData lhs) { union { double d; QData q; } u; u.q /// Return QData from double (bits, not numerically) static inline QData VL_CVT_Q_D(double lhs) { union { double d; QData q; } u; u.d=lhs; return u.q; } /// Return double from QData (numeric) -static inline double VL_ITOR_D_I(IData lhs) { return ((double)((vlsint32_t)(lhs))); } +static inline double VL_ITOR_D_I(IData lhs) { return static_cast(static_cast(lhs)); } /// Return QData from double (numeric) -static inline IData VL_RTOI_I_D(double lhs) { return ((vlsint32_t)(VL_TRUNC(lhs))); } +static inline IData VL_RTOI_I_D(double lhs) { return static_cast(VL_TRUNC(lhs)); } /// Return QData from double (numeric) -static inline IData VL_RTOIROUND_I_D(double lhs) { return ((vlsint32_t)(VL_ROUND(lhs))); } +static inline IData VL_RTOIROUND_I_D(double lhs) { return static_cast(VL_ROUND(lhs)); } // Sign extend such that if MSB set, we get ffff_ffff, else 0s // (Requires clean input) @@ -455,13 +455,13 @@ void _VL_DEBUG_PRINT_W(int lbits, WDataInP iwp); /// Return current simulation time #if defined(SYSTEMC_VERSION) && (SYSTEMC_VERSION>20011000) -# define VL_TIME_I() ((IData)(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER)) -# define VL_TIME_Q() ((QData)(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER)) -# define VL_TIME_D() ((double)(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER)) +# define VL_TIME_I() (static_cast(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER)) +# define VL_TIME_Q() (static_cast(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER)) +# define VL_TIME_D() (static_cast(sc_time_stamp().to_default_time_units()*VL_TIME_MULTIPLIER)) #else -# define VL_TIME_I() ((IData)(sc_time_stamp()*VL_TIME_MULTIPLIER)) -# define VL_TIME_Q() ((QData)(sc_time_stamp()*VL_TIME_MULTIPLIER)) -# define VL_TIME_D() ((double)(sc_time_stamp()*VL_TIME_MULTIPLIER)) +# define VL_TIME_I() (static_cast(sc_time_stamp()*VL_TIME_MULTIPLIER)) +# define VL_TIME_Q() (static_cast(sc_time_stamp()*VL_TIME_MULTIPLIER)) +# define VL_TIME_D() (static_cast(sc_time_stamp()*VL_TIME_MULTIPLIER)) extern double sc_time_stamp(); #endif @@ -581,8 +581,8 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) { od = (svar.read().get_word(0)) & VL_MASK_I(obits); \ } #define VL_ASSIGN_QSW(obits,od,svar) { \ - od = (((QData)svar.read().get_word(1))<(svar.read().get_word(1)))< _bvtemp; \ - _bvtemp.set_word(0,(IData)(rd)); \ - _bvtemp.set_word(1,(IData)((rd)>>VL_WORDSIZE)); \ + _bvtemp.set_word(0, static_cast(rd)); \ + _bvtemp.set_word(1, static_cast((rd)>>VL_WORDSIZE)); \ svar.write(_bvtemp); \ } #define VL_ASSIGN_SWW(obits,svar,rwp) { \ @@ -648,7 +648,7 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) { // Right must be clean because otherwise size increase would pick up bad bits // EMIT_RULE: VL_EXTEND: oclean=clean; rclean==clean; #define VL_EXTEND_II(obits,lbits,lhs) ((lhs)) -#define VL_EXTEND_QI(obits,lbits,lhs) ((QData)(lhs)) +#define VL_EXTEND_QI(obits,lbits,lhs) (static_cast(lhs)) #define VL_EXTEND_QQ(obits,lbits,lhs) ((lhs)) static inline WDataOutP VL_EXTEND_WI(int obits, int, WDataOutP owp, IData ld) { @@ -768,7 +768,7 @@ static inline IData VL_REDXOR_64(QData r) { return __builtin_parityll(r); #else r=(r^(r>>1)); r=(r^(r>>2)); r=(r^(r>>4)); r=(r^(r>>8)); r=(r^(r>>16)); r=(r^(r>>32)); - return (IData)r; + return static_cast(r); #endif } static inline IData VL_REDXOR_W(int words, WDataInP lwp) { @@ -787,7 +787,7 @@ static inline IData VL_COUNTONES_I(IData lhs) { return r; } static inline IData VL_COUNTONES_Q(QData lhs) { - return VL_COUNTONES_I((IData)lhs) + VL_COUNTONES_I((IData)(lhs>>32)); + return VL_COUNTONES_I(static_cast(lhs)) + VL_COUNTONES_I(static_cast(lhs>>32)); } static inline IData VL_COUNTONES_W(int words, WDataInP lwp) { IData r = 0; @@ -1024,7 +1024,7 @@ static inline int _VL_CMPS_W(int lbits, WDataInP lwp, WDataInP rwp) { static inline WDataOutP VL_ADD_W(int words, WDataOutP owp,WDataInP lwp,WDataInP rwp){ QData carry = 0; for (int i=0; i(lwp[i]) + static_cast(rwp[i]); owp[i] = (carry & VL_ULL(0xffffffff)); carry = (carry >> VL_ULL(32)) & VL_ULL(0xffffffff); } @@ -1034,7 +1034,7 @@ static inline WDataOutP VL_ADD_W(int words, WDataOutP owp,WDataInP lwp,WDataInP static inline WDataOutP VL_SUB_W(int words, WDataOutP owp,WDataInP lwp,WDataInP rwp){ QData carry = 0; for (int i=0; i(lwp[i]) + static_cast(static_cast(~rwp[i])); if (i==0) carry++; // Negation of temp2 owp[i] = (carry & VL_ULL(0xffffffff)); carry = (carry >> VL_ULL(32)) & VL_ULL(0xffffffff); @@ -1051,7 +1051,7 @@ static inline QData VL_NEGATE_Q(QData data) { return -data; } static inline WDataOutP VL_NEGATE_W(int words, WDataOutP owp,WDataInP lwp){ QData carry = 0; for (int i=0; i(static_cast(~lwp[i])); if (i==0) carry++; // Negation of temp2 owp[i] = (carry & VL_ULL(0xffffffff)); carry = (carry >> VL_ULL(32)) & VL_ULL(0xffffffff); @@ -1063,9 +1063,9 @@ static inline WDataOutP VL_MUL_W(int words, WDataOutP owp,WDataInP lwp,WDataInP for (int i=0; i(lwp[lword]) * static_cast(rwp[rword]); for (int qword=lword+rword; qword(owp[qword]); owp[qword] = (mul & VL_ULL(0xffffffff)); mul = (mul >> VL_ULL(32)) & VL_ULL(0xffffffff); } @@ -1111,7 +1111,7 @@ static inline WDataOutP VL_MULS_WWW(int,int lbits,int, WDataOutP owp,WDataInP lw if ((lneg ^ rneg) & 1) { // Negate output (not using NEGATE, as owp==lwp) QData carry = 0; for (int i=0; i(static_cast(~owp[i])); if (i==0) carry++; // Negation of temp2 owp[i] = (carry & VL_ULL(0xffffffff)); carry = (carry >> VL_ULL(32)) & VL_ULL(0xffffffff); @@ -1357,7 +1357,7 @@ static inline void _VL_INSERT_WQ(int obits, WDataOutP owp, QData ld, int hbit, i // EMIT_RULE: VL_REPLICATE: oclean=clean>width32, dirty<=width32; lclean=clean; rclean==clean; // RHS MUST BE CLEAN CONSTANT. #define VL_REPLICATE_IOI(obits,lbits,rbits, ld, rep) (-(ld)) // Iff lbits==1 -#define VL_REPLICATE_QOI(obits,lbits,rbits, ld, rep) (-((QData)ld)) // Iff lbits==1 +#define VL_REPLICATE_QOI(obits,lbits,rbits, ld, rep) (-(static_cast(ld))) // Iff lbits==1 static inline IData VL_REPLICATE_III(int, int lbits, int, IData ld, IData rep) { IData returndata = ld; @@ -1371,7 +1371,7 @@ static inline QData VL_REPLICATE_QII(int, int lbits, int, IData ld, IData rep) { QData returndata = ld; for (unsigned i=1; i < rep; ++i){ returndata = returndata << lbits; - returndata |= (QData)ld; + returndata |= static_cast(ld); } return (returndata); } @@ -1497,7 +1497,7 @@ static inline QData VL_STREAML_QQI(int, int lbits, int, QData ld, IData rd) { static inline WDataOutP VL_STREAML_WWI(int, int lbits, int, WDataOutP owp, WDataInP lwp, IData rd) { VL_ZERO_W(lbits, owp); // Slice size should never exceed the lhs width - int ssize = (rd < (IData)lbits) ? rd : ((IData)lbits); + int ssize = (rd < static_cast(lbits)) ? rd : (static_cast(lbits)); for (int istart=0; istart 0 ? ostart : 0; @@ -1515,11 +1515,11 @@ static inline WDataOutP VL_STREAML_WWI(int, int lbits, int, WDataOutP owp, WData // Thus we specify inputs must be clean, so we don't need to clean the output. // Note the bit shifts are always constants, so the adds in these constify out. // Casts required, as args may be 8 bit entities, and need to shift to appropriate output size -#define VL_CONCAT_III(obits,lbits,rbits,ld,rd) ((IData)(ld)<<(rbits) | (IData)(rd)) -#define VL_CONCAT_QII(obits,lbits,rbits,ld,rd) ((QData)(ld)<<(rbits) | (QData)(rd)) -#define VL_CONCAT_QIQ(obits,lbits,rbits,ld,rd) ((QData)(ld)<<(rbits) | (QData)(rd)) -#define VL_CONCAT_QQI(obits,lbits,rbits,ld,rd) ((QData)(ld)<<(rbits) | (QData)(rd)) -#define VL_CONCAT_QQQ(obits,lbits,rbits,ld,rd) ((QData)(ld)<<(rbits) | (QData)(rd)) +#define VL_CONCAT_III(obits,lbits,rbits,ld,rd) (static_cast(ld)<<(rbits) | static_cast(rd)) +#define VL_CONCAT_QII(obits,lbits,rbits,ld,rd) (static_cast(ld)<<(rbits) | static_cast(rd)) +#define VL_CONCAT_QIQ(obits,lbits,rbits,ld,rd) (static_cast(ld)<<(rbits) | static_cast(rd)) +#define VL_CONCAT_QQI(obits,lbits,rbits,ld,rd) (static_cast(ld)<<(rbits) | static_cast(rd)) +#define VL_CONCAT_QQQ(obits,lbits,rbits,ld,rd) (static_cast(ld)<<(rbits) | static_cast(rd)) static inline WDataOutP VL_CONCAT_WII(int obits,int lbits,int rbits,WDataOutP owp,IData ld,IData rd) { owp[0] = rd; @@ -1597,7 +1597,7 @@ static inline void _VL_SHIFTL_INPLACE_W(int obits,WDataOutP iowp,IData rd/*1 or static inline WDataOutP VL_SHIFTL_WWI(int obits,int,int,WDataOutP owp,WDataInP lwp, IData rd) { int word_shift = VL_BITWORD_I(rd); int bit_shift = VL_BITBIT_I(rd); - if (rd >= (IData)obits) { // rd may be huge with MSB set + if (rd >= static_cast(obits)) { // rd may be huge with MSB set for (int i=0; i < VL_WORDS_I(obits); ++i) owp[i] = 0; } else if (bit_shift==0) { // Aligned word shift (<<0,<<32,<<64 etc) for (int i=0; i < word_shift; ++i) owp[i] = 0; @@ -1631,7 +1631,7 @@ static inline IData VL_SHIFTL_IIW(int obits,int,int rbits,IData lhs, WDataInP rw static inline WDataOutP VL_SHIFTR_WWI(int obits,int,int,WDataOutP owp,WDataInP lwp, IData rd) { int word_shift = VL_BITWORD_I(rd); // Maybe 0 int bit_shift = VL_BITBIT_I(rd); - if (rd >= (IData)obits) { // rd may be huge with MSB set + if (rd >= static_cast(obits)) { // rd may be huge with MSB set for (int i=0; i < VL_WORDS_I(obits); ++i) owp[i] = 0; } else if (bit_shift==0) { // Aligned word shift (>>0,>>32,>>64 etc) int copy_words = (VL_WORDS_I(obits)-word_shift); @@ -1686,14 +1686,14 @@ static inline QData VL_SHIFTRS_QQI(int obits, int lbits, int, QData lhs, IData r return (lhs >> rhs) | (sign & VL_CLEAN_QQ(obits,obits,signext)); } static inline IData VL_SHIFTRS_IQI(int obits, int lbits, int rbits, QData lhs, IData rhs) { - return (IData)(VL_SHIFTRS_QQI(obits, lbits, rbits, lhs, rhs)); + return static_cast(VL_SHIFTRS_QQI(obits, lbits, rbits, lhs, rhs)); } static inline WDataOutP VL_SHIFTRS_WWI(int obits,int lbits,int,WDataOutP owp,WDataInP lwp, IData rd) { int word_shift = VL_BITWORD_I(rd); int bit_shift = VL_BITBIT_I(rd); int lmsw = VL_WORDS_I(obits)-1; IData sign = VL_SIGNONES_I(lbits,lwp[lmsw]); - if (rd >= (IData)obits) { // Shifting past end, sign in all of lbits + if (rd >= static_cast(obits)) { // Shifting past end, sign in all of lbits for (int i=0; i <= lmsw; ++i) owp[i] = sign; owp[lmsw] &= VL_MASK_I(lbits); } else if (bit_shift==0) { // Aligned word shift (>>0,>>32,>>64 etc) @@ -1766,11 +1766,11 @@ static inline QData VL_SHIFTRS_QQQ(int obits,int lbits,int rbits,QData lhs, QDat #define VL_BITSEL_IIII(obits,lbits,rbits,zbits,lhs,rhs) ((lhs)>>(rhs)) #define VL_BITSEL_QIII(obits,lbits,rbits,zbits,lhs,rhs) ((lhs)>>(rhs)) #define VL_BITSEL_QQII(obits,lbits,rbits,zbits,lhs,rhs) ((lhs)>>(rhs)) -#define VL_BITSEL_IQII(obits,lbits,rbits,zbits,lhs,rhs) ((IData)((lhs)>>(rhs))) +#define VL_BITSEL_IQII(obits,lbits,rbits,zbits,lhs,rhs) (static_cast((lhs)>>(rhs))) static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP lwp, IData rd) { int word = VL_BITWORD_I(rd); - if (VL_UNLIKELY(rd>(IData)lbits)) { + if (VL_UNLIKELY(rd > static_cast(lbits))) { return ~0; // Spec says you can go outside the range of a array. Don't coredump if so. // We return all 1's as that's more likely to find bugs (?) than 0's. } else { @@ -1782,13 +1782,13 @@ static inline IData VL_BITSEL_IWII(int, int lbits, int, int, WDataInP lwp, IData // & MUST BE CLEAN (currently constant) #define VL_SEL_IIII(obits,lbits,rbits,tbits,lhs,lsb,width) ((lhs)>>(lsb)) #define VL_SEL_QQII(obits,lbits,rbits,tbits,lhs,lsb,width) ((lhs)>>(lsb)) -#define VL_SEL_IQII(obits,lbits,rbits,tbits,lhs,lsb,width) ((IData)((lhs)>>(lsb))) +#define VL_SEL_IQII(obits,lbits,rbits,tbits,lhs,lsb,width) (static_cast((lhs)>>(lsb))) static inline IData VL_SEL_IWII(int, int lbits, int, int, WDataInP lwp, IData lsb, IData width) { int msb = lsb+width-1; if (VL_UNLIKELY(msb>lbits)) { return ~0; // Spec says you can go outside the range of a array. Don't coredump if so. - } else if (VL_BITWORD_I(msb)==VL_BITWORD_I((int)lsb)) { + } else if (VL_BITWORD_I(msb)==VL_BITWORD_I(static_cast(lsb))) { return (lwp[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb)); } else { // 32 bit extraction may span two words @@ -1802,9 +1802,9 @@ static inline QData VL_SEL_QWII(int, int lbits, int, int, WDataInP lwp, IData ls int msb = lsb+width-1; if (VL_UNLIKELY(msb>lbits)) { return ~0; // Spec says you can go outside the range of a array. Don't coredump if so. - } else if (VL_BITWORD_I(msb)==VL_BITWORD_I((int)lsb)) { + } else if (VL_BITWORD_I(msb)==VL_BITWORD_I(static_cast(lsb))) { return (lwp[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb)); - } else if (VL_BITWORD_I(msb)==1+VL_BITWORD_I((int)lsb)) { + } else if (VL_BITWORD_I(msb)==1+VL_BITWORD_I(static_cast(lsb))) { int nbitsfromlow = 32-VL_BITBIT_I(lsb); QData hi = (lwp[VL_BITWORD_I(msb)]); QData lo = (lwp[VL_BITWORD_I(lsb)]>>VL_BITBIT_I(lsb)); @@ -1837,7 +1837,7 @@ static inline WDataOutP VL_SEL_WWII(int obits,int lbits,int,int,WDataOutP owp,WD for (int i=0; i>loffset; int upperword = i+word_shift+1; - if (upperword <= (int)VL_BITWORD_I(msb)) { + if (upperword <= static_cast(VL_BITWORD_I(msb))) { owp[i] |= lwp[upperword]<< nbitsfromlow; } } @@ -1900,7 +1900,7 @@ static inline WDataOutP VL_COND_WIWW(int obits, int, int, int, // If changing the number of functions here, also change EMITCINLINES_NUM_CONSTW #define _END(obits,wordsSet) \ - for(int i=(wordsSet);i(i)); } IData idx = s_s.m_fdFree.back(); s_s.m_fdFree.pop_back(); s_s.m_fdps[idx] = fp; diff --git a/include/verilated_save.cpp b/include/verilated_save.cpp index 6eaf96e59..cd8601804 100644 --- a/include/verilated_save.cpp +++ b/include/verilated_save.cpp @@ -61,7 +61,7 @@ bool VerilatedDeserialize::readDiffers (const void* __restrict datap, size_t siz VerilatedDeserialize& VerilatedDeserialize::readAssert (const void* __restrict datap, size_t size) { if (VL_UNLIKELY(readDiffers(datap,size))) { std::string fn = filename(); - std::string msg = (std::string)"Can't deserialize save-restore file as was made from different model"; + std::string msg = std::string("Can't deserialize save-restore file as was made from different model"); vl_fatal(fn.c_str(), 0, "", msg.c_str()); close(); } @@ -82,7 +82,7 @@ void VerilatedDeserialize::header() { VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below if (VL_UNLIKELY(os.readDiffers(VLTSAVE_HEADER_STR, strlen(VLTSAVE_HEADER_STR)))) { std::string fn = filename(); - std::string msg = (std::string)"Can't deserialize; file has wrong header signature"; + std::string msg = std::string("Can't deserialize; file has wrong header signature"); vl_fatal(fn.c_str(), 0, "", msg.c_str()); close(); } @@ -99,7 +99,7 @@ void VerilatedDeserialize::trailer() { VerilatedDeserialize& os = *this; // So can cut and paste standard >> code below if (VL_UNLIKELY(os.readDiffers(VLTSAVE_TRAILER_STR, strlen(VLTSAVE_TRAILER_STR)))) { 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"); vl_fatal(fn.c_str(), 0, "", msg.c_str()); close(); } diff --git a/include/verilated_sc.h b/include/verilated_sc.h index ebd28e8f6..ce8554889 100644 --- a/include/verilated_sc.h +++ b/include/verilated_sc.h @@ -41,7 +41,7 @@ class VlScBvExposer : public sc_bv_base { public: static vluint32_t* sp_datap(const sc_bv_base& base) { return static_cast(&base)->sp_datatp(); } - vluint32_t* sp_datatp() const { return (vluint32_t*)(m_data); } + vluint32_t* sp_datatp() const { return reinterpret_cast(m_data); } // Above reads this protected element in sc_bv_base: // sc_digit* m_data; // data array }; diff --git a/include/verilated_syms.h b/include/verilated_syms.h index 8266de24d..6d5e7e894 100644 --- a/include/verilated_syms.h +++ b/include/verilated_syms.h @@ -71,7 +71,7 @@ public: ~VerilatedVar() {} void* datap() const { return m_datap; } VerilatedVarType vltype() const { return m_vltype; } - VerilatedVarFlags vldir() const { return (VerilatedVarFlags)((int)m_vlflags & VLVF_MASK_DIR); } + VerilatedVarFlags vldir() const { return static_cast(static_cast(m_vlflags) & VLVF_MASK_DIR); } vluint32_t entSize() const; bool isPublicRW() const { return ((m_vlflags & VLVF_PUB_RW) != 0); } const VerilatedRange& range() const { return m_range; } diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 1d8bdc3ac..d52c91b5b 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -326,7 +326,7 @@ void VerilatedVcd::bufferFlush () { } else if (got < 0) { if (errno != EAGAIN && errno != EINTR) { // 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: ")+strerror(errno); vl_fatal("",0,"",msg.c_str()); closeErr(); break; @@ -571,7 +571,7 @@ void VerilatedVcd::declDouble (vluint32_t code, const char* name, int arraynum void VerilatedVcd::fullDouble (vluint32_t code, const double newval) { // cppcheck-suppress invalidPointerCast - (*((double*)&m_sigs_oldvalp[code])) = newval; + (*(reinterpret_cast(&m_sigs_oldvalp[code]))) = newval; // Buffer can't overflow before sprintf; we sized during declaration sprintf(m_writep, "r%.16g", newval); m_writep += strlen(m_writep); @@ -580,9 +580,9 @@ void VerilatedVcd::fullDouble (vluint32_t code, const double newval) { } void VerilatedVcd::fullFloat (vluint32_t code, const float newval) { // cppcheck-suppress invalidPointerCast - (*((float*)&m_sigs_oldvalp[code])) = newval; + (*(reinterpret_cast(&m_sigs_oldvalp[code]))) = newval; // Buffer can't overflow before sprintf; we sized during declaration - sprintf(m_writep, "r%.16g", (double)newval); + sprintf(m_writep, "r%.16g", static_cast(newval)); m_writep += strlen(m_writep); *m_writep++=' '; printCode(code); *m_writep++='\n'; bufferCheck(); @@ -596,7 +596,7 @@ void VerilatedVcd::addCallback ( void* userthis) { if (VL_UNLIKELY(isOpen())) { - std::string msg = (std::string)"Internal: "+__FILE__+"::"+__FUNCTION__+" called with already open file"; + std::string msg = std::string("Internal: ")+__FILE__+"::"+__FUNCTION__+" called with already open file"; vl_fatal(__FILE__,__LINE__,"",msg.c_str()); } VerilatedVcdCallInfo* vci = new VerilatedVcdCallInfo(initcb, fullcb, changecb, userthis, nextCode()); diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index b353b5401..46b18b763 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -137,17 +137,17 @@ private: // cppcheck-suppress functionConst void dumpDone (); inline void printCode (vluint32_t code) { - if (code>=(94*94*94)) *m_writep++ = ((char)((code/94/94/94)%94+33)); - if (code>=(94*94)) *m_writep++ = ((char)((code/94/94)%94+33)); - if (code>=(94)) *m_writep++ = ((char)((code/94)%94+33)); - *m_writep++ = ((char)((code)%94+33)); + if (code>=(94*94*94)) *m_writep++ = static_cast((code/94/94/94)%94+33); + if (code>=(94*94)) *m_writep++ = static_cast((code/94/94)%94+33); + if (code>=(94)) *m_writep++ = static_cast((code/94)%94+33); + *m_writep++ = static_cast((code)%94+33); } static std::string stringCode (vluint32_t code) { std::string out; - if (code>=(94*94*94)) out += ((char)((code/94/94/94)%94+33)); - if (code>=(94*94)) out += ((char)((code/94/94)%94+33)); - if (code>=(94)) out += ((char)((code/94)%94+33)); - return out + ((char)((code)%94+33)); + if (code>=(94*94*94)) out += static_cast((code/94/94/94)%94+33); + if (code>=(94*94)) out += static_cast((code/94/94)%94+33); + if (code>=(94)) out += static_cast((code/94)%94+33); + return out + static_cast((code)%94+33); } VerilatedVcd(const VerilatedVcd& ); ///< N/A, no copy constructor @@ -192,7 +192,7 @@ public: /// Inside dumping routines, called each cycle to make the dump void dump (vluint64_t timeui); /// Call dump with a absolute unscaled time in seconds - void dumpSeconds (double secs) { dump((vluint64_t)(secs * m_timeRes)); } + void dumpSeconds (double secs) { dump(static_cast(secs * m_timeRes)); } /// Inside dumping routines, declare callbacks for tracings void addCallback (VerilatedVcdCallback_t init, VerilatedVcdCallback_t full, @@ -218,7 +218,7 @@ public: void fullBit (vluint32_t code, const vluint32_t newval) { // Note the &1, so we don't require clean input -- makes more common no change case faster m_sigs_oldvalp[code] = newval; - *m_writep++=('0'+(char)(newval&1)); printCode(code); *m_writep++='\n'; + *m_writep++=('0'+static_cast(newval&1)); printCode(code); *m_writep++='\n'; bufferCheck(); } void fullBus (vluint32_t code, const vluint32_t newval, int bits) { @@ -231,7 +231,7 @@ public: bufferCheck(); } void fullQuad (vluint32_t code, const vluint64_t newval, int bits) { - (*((vluint64_t*)&m_sigs_oldvalp[code])) = newval; + (*(reinterpret_cast(&m_sigs_oldvalp[code]))) = newval; *m_writep++='b'; for (int bit=bits-1; bit>=0; --bit) { *m_writep++=((newval&(1ULL<(&m_sigs_oldvalp[code]))) = newval; + (*(reinterpret_cast(&m_sigs_oldvalp[code+1]))) = newtri; *m_writep++='b'; for (int bit=bits-1; bit>=0; --bit) { *m_writep++ = "01zz"[((newval >> bit)&1ULL) @@ -335,7 +335,7 @@ public: } } inline void chgQuad (vluint32_t code, const vluint64_t newval, int bits) { - vluint64_t diff = (*((vluint64_t*)&m_sigs_oldvalp[code])) ^ newval; + vluint64_t diff = (*(reinterpret_cast(&m_sigs_oldvalp[code]))) ^ newval; if (VL_UNLIKELY(diff)) { if (VL_UNLIKELY(bits==64 || (diff & ((1ULL<(&m_sigs_oldvalp[code]))) ^ newval) + | ((*(reinterpret_cast(&m_sigs_oldvalp[code+1]))) ^ newtri)); if (VL_UNLIKELY(diff)) { if (VL_UNLIKELY(bits==64 || (diff & ((1ULL<(&m_sigs_oldvalp[code]))) != newval)) { fullDouble (code, newval); } } inline void chgFloat (vluint32_t code, const float newval) { // cppcheck-suppress invalidPointerCast - if (VL_UNLIKELY((*((float*)&m_sigs_oldvalp[code])) != newval)) { + if (VL_UNLIKELY((*(reinterpret_cast(&m_sigs_oldvalp[code]))) != newval)) { fullFloat (code, newval); } } @@ -433,9 +433,9 @@ public: void dump (vluint64_t timeui) { m_sptrace.dump(timeui); } /// Write one cycle of dump data - backward compatible and to reduce /// conversion warnings. It's better to use a vluint64_t time instead. - void dump (double timestamp) { dump((vluint64_t)timestamp); } - void dump (vluint32_t timestamp) { dump((vluint64_t)timestamp); } - void dump (int timestamp) { dump((vluint64_t)timestamp); } + void dump (double timestamp) { dump(static_cast(timestamp)); } + void dump (vluint32_t timestamp) { dump(static_cast(timestamp)); } + void dump (int timestamp) { dump(static_cast(timestamp)); } /// Set time units (s/ms, defaults to ns) /// See also VL_TIME_PRECISION, and VL_TIME_MULTIPLIER in verilated.h void set_time_unit (const char* unit) { m_sptrace.set_time_unit(unit); } diff --git a/include/verilatedos.h b/include/verilatedos.h index ac6a9a1cd..48f46e1b4 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -96,7 +96,7 @@ #endif // This is not necessarily the same as #UL, depending on what the IData typedef is. -#define VL_UL(c) ((IData)(c##UL)) ///< Add appropriate suffix to 32-bit constant +#define VL_UL(c) (static_cast(c##UL)) ///< Add appropriate suffix to 32-bit constant #if defined(VL_CPPCHECK) || defined(__clang_analyzer__) # define VL_DANGLING(v)