From 21030f0a4fe7b09f89b0c0b28b66396a9c020e60 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 14 Oct 2017 13:00:42 -0400 Subject: [PATCH] Internals: C++ style casts. No functional change intended. --- include/verilated.cpp | 14 ++++---- include/verilated_dpi.cpp | 4 +-- include/verilated_vpi.cpp | 73 +++++++++++++++++++++------------------ include/verilated_vpi.h | 8 +++-- 4 files changed, 53 insertions(+), 46 deletions(-) diff --git a/include/verilated.cpp b/include/verilated.cpp index fed28d6a7..93f33dc54 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -194,9 +194,9 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, boo if (vw == 1) { // Single divisor word breaks rest of algorithm vluint64_t k = 0; for (int j = uw-1; j >= 0; --j) { - vluint64_t unw64 = ((k<(lwp[j])); + owp[j] = unw64 / static_cast(rwp[0]); + k = unw64 - static_cast(owp[j])*static_cast(rwp[0]); } if (is_modulus) { owp[0] = k; @@ -233,9 +233,9 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, boo // Main loop for (int j = uw - vw; j >= 0; --j) { // Estimate - vluint64_t unw64 = ((vluint64_t)(un[j+vw])<(un[j+vw])<(un[j+vw-1])); + vluint64_t qhat = unw64 / static_cast(vn[vw-1]); + vluint64_t rhat = unw64 - qhat*static_cast(vn[vw-1]); again: if (qhat >= VL_ULL(0x100000000) @@ -262,7 +262,7 @@ WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP rwp, boo owp[j]--; k = 0; for (int i=0; i(un[i+j]) + static_cast(vn[i]) + k; un[i+j] = t; k = t >> VL_ULL(32); } diff --git a/include/verilated_dpi.cpp b/include/verilated_dpi.cpp index 1e2ed4576..e253ead01 100644 --- a/include/verilated_dpi.cpp +++ b/include/verilated_dpi.cpp @@ -263,13 +263,13 @@ svScope svGetScope() { svScope svSetScope(const svScope scope) { const VerilatedScope* prevScopep = Verilated::dpiScope(); - const VerilatedScope* vscopep = (const VerilatedScope*)(scope); + const VerilatedScope* vscopep = reinterpret_cast(scope); Verilated::dpiScope(vscopep); return (svScope)prevScopep; } const char* svGetNameFromScope(const svScope scope) { - const VerilatedScope* vscopep = (const VerilatedScope*)(scope); + const VerilatedScope* vscopep = reinterpret_cast(scope); return vscopep->name(); } diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 357491356..cad0759e0 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -737,15 +737,15 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { value_p->value.vector = out; switch (vop->varp()->vltype()) { case VLVT_UINT8: - out[0].aval = *((CData*)(vop->varDatap())); + out[0].aval = *(reinterpret_cast(vop->varDatap())); out[0].bval = 0; return; case VLVT_UINT16: - out[0].aval = *((SData*)(vop->varDatap())); + out[0].aval = *(reinterpret_cast(vop->varDatap())); out[0].bval = 0; return; case VLVT_UINT32: - out[0].aval = *((IData*)(vop->varDatap())); + out[0].aval = *(reinterpret_cast(vop->varDatap())); out[0].bval = 0; return; case VLVT_WDATA: { @@ -753,7 +753,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { if (VL_UNLIKELY(words >= VL_MULS_MAX_WORDS)) { vl_fatal(__FILE__,__LINE__,"", "vpi_get_value with more than VL_MULS_MAX_WORDS; increase and recompile"); } - WDataInP datap = ((IData*)(vop->varDatap())); + WDataInP datap = (reinterpret_cast(vop->varDatap())); for (int i=0; ivarDatap())); - out[1].aval = (IData)(data>>VL_ULL(32)); + QData data = *(reinterpret_cast(vop->varDatap())); + out[1].aval = static_cast(data>>VL_ULL(32)); out[1].bval = 0; - out[0].aval = (IData)(data); + out[0].aval = static_cast(data); out[0].bval = 0; return; } @@ -783,7 +783,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { case VLVT_UINT64: case VLVT_WDATA: { int bits = vop->varp()->range().elements(); - CData* datap = ((CData*)(vop->varDatap())); + CData* datap = (reinterpret_cast(vop->varDatap())); int i; if (bits > outStrSz) { // limit maximum size of output to size of buffer to prevent overrun. @@ -813,7 +813,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { case VLVT_WDATA: { int chars = (vop->varp()->range().elements()+2)/3; int bytes = VL_BYTES_I(vop->varp()->range().elements()); - CData* datap = ((CData*)(vop->varDatap())); + CData* datap = (reinterpret_cast(vop->varDatap())); int i; if (chars > outStrSz) { // limit maximum size of output to size of buffer to prevent overrun. @@ -855,10 +855,14 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { value_p->value.str = outStr; switch (vop->varp()->vltype()) { // outStrSz does not include NULL termination so add one - case VLVT_UINT8 : VL_SNPRINTF(outStr, outStrSz+1, "%hhu", (unsigned char )*((CData*)(vop->varDatap()))); return; - case VLVT_UINT16: VL_SNPRINTF(outStr, outStrSz+1, "%hu", (unsigned short)*((SData*)(vop->varDatap()))); return; - case VLVT_UINT32: VL_SNPRINTF(outStr, outStrSz+1, "%u", (unsigned int )*((IData*)(vop->varDatap()))); return; - case VLVT_UINT64: VL_SNPRINTF(outStr, outStrSz+1, "%llu", (unsigned long long)*((QData*)(vop->varDatap()))); return; + case VLVT_UINT8 : VL_SNPRINTF(outStr, outStrSz+1, "%hhu", + static_cast(*(reinterpret_cast(vop->varDatap())))); return; + case VLVT_UINT16: VL_SNPRINTF(outStr, outStrSz+1, "%hu", + static_cast(*(reinterpret_cast(vop->varDatap())))); return; + case VLVT_UINT32: VL_SNPRINTF(outStr, outStrSz+1, "%u", + static_cast(*(reinterpret_cast(vop->varDatap())))); return; + case VLVT_UINT64: VL_SNPRINTF(outStr, outStrSz+1, "%llu", + static_cast(*(reinterpret_cast(vop->varDatap())))); return; default: strcpy(outStr, "-1"); _VL_VPI_ERROR(__FILE__, __LINE__, "%s: Unsupported format (%s) for %s, maximum limit is 64 bits", @@ -874,7 +878,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { case VLVT_UINT64: case VLVT_WDATA: { int chars = (vop->varp()->range().elements()+3)>>2; - CData* datap = ((CData*)(vop->varDatap())); + CData* datap = (reinterpret_cast(vop->varDatap())); int i; if (chars > outStrSz) { // limit maximum size of output to size of buffer to prevent overrun. @@ -912,7 +916,7 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { case VLVT_UINT64: case VLVT_WDATA: { int bytes = VL_BYTES_I(vop->varp()->range().elements()); - CData* datap = ((CData*)(vop->varDatap())); + CData* datap = (reinterpret_cast(vop->varDatap())); int i; if (bytes > outStrSz) { // limit maximum size of output to size of buffer to prevent overrun. @@ -937,13 +941,13 @@ void vpi_get_value(vpiHandle object, p_vpi_value value_p) { } else if (value_p->format == vpiIntVal) { switch (vop->varp()->vltype()) { case VLVT_UINT8: - value_p->value.integer = *((CData*)(vop->varDatap())); + value_p->value.integer = *(reinterpret_cast(vop->varDatap())); return; case VLVT_UINT16: - value_p->value.integer = *((SData*)(vop->varDatap())); + value_p->value.integer = *(reinterpret_cast(vop->varDatap())); return; case VLVT_UINT32: - value_p->value.integer = *((IData*)(vop->varDatap())); + value_p->value.integer = *(reinterpret_cast(vop->varDatap())); return; case VLVT_WDATA: // FALLTHRU case VLVT_UINT64: // FALLTHRU @@ -994,17 +998,17 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p, if (VL_UNLIKELY(!value_p->value.vector)) return NULL; switch (vop->varp()->vltype()) { case VLVT_UINT8: - *((CData*)(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask(); + *(reinterpret_cast(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask(); return object; case VLVT_UINT16: - *((SData*)(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask(); + *(reinterpret_cast(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask(); return object; case VLVT_UINT32: - *((IData*)(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask(); + *(reinterpret_cast(vop->varDatap())) = value_p->value.vector[0].aval & vop->mask(); return object; case VLVT_WDATA: { int words = VL_WORDS_I(vop->varp()->range().elements()); - WDataOutP datap = ((IData*)(vop->varDatap())); + WDataOutP datap = (reinterpret_cast(vop->varDatap())); for (int i=0; ivalue.vector[i].aval; if (i==(words-1)) { @@ -1014,7 +1018,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p, return object; } case VLVT_UINT64: { - *((QData*)(vop->varDatap())) = _VL_SET_QII( + *(reinterpret_cast(vop->varDatap())) = _VL_SET_QII( value_p->value.vector[1].aval & vop->mask(), value_p->value.vector[0].aval); return object; @@ -1034,7 +1038,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p, case VLVT_WDATA: { int bits = vop->varp()->range().elements(); int len = strlen(value_p->value.str); - CData* datap = ((CData*)(vop->varDatap())); + CData* datap = (reinterpret_cast(vop->varDatap())); for (int i=0; ivalue.str[len-i-1]=='1'):0; // zero bits 7:1 of byte when assigning to bit 0, else @@ -1062,7 +1066,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p, int chars = (vop->varp()->range().elements()+2)/3; int bytes = VL_BYTES_I(vop->varp()->range().elements()); int len = strlen(value_p->value.str); - CData* datap = ((CData*)(vop->varDatap())); + CData* datap = (reinterpret_cast(vop->varDatap())); div_t idx; datap[0] = 0; // reset zero'th byte for (int i=0; ivalue.str, VerilatedVpiError::strFromVpiVal(value_p->format), vop->fullname()); } switch (vop->varp()->vltype()) { - case VLVT_UINT8 : *((CData*)(vop->varDatap())) = val & vop->mask(); break; - case VLVT_UINT16: *((SData*)(vop->varDatap())) = val & vop->mask(); break; - case VLVT_UINT32: *((IData*)(vop->varDatap())) = val & vop->mask(); break; - case VLVT_UINT64: *((QData*)(vop->varDatap())) = val; ((IData*)(vop->varDatap()))[1] &= vop->mask(); break; + case VLVT_UINT8 : *(reinterpret_cast(vop->varDatap())) = val & vop->mask(); break; + case VLVT_UINT16: *(reinterpret_cast(vop->varDatap())) = val & vop->mask(); break; + case VLVT_UINT32: *(reinterpret_cast(vop->varDatap())) = val & vop->mask(); break; + case VLVT_UINT64: *(reinterpret_cast(vop->varDatap())) = val; + (reinterpret_cast(vop->varDatap()))[1] &= vop->mask(); break; case VLVT_WDATA: default: _VL_VPI_ERROR(__FILE__, __LINE__, "%s: Unsupported format (%s) for %s, maximum limit is 64 bits", @@ -1146,7 +1151,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p, case VLVT_UINT64: case VLVT_WDATA: { int chars = (vop->varp()->range().elements()+3)>>2; - CData* datap = ((CData*)(vop->varDatap())); + CData* datap = (reinterpret_cast(vop->varDatap())); char* val = value_p->value.str; // skip hex ident if one is detected at the start of the string if (val[0] == '0' && (val[1] == 'x' || val[1] == 'X')) { @@ -1194,7 +1199,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p, case VLVT_WDATA: { int bytes = VL_BYTES_I(vop->varp()->range().elements()); int len = strlen(value_p->value.str); - CData* datap = ((CData*)(vop->varDatap())); + CData* datap = (reinterpret_cast(vop->varDatap())); for (int i=0; ivalue.str[len-i-1]:0; // prepend with 0 values before placing string the least signifcant bytes } @@ -1208,13 +1213,13 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value value_p, } else if (value_p->format == vpiIntVal) { switch (vop->varp()->vltype()) { case VLVT_UINT8: - *((CData*)(vop->varDatap())) = vop->mask() & value_p->value.integer; + *(reinterpret_cast(vop->varDatap())) = vop->mask() & value_p->value.integer; return object; case VLVT_UINT16: - *((SData*)(vop->varDatap())) = vop->mask() & value_p->value.integer; + *(reinterpret_cast(vop->varDatap())) = vop->mask() & value_p->value.integer; return object; case VLVT_UINT32: - *((IData*)(vop->varDatap())) = vop->mask() & value_p->value.integer; + *(reinterpret_cast(vop->varDatap())) = vop->mask() & value_p->value.integer; return object; case VLVT_WDATA: // FALLTHRU case VLVT_UINT64: // FALLTHRU diff --git a/include/verilated_vpi.h b/include/verilated_vpi.h index 3647e4b9d..cb80528af 100644 --- a/include/verilated_vpi.h +++ b/include/verilated_vpi.h @@ -83,7 +83,7 @@ public: return newp+8; } else { // +8: 8 bytes for next - vluint8_t* newp = (vluint8_t*)(::operator new(chunk+8)); + vluint8_t* newp = reinterpret_cast(::operator new(chunk+8)); return newp+8; } } @@ -94,7 +94,7 @@ public: } // MEMBERS static inline VerilatedVpio* castp(vpiHandle h) { return dynamic_cast((VerilatedVpio*)h); } - inline vpiHandle castVpiHandle() { return (vpiHandle)(this); } + inline vpiHandle castVpiHandle() { return reinterpret_cast(this); } // ACCESSORS virtual const char* name() const { return ""; } virtual const char* fullname() const { return ""; } @@ -287,7 +287,9 @@ public: virtual ~VerilatedVpioMemoryWordIter() {} static inline VerilatedVpioMemoryWordIter* castp(vpiHandle h) { return dynamic_cast((VerilatedVpio*)h); } virtual vluint32_t type() const { return vpiIterator; } - void iterationInc() { if (!(m_done = (m_iteration == m_varp->array().left()))) m_iteration+=m_direction; } + void iterationInc() { + if (!(m_done = (m_iteration == m_varp->array().left()))) m_iteration+=m_direction; + } virtual vpiHandle dovpi_scan() { vpiHandle result; if (m_done) return 0;