From 304a24d03a2b521566204aaafdf77b72ed2b46bd Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 14 Oct 2018 18:39:33 -0400 Subject: [PATCH] Internals: Fix many clang-tidy issues. No functional change intended. --- .clang-tidy | 9 ++ .gitignore | 1 + MANIFEST.SKIP | 4 +- Makefile.in | 21 ++++- include/verilated.cpp | 92 ++++++++++---------- include/verilated.h | 155 +++++++++++++++++----------------- include/verilated_cov.cpp | 24 +++--- include/verilated_dpi.cpp | 9 +- include/verilated_fst_c.cpp | 2 +- include/verilated_fst_c.h | 8 +- include/verilated_heavy.h | 6 +- include/verilated_lxt2_c.h | 8 +- include/verilated_save.cpp | 9 +- include/verilated_vcd_c.cpp | 13 ++- include/verilated_vcd_c.h | 10 +-- include/verilated_vpi.cpp | 32 +++---- include/verilatedos.h | 2 +- src/V3Assert.cpp | 7 +- src/V3Ast.cpp | 22 ++--- src/V3Ast.h | 22 ++--- src/V3AstNodes.cpp | 10 ++- src/V3AstNodes.h | 4 +- src/V3Branch.cpp | 4 +- src/V3Branch.h | 2 +- src/V3Broken.cpp | 7 +- src/V3Cdc.cpp | 18 ++-- src/V3Clean.cpp | 2 +- src/V3ClkGater.cpp | 8 +- src/V3Clock.cpp | 2 +- src/V3Combine.cpp | 2 +- src/V3Const.cpp | 22 ++--- src/V3Coverage.cpp | 12 +-- src/V3EmitC.cpp | 23 +++-- src/V3EmitV.cpp | 4 +- src/V3EmitV.h | 2 +- src/V3EmitXml.cpp | 6 +- src/V3Error.cpp | 2 +- src/V3Expand.cpp | 34 +++++--- src/V3File.cpp | 23 ++--- src/V3File.h | 8 +- src/V3FileLine.cpp | 26 +++--- src/V3FileLine.h | 4 +- src/V3Gate.cpp | 40 +++++---- src/V3GraphAcyc.cpp | 35 ++++---- src/V3GraphAlg.cpp | 6 +- src/V3GraphDfa.cpp | 4 +- src/V3GraphPathChecker.h | 2 +- src/V3GraphTest.cpp | 2 +- src/V3Inst.h | 4 +- src/V3LifePost.cpp | 4 +- src/V3LinkCells.cpp | 10 +-- src/V3LinkDot.h | 10 +-- src/V3LinkLValue.cpp | 4 +- src/V3LinkLevel.cpp | 28 +++--- src/V3LinkLevel.h | 6 +- src/V3LinkParse.h | 2 +- src/V3LinkResolve.h | 2 +- src/V3Localize.cpp | 4 +- src/V3Number.cpp | 96 +++++++++++---------- src/V3Number.h | 28 +++--- src/V3Number_test.cpp | 4 + src/V3Options.cpp | 11 ++- src/V3Options.h | 10 +-- src/V3Order.cpp | 19 +++-- src/V3Os.cpp | 1 + src/V3Os.h | 2 +- src/V3Param.cpp | 33 ++++---- src/V3ParseImp.cpp | 2 +- src/V3ParseImp.h | 2 +- src/V3ParseLex.cpp | 23 ++--- src/V3Partition.cpp | 15 ++-- src/V3Partition.h | 2 +- src/V3PreProc.cpp | 37 ++++---- src/V3PreProc.h | 2 +- src/V3PreShell.h | 6 +- src/V3Scope.cpp | 4 +- src/V3Slice.cpp | 8 +- src/V3Split.cpp | 39 +++++---- src/V3StatsReport.cpp | 2 +- src/V3String.cpp | 45 +++++----- src/V3Subst.cpp | 15 ++-- src/V3TSP.cpp | 4 +- src/V3Table.cpp | 11 +-- src/V3Task.cpp | 12 +-- src/V3TraceDecl.cpp | 4 +- src/V3Tristate.cpp | 22 ++--- src/V3Undriven.cpp | 6 +- src/V3Unknown.cpp | 10 +-- src/V3Width.cpp | 8 +- src/V3WidthSel.cpp | 12 +-- src/Verilator.cpp | 2 +- src/VlcMain.cpp | 4 +- src/VlcOptions.h | 2 +- src/VlcTop.cpp | 4 +- test_regress/t/t_dist_tabs.pl | 7 ++ 95 files changed, 724 insertions(+), 634 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..77d0ee43a --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,9 @@ +Checks: 'clang-diagnostic-*,clang-analyzer-*,*,-modernize*,-hicpp*,-android-cloexec-fopen,-cert-dcl50-cpp,-cert-env33-c,-cert-err34-c,-cert-err58-cpp,-clang-analyzer-core.UndefinedBinaryOperatorResult,-clang-analyzer-security*,-cppcoreguidelines-no-malloc,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-pro-type-const-cast,-cppcoreguidelines-pro-type-reinterpret-cast,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-type-vararg,-cppcoreguidelines-special-member-functions,-fuchsia-default-arguments,-fuchsia-overloaded-operator,-google-default-arguments,-google-readability-todo,-google-runtime-references,-llvm-header-guard,-llvm-include-order,-misc-string-integer-assignment,-misc-string-literal-with-embedded-nul,-readability-braces-around-statements,-readability-container-size-empty,-readability-delete-null-pointer,-readability-else-after-return,-readability-implicit-bool-conversion,-readability-named-parameter,-readability-static-accessed-through-instance' +WarningsAsErrors: '' +HeaderFilterRegex: '' +FormatStyle: none +CheckOptions: + - key: google-readability-braces-around-statements.ShortStatementLines + value: '2' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' diff --git a/.gitignore b/.gitignore index 0e9b76aa1..fdbb3d1d1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ \#* .#* *~ +*.tidy *.old *.gz *.gz.uu diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 91b0f8131..cafdec143 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -1,5 +1,4 @@ -^CVS/ -/CVS/ +\.clang-tidy \.git/ \.svn/ \.(bak|old)/ @@ -9,6 +8,7 @@ .*\.log \..*\.swp .*\.tmp +.*\.tidy .*\.tex .*\.key .*\.vcd diff --git a/Makefile.in b/Makefile.in index e8621f844..2665a18c3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -427,14 +427,16 @@ endif endif # Use --xml flag to see the cppcheck code to use for suppression +CPPCHECK_CPP = $(wildcard \ + $(srcdir)/include/*.cpp \ + $(srcdir)/src/*.cpp ) +CPPCHECK_H = $(wildcard \ + $(srcdir)/include/*.h \ + $(srcdir)/src/*.h ) CPPCHECK = src/cppcheck_filtered CPPCHECK_FLAGS = --enable=all --inline-suppr \ --suppress=unusedScopedObject --suppress=cstyleCast --suppress=useInitializationList CPPCHECK_FLAGS += --xml -CPPCHECK_CPP = $(wildcard \ - $(srcdir)/include/*.cpp \ - $(srcdir)/include/gtkwave/*.cpp \ - $(srcdir)/src/*.cpp) CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP)) CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src @@ -442,6 +444,17 @@ cppcheck: $(CPPCHECK_DEP) %.cppcheck: %.cpp $(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $< +CLANGTIDY = clang-tidy +CLANGTIDY_FLAGS = -config='' +CLANGTIDY_DEP = $(subst .h,.h.tidy,$(CPPCHECK_H)) \ + $(subst .cpp,.cpp.tidy,$(CPPCHECK_CPP)) + +clangtidy: $(CLANGTIDY_DEP) +%.cpp.tidy: %.cpp + $(CLANGTIDY) $(CLANGTIDY_FLAGS) $< -- -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) | 2>&1 tee $@ +%.h.tidy: %.h + $(CLANGTIDY) $(CLANGTIDY_FLAGS) $< -- -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) | 2>&1 tee $@ + analyzer-src: -rm -rf src/obj_dbg scan-build $(MAKE) -k verilator_coverage_bin_dbg verilator_bin_dbg diff --git a/include/verilated.cpp b/include/verilated.cpp index 56dde07e3..95631a5d8 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -135,13 +135,11 @@ std::string _vl_string_vprintf(const char* formatp, va_list ap) VL_MT_SAFE { int len = VL_VSNPRINTF(NULL, 0, formatp, aq); va_end(aq); if (VL_UNLIKELY(len < 1)) { - va_end(ap); return ""; } char* bufp = new char[len+1]; VL_VSNPRINTF(bufp, len+1, formatp, ap); - va_end(ap); std::string out = std::string(bufp, len); delete[] bufp; @@ -240,10 +238,10 @@ vluint64_t vl_rand64() VL_MT_SAFE { t_seeded = true; { VerilatedLockGuard lock(s_mutex); - t_state[0] = (((vluint64_t)vl_sys_rand32())<<32 - ^ ((vluint64_t)vl_sys_rand32())); - t_state[1] = (((vluint64_t)vl_sys_rand32())<<32 - ^ ((vluint64_t)vl_sys_rand32())); + t_state[0] = ((static_cast(vl_sys_rand32()) << 32) + ^ (static_cast(vl_sys_rand32()))); + t_state[1] = ((static_cast(vl_sys_rand32()) << 32) + ^ (static_cast(vl_sys_rand32()))); // Fix state as algorithm is slow to randomize if many zeros // This causes a loss of ~ 1 bit of seed entropy, no big deal if (VL_COUNTONES_I(t_state[0]) < 10) t_state[0] = ~t_state[0]; @@ -1245,19 +1243,19 @@ IData VL_SSCANF_INX(int, const std::string& ld, const char* formatp, ...) VL_MT_ } void VL_WRITEMEM_Q(bool hex, int width, int depth, int array_lsb, int, - QData ofilename, const void* memp, IData start, + QData filename, const void* memp, IData start, IData end) VL_MT_SAFE { - WData fnw[2]; VL_SET_WQ(fnw, ofilename); - return VL_WRITEMEM_W(hex, width,depth,array_lsb,2,fnw,memp,start,end); + WData fnw[2]; VL_SET_WQ(fnw, filename); + return VL_WRITEMEM_W(hex, width, depth, array_lsb,2, fnw, memp, start, end); } void VL_WRITEMEM_W(bool hex, int width, int depth, int array_lsb, int fnwords, - WDataInP ofilenamep, const void* memp, IData start, + WDataInP filenamep, const void* memp, IData start, IData end) VL_MT_SAFE { - char ofilenamez[VL_TO_STRING_MAX_WORDS*VL_WORDSIZE+1]; - _VL_VINT_TO_STRING(fnwords*VL_WORDSIZE, ofilenamez, ofilenamep); - std::string ofilenames(ofilenamez); - return VL_WRITEMEM_N(hex, width,depth,array_lsb,ofilenames,memp,start,end); + char filenamez[VL_TO_STRING_MAX_WORDS*VL_WORDSIZE+1]; + _VL_VINT_TO_STRING(fnwords*VL_WORDSIZE, filenamez, filenamep); + std::string filenames(filenamez); + return VL_WRITEMEM_N(hex, width, depth, array_lsb, filenames, memp, start, end); } const char* memhFormat(int nBits) { @@ -1284,19 +1282,19 @@ void VL_WRITEMEM_N( int depth, // Number of rows int array_lsb, // Index of first row. Valid row addresses // // range from array_lsb up to (array_lsb + depth - 1) - const std::string& ofilenamep, // Output file name + const std::string& filename, // Output file name const void* memp, // Array state IData start, // First array row address to write IData end // Last address to write ) VL_MT_SAFE { if (VL_UNLIKELY(!hex)) { - VL_FATAL_MT(ofilenamep.c_str(), 0, "", + VL_FATAL_MT(filename.c_str(), 0, "", "VL_WRITEMEM_N only supports hex format for now, sorry!"); return; } - FILE* fp = fopen(ofilenamep.c_str(), "w"); + FILE* fp = fopen(filename.c_str(), "w"); if (VL_UNLIKELY(!fp)) { - VL_FATAL_MT(ofilenamep.c_str(), 0, "", "$writemem file not found"); + VL_FATAL_MT(filename.c_str(), 0, "", "$writemem file not found"); return; } @@ -1305,7 +1303,7 @@ void VL_WRITEMEM_N( || (row_addr > array_lsb + depth - 1)) { vluint32_t endmax = ~0; if (end != endmax) { - VL_FATAL_MT(ofilenamep.c_str(), 0, "", + VL_FATAL_MT(filename.c_str(), 0, "", "$writemem specified address out-of-bounds"); } // else, it's not an error to overflow due to end == endmax, @@ -1369,17 +1367,17 @@ void VL_WRITEMEM_N( } void VL_READMEM_Q(bool hex, int width, int depth, int array_lsb, int, - QData ofilename, void* memp, IData start, IData end) VL_MT_SAFE { - WData fnw[2]; VL_SET_WQ(fnw, ofilename); - return VL_READMEM_W(hex,width,depth,array_lsb,2,fnw,memp,start,end); + QData filename, void* memp, IData start, IData end) VL_MT_SAFE { + WData fnw[2]; VL_SET_WQ(fnw, filename); + return VL_READMEM_W(hex, width, depth, array_lsb, 2, fnw, memp, start, end); } void VL_READMEM_W(bool hex, int width, int depth, int array_lsb, int fnwords, - WDataInP ofilenamep, void* memp, IData start, IData end) VL_MT_SAFE { - char ofilenamez[VL_TO_STRING_MAX_WORDS*VL_WORDSIZE+1]; - _VL_VINT_TO_STRING(fnwords*VL_WORDSIZE, ofilenamez, ofilenamep); - std::string ofilenames(ofilenamez); - return VL_READMEM_N(hex,width,depth,array_lsb,ofilenames,memp,start,end); + WDataInP filenamep, void* memp, IData start, IData end) VL_MT_SAFE { + char filenamez[VL_TO_STRING_MAX_WORDS*VL_WORDSIZE+1]; + _VL_VINT_TO_STRING(fnwords*VL_WORDSIZE, filenamez, filenamep); + std::string filenames(filenamez); + return VL_READMEM_N(hex, width, depth, array_lsb, filenames, memp, start, end); } void VL_READMEM_N( @@ -1388,15 +1386,15 @@ void VL_READMEM_N( int depth, // Number of rows int array_lsb, // Index of first row. Valid row addresses // // range from array_lsb up to (array_lsb + depth - 1) - const std::string& ofilenamep, // Input file name + const std::string& filename, // Input file name void* memp, // Array state IData start, // First array row address to read IData end // Last row address to read ) VL_MT_SAFE { - FILE* fp = fopen(ofilenamep.c_str(), "r"); + FILE* fp = fopen(filename.c_str(), "r"); if (VL_UNLIKELY(!fp)) { // We don't report the Verilog source filename as it slow to have to pass it down - VL_FATAL_MT(ofilenamep.c_str(), 0, "", "$readmem file not found"); + VL_FATAL_MT(filename.c_str(), 0, "", "$readmem file not found"); return; } // Prep for reading @@ -1443,7 +1441,7 @@ void VL_READMEM_N( //printf(" Value width=%d @%x = %c\n", width, addr, c); if (VL_UNLIKELY(addr >= static_cast(depth+array_lsb) || addr < static_cast(array_lsb))) { - VL_FATAL_MT(ofilenamep.c_str(), linenum, "", + VL_FATAL_MT(filename.c_str(), linenum, "", "$readmem file address beyond bounds of array"); } else { int entry = addr - array_lsb; @@ -1473,7 +1471,7 @@ void VL_READMEM_N( datap[0] |= value; } if (VL_UNLIKELY(value>=(1<> 8; // Want exit status } IData VL_TESTPLUSARGS_I(const char* formatp) VL_MT_SAFE { const std::string& match = VerilatedImp::argPlusMatch(formatp); - if (match == "") return 0; + if (match.empty()) return 0; else return 1; } @@ -1538,7 +1537,7 @@ IData VL_VALUEPLUSARGS_INW(int rbits, const std::string& ld, WDataOutP rwp) VL_M const std::string& match = VerilatedImp::argPlusMatch(prefix.c_str()); const char* dp = match.c_str() + 1 /*leading + */ + prefix.length(); - if (match == "") return 0; + if (match.empty()) return 0; VL_ZERO_RESET_W(rbits, rwp); switch (tolower(fmt)) { @@ -1594,7 +1593,7 @@ IData VL_VALUEPLUSARGS_INN(int, const std::string& ld, std::string& rdr) VL_MT_S } const std::string& match = VerilatedImp::argPlusMatch(prefix.c_str()); const char* dp = match.c_str() + 1 /*leading + */ + prefix.length(); - if (match == "") return 0; + if (match.empty()) return 0; rdr = std::string(dp); return 1; } @@ -1602,7 +1601,7 @@ IData VL_VALUEPLUSARGS_INN(int, const std::string& ld, std::string& rdr) VL_MT_S const char* vl_mc_scan_plusargs(const char* prefixp) VL_MT_SAFE { const std::string& match = VerilatedImp::argPlusMatch(prefixp); static VL_THREAD_LOCAL char outstr[VL_VALUE_STRING_MAX_WIDTH]; - if (match == "") return NULL; + if (match.empty()) return NULL; strncpy(outstr, match.c_str()+strlen(prefixp)+1, // +1 to skip the "+" VL_VALUE_STRING_MAX_WIDTH); outstr[VL_VALUE_STRING_MAX_WIDTH-1] = '\0'; @@ -1646,10 +1645,10 @@ Verilated::ThreadLocal::ThreadLocal() Verilated::ThreadLocal::~ThreadLocal() { } -void Verilated::debug(int val) VL_MT_SAFE { +void Verilated::debug(int level) VL_MT_SAFE { VerilatedLockGuard lock(m_mutex); - s_s.s_debug = val; - if (val) { + s_s.s_debug = level; + if (level) { #ifdef VL_DEBUG VL_DEBUG_IF(VL_DBG_MSGF("- Verilated::debug is on. Message prefix indicates {,}.\n");); #else @@ -1743,7 +1742,7 @@ void Verilated::commandArgs(int argc, const char** argv) VL_MT_SAFE { const char* Verilated::commandArgsPlusMatch(const char* prefixp) VL_MT_SAFE { const std::string& match = VerilatedImp::argPlusMatch(prefixp); static VL_THREAD_LOCAL char outstr[VL_VALUE_STRING_MAX_WIDTH]; - if (match == "") return ""; + if (match.empty()) return ""; strncpy(outstr, match.c_str(), VL_VALUE_STRING_MAX_WIDTH); outstr[VL_VALUE_STRING_MAX_WIDTH-1] = '\0'; return outstr; @@ -1917,7 +1916,8 @@ VerilatedModule::VerilatedModule(const char* namep) VerilatedModule::~VerilatedModule() { // Memory cleanup - not called during normal operation - if (m_namep) { free((void*)m_namep); m_namep=NULL; } + // NOLINTNEXTLINE(google-readability-casting) + if (m_namep) { free((void*)(m_namep)); m_namep=NULL; } } //====================================================================== @@ -2017,7 +2017,7 @@ void VerilatedScope::varInsert(int finalize, const char* namep, void* datap, if (!finalize) return; if (!m_varsp) m_varsp = new VerilatedVarNameMap(); - VerilatedVar var(namep, datap, vltype, (VerilatedVarFlags)vlflags, dims); + VerilatedVar var(namep, datap, vltype, static_cast(vlflags), dims); va_list ap; va_start(ap,dims); diff --git a/include/verilated.h b/include/verilated.h index 365f21aac..939bddc3d 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -583,29 +583,29 @@ extern WDataOutP _vl_moddiv_w(int lbits, WDataOutP owp, WDataInP lwp, WDataInP r /// File I/O extern IData VL_FGETS_IXI(int obits, void* destp, IData fpi); -extern IData VL_FOPEN_S(const char* filenamep, const char* mode); -extern IData VL_FOPEN_WI(int fnwords, WDataInP ofilename, IData mode); -extern IData VL_FOPEN_QI(QData ofilename, IData mode); -inline IData VL_FOPEN_II(IData ofilename, IData mode) VL_MT_SAFE { - return VL_FOPEN_QI(ofilename,mode); } +extern IData VL_FOPEN_S(const char* filenamep, const char* modep); +extern IData VL_FOPEN_WI(int fnwords, WDataInP filenamep, IData mode); +extern IData VL_FOPEN_QI(QData filename, IData mode); +inline IData VL_FOPEN_II(IData filename, IData mode) VL_MT_SAFE { + return VL_FOPEN_QI(filename,mode); } extern void VL_FCLOSE_I(IData fdi); extern void VL_READMEM_W(bool hex, int width, int depth, int array_lsb, int fnwords, - WDataInP ofilename, void* memp, IData start, IData end); + WDataInP filenamep, void* memp, IData start, IData end); extern void VL_READMEM_Q(bool hex, int width, int depth, int array_lsb, int fnwords, - QData ofilename, void* memp, IData start, IData end); + QData filename, void* memp, IData start, IData end); inline void VL_READMEM_I(bool hex, int width, int depth, int array_lsb, int fnwords, - IData ofilename, void* memp, IData start, IData end) VL_MT_SAFE { - VL_READMEM_Q(hex, width,depth,array_lsb,fnwords, ofilename,memp,start,end); } + IData filename, void* memp, IData start, IData end) VL_MT_SAFE { + VL_READMEM_Q(hex, width,depth,array_lsb,fnwords, filename,memp,start,end); } extern void VL_WRITEMEM_W(bool hex, int width, int depth, int array_lsb, int fnwords, - WDataInP ofilename, const void* memp, IData start, IData end); + WDataInP filenamep, const void* memp, IData start, IData end); extern void VL_WRITEMEM_Q(bool hex, int width, int depth, int array_lsb, int fnwords, - QData ofilename, const void* memp, IData start, IData end); + QData filename, const void* memp, IData start, IData end); inline void VL_WRITEMEM_I(bool hex, int width, int depth, int array_lsb, int fnwords, - IData ofilename, const void* memp, IData start, IData end) VL_MT_SAFE { - VL_WRITEMEM_Q(hex, width,depth,array_lsb,fnwords, ofilename,memp,start,end); } + IData filename, const void* memp, IData start, IData end) VL_MT_SAFE { + VL_WRITEMEM_Q(hex, width,depth,array_lsb,fnwords, filename,memp,start,end); } extern void VL_WRITEF(const char* formatp, ...); extern void VL_FWRITEF(IData fpi, const char* formatp, ...); @@ -621,7 +621,7 @@ extern void VL_SFORMAT_X(int obits, IData& destr, const char* formatp, ...); extern void VL_SFORMAT_X(int obits, QData& destr, const char* formatp, ...); extern void VL_SFORMAT_X(int obits, void* destp, const char* formatp, ...); -extern IData VL_SYSTEM_IW(int lhsnwords, WDataInP lhs); +extern IData VL_SYSTEM_IW(int lhswords, WDataInP lhsp); extern IData VL_SYSTEM_IQ(QData lhs); inline IData VL_SYSTEM_II(IData lhs) VL_MT_SAFE { return VL_SYSTEM_IQ(lhs); } @@ -632,24 +632,24 @@ extern const char* vl_mc_scan_plusargs(const char* prefixp); // PLIish // Base macros /// Return true if data[bit] set; not 0/1 return, but 0/non-zero return. -#define VL_BITISSET_I(data,bit) (data & (VL_UL(1)<> VL_BITBIT_I(bit)) +#define VL_BITRSHIFT_W(data,bit) ((data)[VL_BITWORD_I(bit)] >> VL_BITBIT_I(bit)) /// 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]=static_cast(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_WQ(owp,data) { (owp)[0] = static_cast(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) ) + ( (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); @@ -698,7 +698,7 @@ extern void _VL_DEBUG_PRINT_W(int lbits, WDataInP iwp); // Pli macros #ifndef VL_TIME_PRECISION -# define VL_TIME_PRECISION -12 ///< Timescale units only for for VPI return - picoseconds +# define VL_TIME_PRECISION (-12) ///< Timescale units only for for VPI return - picoseconds #endif #ifndef VL_TIME_MULTIPLIER # define VL_TIME_MULTIPLIER 1 @@ -828,31 +828,32 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) VL_MT_SAF #define VL_ASSIGN_ISI(obits,vvar,svar) { (vvar) = VL_CLEAN_II((obits),(obits),(svar).read()); } #define VL_ASSIGN_QSQ(obits,vvar,svar) { (vvar) = VL_CLEAN_QQ((obits),(obits),(svar).read()); } -#define VL_ASSIGN_ISW(obits,od,svar) { \ - od = (svar.read().get_word(0)) & VL_MASK_I(obits); \ -} -#define VL_ASSIGN_QSW(obits,od,svar) { \ - od = ((static_cast(svar.read().get_word(1)))<((svar).read().get_word(1)))< _butemp = (svar).read(); \ - for (int i=0; i < words; ++i) { \ - int msb = ((i+1)*VL_WORDSIZE) - 1; \ - msb = (msb >= obits) ? (obits-1) : msb; \ - owp[i] = _butemp.range(msb,i*VL_WORDSIZE).to_uint(); \ - } \ - owp[words-1] &= VL_MASK_I(obits); \ -} +#define VL_ASSIGN_WSB(obits,owp,svar) { \ + int words = VL_WORDS_I(obits); \ + sc_biguint<(obits)> _butemp = (svar).read(); \ + for (int i=0; i < words; ++i) { \ + int msb = ((i+1)*VL_WORDSIZE) - 1; \ + msb = (msb >= (obits)) ? ((obits)-1) : msb; \ + (owp)[i] = _butemp.range(msb,i*VL_WORDSIZE).to_uint(); \ + } \ + (owp)[words-1] &= VL_MASK_I(obits); \ + } // Copying verilog format from systemc integers and bit vectors. // Set a SystemC variable @@ -860,36 +861,36 @@ static inline void VL_ASSIGNBIT_WO(int, int bit, WDataOutP owp, IData) VL_MT_SAF #define VL_ASSIGN_SII(obits,svar,vvar) { (svar).write(vvar); } #define VL_ASSIGN_SQQ(obits,svar,vvar) { (svar).write(vvar); } -#define VL_ASSIGN_SWI(obits,svar,rd) { \ - sc_bv _bvtemp; \ - _bvtemp.set_word(0,(rd)); \ - svar.write(_bvtemp); \ -} -#define VL_ASSIGN_SWQ(obits,svar,rd) { \ - sc_bv _bvtemp; \ - _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) { \ - sc_bv _bvtemp; \ - for (int i=0; i < VL_WORDS_I(obits); ++i) _bvtemp.set_word(i,rwp[i]); \ - svar.write(_bvtemp); \ -} +#define VL_ASSIGN_SWI(obits,svar,rd) { \ + sc_bv<(obits)> _bvtemp; \ + _bvtemp.set_word(0, (rd)); \ + (svar).write(_bvtemp); \ + } +#define VL_ASSIGN_SWQ(obits,svar,rd) { \ + sc_bv<(obits)> _bvtemp; \ + _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) { \ + sc_bv<(obits)> _bvtemp; \ + for (int i=0; i < VL_WORDS_I(obits); ++i) _bvtemp.set_word(i, (rwp)[i]); \ + (svar).write(_bvtemp); \ + } #define VL_ASSIGN_SUI(obits,svar,rd) { (svar).write(rd); } #define VL_ASSIGN_SUQ(obits,svar,rd) { (svar).write(rd); } #define VL_ASSIGN_SBI(obits,svar,rd) { (svar).write(rd); } #define VL_ASSIGN_SBQ(obits,svar,rd) { (svar).write(rd); } -#define VL_ASSIGN_SBW(obits,svar,rwp) { \ - sc_biguint _butemp; \ - for (int i=0; i < VL_WORDS_I(obits); ++i) { \ - int msb = ((i+1)*VL_WORDSIZE) - 1; \ - msb = (msb >= obits) ? (obits-1) : msb; \ - _butemp.range(msb,i*VL_WORDSIZE) = rwp[i]; \ - } \ - svar.write(_butemp); \ -} +#define VL_ASSIGN_SBW(obits,svar,rwp) { \ + sc_biguint<(obits)> _butemp; \ + for (int i=0; i < VL_WORDS_I(obits); ++i) { \ + int msb = ((i+1)*VL_WORDSIZE) - 1; \ + msb = (msb >= (obits)) ? ((obits)-1) : msb; \ + _butemp.range(msb, i*VL_WORDSIZE) = (rwp)[i]; \ + } \ + (svar).write(_butemp); \ + } //=================================================================== // Extending sizes @@ -957,8 +958,8 @@ static inline WDataOutP VL_EXTENDS_WW(int obits, int lbits, WDataOutP owp, WData // REDUCTION OPERATORS // EMIT_RULE: VL_REDAND: oclean=clean; lclean==clean; obits=1; -#define VL_REDAND_II(obits,lbits,lhs) (lhs == VL_MASK_I(lbits)) -#define VL_REDAND_IQ(obits,lbits,lhs) (lhs == VL_MASK_Q(lbits)) +#define VL_REDAND_II(obits,lbits,lhs) ((lhs) == VL_MASK_I(lbits)) +#define VL_REDAND_IQ(obits,lbits,lhs) ((lhs) == VL_MASK_Q(lbits)) static inline IData VL_REDAND_IW(int, int lbits, WDataInP lwp) VL_MT_SAFE { int words = VL_WORDS_I(lbits); IData combine=lwp[0]; @@ -968,8 +969,8 @@ static inline IData VL_REDAND_IW(int, int lbits, WDataInP lwp) VL_MT_SAFE { } // EMIT_RULE: VL_REDOR: oclean=clean; lclean==clean; obits=1; -#define VL_REDOR_I(lhs) (lhs!=0) -#define VL_REDOR_Q(lhs) (lhs!=0) +#define VL_REDOR_I(lhs) ((lhs)!=0) +#define VL_REDOR_Q(lhs) ((lhs)!=0) static inline IData VL_REDOR_W(int words, WDataInP lwp) VL_MT_SAFE { IData equal=0; for (int i=0; i < words; ++i) equal |= lwp[i]; diff --git a/include/verilated_cov.cpp b/include/verilated_cov.cpp index bd186f13e..90c83a3ba 100644 --- a/include/verilated_cov.cpp +++ b/include/verilated_cov.cpp @@ -77,7 +77,7 @@ public: virtual void zero() const { *m_countp = 0; } // CONSTRUCTORS // cppcheck-suppress noExplicitConstructor - VerilatedCoverItemSpec(T* countp) : m_countp(countp) { zero(); } + VerilatedCoverItemSpec(T* countp) : m_countp(countp) { *m_countp = 0; } virtual ~VerilatedCoverItemSpec() {} }; @@ -167,8 +167,8 @@ private: // (foo.a.x, foo.b.y) => foo.* // (foo.a.x, foo.b) => foo.* if (old == add) return add; - if (old == "") return add; - if (add == "") return old; + if (old.empty()) return add; + if (add.empty()) return old; const char* a = old.c_str(); const char* b = add.c_str(); @@ -296,7 +296,7 @@ public: } // Ignore empty keys for (int i=0; ifirst; - if (it->second.first != "") os<second.first); + if (!it->second.first.empty()) os<second.first); os<<"' "<second.second; os<(scope); Verilated::dpiScope(vscopep); - return (svScope)prevScopep; + // NOLINTNEXTLINE(google-readability-casting) + return (svScope)(prevScopep); } const char* svGetNameFromScope(const svScope scope) { @@ -737,7 +739,8 @@ const char* svGetNameFromScope(const svScope scope) { } svScope svGetScopeFromName(const char* scopeName) { - return (svScope)VerilatedImp::scopeFind(scopeName); + // NOLINTNEXTLINE(google-readability-casting) + return (svScope)(VerilatedImp::scopeFind(scopeName)); } int svPutUserData(const svScope scope, void* userKey, void* userData) { diff --git a/include/verilated_fst_c.cpp b/include/verilated_fst_c.cpp index 09210af10..b586c4d95 100644 --- a/include/verilated_fst_c.cpp +++ b/include/verilated_fst_c.cpp @@ -107,7 +107,7 @@ void VerilatedFst::declSymbol(vluint32_t code, const char* name, int dtypenum, fstVarDir vardir, fstVarType vartype, int arraynum, vluint32_t len) { std::pair p - = m_code2symbol.insert(std::make_pair(code, (fstHandle)(0))); + = m_code2symbol.insert(std::make_pair(code, static_cast(NULL))); std::istringstream nameiss(name); std::istream_iterator beg(nameiss), end; std::list tokens(beg, end); // Split name diff --git a/include/verilated_fst_c.h b/include/verilated_fst_c.h index 619fb110f..424e2b89a 100644 --- a/include/verilated_fst_c.h +++ b/include/verilated_fst_c.h @@ -77,10 +77,10 @@ public: fstWriterClose(m_fst); m_fst = NULL; } - // void set_time_unit(const char* unit); ///< Set time units (s/ms, defaults to ns) + // void set_time_unit(const char* unitp); ///< Set time units (s/ms, defaults to ns) // void set_time_unit(const std::string& unit) { set_time_unit(unit.c_str()); } - // void set_time_resolution(const char* unit); ///< Set time resolution (s/ms, defaults to ns) + // void set_time_resolution(const char* unitp); ///< Set time resolution (s/ms, defaults to ns) // void set_time_resolution(const std::string& unit) { set_time_resolution(unit.c_str()); } // double timescaleToDouble(const char* unitp); @@ -93,8 +93,8 @@ public: /// Inside dumping routines, called each cycle to make the dump void dump(vluint64_t timeui); /// Inside dumping routines, declare callbacks for tracings - void addCallback(VerilatedFstCallback_t init, VerilatedFstCallback_t full, - VerilatedFstCallback_t change, + void addCallback(VerilatedFstCallback_t initcb, VerilatedFstCallback_t fullcb, + VerilatedFstCallback_t changecb, void* userthis) VL_MT_UNSAFE_ONE; /// Inside dumping routines, declare a module diff --git a/include/verilated_heavy.h b/include/verilated_heavy.h index 77515849f..ec9895e43 100644 --- a/include/verilated_heavy.h +++ b/include/verilated_heavy.h @@ -65,15 +65,15 @@ inline IData VL_LEN_IN(const std::string& ld) { return ld.length(); } extern IData VL_FOPEN_NI(const std::string& filename, IData mode) VL_MT_SAFE; extern void VL_READMEM_N(bool hex, int width, int depth, int array_lsb, - const std::string& ofilename, + const std::string& filename, void* memp, IData start, IData end) VL_MT_SAFE; extern void VL_WRITEMEM_N(bool hex, int width, int depth, int array_lsb, - const std::string& ofilename, + const std::string& filename, const void* memp, IData start, IData end) VL_MT_SAFE; extern IData VL_SSCANF_INX(int lbits, const std::string& ld, const char* formatp, ...) VL_MT_SAFE; extern void VL_SFORMAT_X(int obits_ignored, std::string& output, const char* formatp, ...) VL_MT_SAFE; extern std::string VL_SFORMATF_NX(const char* formatp, ...) VL_MT_SAFE; -extern IData VL_VALUEPLUSARGS_INW(int rbits, const std::string& ld, WDataOutP rdp) VL_MT_SAFE; +extern IData VL_VALUEPLUSARGS_INW(int rbits, const std::string& ld, WDataOutP rwp) VL_MT_SAFE; inline IData VL_VALUEPLUSARGS_INI(int rbits, const std::string& ld, IData& rdr) VL_MT_SAFE { WData rwp[2]; // WData must always be at least 2 IData got = VL_VALUEPLUSARGS_INW(rbits,ld,rwp); diff --git a/include/verilated_lxt2_c.h b/include/verilated_lxt2_c.h index b30414670..709d3a7f2 100644 --- a/include/verilated_lxt2_c.h +++ b/include/verilated_lxt2_c.h @@ -70,10 +70,10 @@ public: lxt2_wr_close(m_lxt2); m_lxt2 = NULL; } - // void set_time_unit(const char* unit); ///< Set time units (s/ms, defaults to ns) + // void set_time_unit(const char* unitp); ///< Set time units (s/ms, defaults to ns) // void set_time_unit(const std::string& unit) { set_time_unit(unit.c_str()); } - // void set_time_resolution(const char* unit); ///< Set time resolution (s/ms, defaults to ns) + // void set_time_resolution(const char* unitp); ///< Set time resolution (s/ms, defaults to ns) // void set_time_resolution(const std::string& unit) { set_time_resolution(unit.c_str()); } // double timescaleToDouble(const char* unitp); @@ -86,8 +86,8 @@ public: /// Inside dumping routines, called each cycle to make the dump void dump(vluint64_t timeui); /// Inside dumping routines, declare callbacks for tracings - void addCallback(VerilatedLxt2Callback_t init, VerilatedLxt2Callback_t full, - VerilatedLxt2Callback_t change, + void addCallback(VerilatedLxt2Callback_t initcb, VerilatedLxt2Callback_t fullcb, + VerilatedLxt2Callback_t changecb, void* userthis) VL_MT_UNSAFE_ONE; /// Inside dumping routines, declare a module diff --git a/include/verilated_save.cpp b/include/verilated_save.cpp index 3768244e4..f884547cb 100644 --- a/include/verilated_save.cpp +++ b/include/verilated_save.cpp @@ -38,6 +38,9 @@ #ifndef O_NONBLOCK # define O_NONBLOCK 0 #endif +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif // CONSTANTS static const char* const VLTSAVE_HEADER_STR = "verilatorsave01\n"; ///< Value of first bytes of each file @@ -50,7 +53,7 @@ static const char* const VLTSAVE_TRAILER_STR = "vltsaved"; ///< Value of last by bool VerilatedDeserialize::readDiffers(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE { bufferCheck(); - const vluint8_t* __restrict dp = (const vluint8_t* __restrict)datap; + const vluint8_t* __restrict dp = static_cast(datap); vluint8_t miss = 0; while (size--) { miss |= (*dp++ ^ *m_cp++); @@ -119,7 +122,7 @@ void VerilatedSave::open(const char* filenamep) VL_MT_UNSAFE_ONE { assert(0); // Not supported yet. } else { // cppcheck-suppress duplicateExpression - m_fd = ::open(filenamep, O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK + m_fd = ::open(filenamep, O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK|O_CLOEXEC , 0666); if (m_fd<0) { // User code can check isOpen() @@ -142,7 +145,7 @@ void VerilatedRestore::open(const char* filenamep) VL_MT_UNSAFE_ONE { assert(0); // Not supported yet. } else { // cppcheck-suppress duplicateExpression - m_fd = ::open(filenamep, O_CREAT|O_RDONLY|O_LARGEFILE + m_fd = ::open(filenamep, O_CREAT|O_RDONLY|O_LARGEFILE|O_CLOEXEC , 0666); if (m_fd<0) { // User code can check isOpen() diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index f872fc547..703a993ea 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -44,6 +44,9 @@ #ifndef O_NONBLOCK # define O_NONBLOCK 0 #endif +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif //============================================================================= // VerilatedVcdImp @@ -109,7 +112,7 @@ protected: // VerilatedVcdFile bool VerilatedVcdFile::open(const std::string& name) VL_MT_UNSAFE { - m_fd = ::open(name.c_str(), O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK, 0666); + m_fd = ::open(name.c_str(), O_CREAT|O_WRONLY|O_TRUNC|O_LARGEFILE|O_NONBLOCK|O_CLOEXEC, 0666); return (m_fd>=0); } @@ -237,7 +240,7 @@ void VerilatedVcd::makeNameMap() { bool nullScope = false; for (NameMap::const_iterator it=m_namemapp->begin(); it!=m_namemapp->end(); ++it) { const std::string& hiername = it->first; - if (hiername.size() >= 1 && hiername[0] == '\t') nullScope=true; + if (!hiername.empty() && hiername[0] == '\t') nullScope=true; } if (nullScope) { NameMap* newmapp = new NameMap; @@ -546,13 +549,15 @@ void VerilatedVcd::declare(vluint32_t code, const char* name, const char* wirep, // Tab sorts before spaces, so signals nicely will print before scopes // Note the hiername may be nothing, if so we'll add "\t{name}" std::string nameasstr = name; - if (m_modName!="") { nameasstr = m_modName+m_scopeEscape+nameasstr; } // Optional ->module prefix + if (!m_modName.empty()) { + nameasstr = m_modName+m_scopeEscape+nameasstr; // Optional ->module prefix + } std::string hiername; std::string basename; for (const char* cp=nameasstr.c_str(); *cp; cp++) { if (isScopeEscape(*cp)) { // Ahh, we've just read a scope, not a basename - if (hiername!="") hiername += " "; + if (!hiername.empty()) hiername += " "; hiername += basename; basename = ""; } else { diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index 428b9220a..780c8e74a 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -121,7 +121,7 @@ private: void openNext(); void makeNameMap(); void deleteNameMap(); - void printIndent(int levelchange); + void printIndent(int level_change); void printStr(const char* str); void printQuad(vluint64_t n); void printTime(vluint64_t timeui); @@ -172,10 +172,10 @@ public: /// Flush any remaining data from all files static void flush_all() VL_MT_UNSAFE_ONE; - void set_time_unit(const char* unit); ///< Set time units (s/ms, defaults to ns) + void set_time_unit(const char* unitp); ///< Set time units (s/ms, defaults to ns) void set_time_unit(const std::string& unit) { set_time_unit(unit.c_str()); } - void set_time_resolution(const char* unit); ///< Set time resolution (s/ms, defaults to ns) + void set_time_resolution(const char* unitp); ///< Set time resolution (s/ms, defaults to ns) void set_time_resolution(const std::string& unit) { set_time_resolution(unit.c_str()); } double timescaleToDouble(const char* unitp); @@ -187,8 +187,8 @@ public: 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, - VerilatedVcdCallback_t change, + void addCallback(VerilatedVcdCallback_t initcb, VerilatedVcdCallback_t fullcb, + VerilatedVcdCallback_t changecb, void* userthis) VL_MT_UNSAFE_ONE; /// Inside dumping routines, declare a module diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index f36405720..992a2943b 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -79,11 +79,10 @@ public: vluint8_t* newp = t_freeHead; t_freeHead = *((vluint8_t**)newp); return newp+8; - } else { - // +8: 8 bytes for next - vluint8_t* newp = reinterpret_cast(::operator new(chunk+8)); - return newp+8; } + // +8: 8 bytes for next + vluint8_t* newp = reinterpret_cast(::operator new(chunk+8)); + return newp+8; } inline static void operator delete(void* obj, size_t size) VL_MT_SAFE { vluint8_t* oldp = ((vluint8_t*)obj)-8; @@ -156,9 +155,8 @@ public: VerilatedVpioRange* nextp = new VerilatedVpioRange(*this); nextp->iterationInc(); return ((nextp)->castVpiHandle()); - } else { - return 0; // End of list - only one deep } + return 0; // End of list - only one deep } }; @@ -275,9 +273,8 @@ public: if (m_it == varsp->end()) return 0; return ((new VerilatedVpioVar(&(m_it->second), m_scopep)) ->castVpiHandle()); - } else { - return 0; // End of list - only one deep } + return 0; // End of list - only one deep } }; @@ -388,9 +385,8 @@ public: VpioTimedCbs::const_iterator it=s_s.m_timedCbs.begin(); if (VL_LIKELY(it!=s_s.m_timedCbs.end())) { return it->first; - } else { - return ~VL_ULL(0); // maxquad } + return ~VL_ULL(0); // maxquad } static void callCbs(vluint32_t reason) { VpioCbList& cbObjList = s_s.m_cbObjLists[reason]; @@ -1037,17 +1033,15 @@ vpiHandle vpi_handle_by_index(vpiHandle object, PLI_INT32 indx) { return (new VerilatedVpioMemoryWord(varop->varp(), varop->scopep(), indx, indx - varop->varp()->unpacked().right())) ->castVpiHandle(); - } else { - if (VL_UNLIKELY(indx < varop->varp()->unpacked().left() - || indx > varop->varp()->unpacked().right())) return 0; - return (new VerilatedVpioMemoryWord(varop->varp(), varop->scopep(), indx, - indx - varop->varp()->unpacked().left())) - ->castVpiHandle(); } - } else { - _VL_VPI_INTERNAL(__FILE__, __LINE__, "%s : can't resolve handle", VL_FUNC); - return 0; + if (VL_UNLIKELY(indx < varop->varp()->unpacked().left() + || indx > varop->varp()->unpacked().right())) return 0; + return (new VerilatedVpioMemoryWord(varop->varp(), varop->scopep(), indx, + indx - varop->varp()->unpacked().left())) + ->castVpiHandle(); } + _VL_VPI_INTERNAL(__FILE__, __LINE__, "%s : can't resolve handle", VL_FUNC); + return 0; } // for traversing relationships diff --git a/include/verilatedos.h b/include/verilatedos.h index f4d1a928c..9c87e3031 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -40,7 +40,7 @@ # ifdef _WIN32 # define VL_ATTR_PRINTF(fmtArgNum) // GCC with MS runtime will fool the print arg checker # else -# define VL_ATTR_PRINTF(fmtArgNum) __attribute__ ((format (printf, fmtArgNum, fmtArgNum+1))) +# define VL_ATTR_PRINTF(fmtArgNum) __attribute__ ((format (printf, (fmtArgNum), (fmtArgNum)+1))) # endif # define VL_ATTR_PURE __attribute__ ((pure)) # define VL_ATTR_UNUSED __attribute__ ((unused)) diff --git a/src/V3Assert.cpp b/src/V3Assert.cpp index 2ea4eeeb1..84287d0f9 100644 --- a/src/V3Assert.cpp +++ b/src/V3Assert.cpp @@ -75,13 +75,14 @@ private: AstNode* newIfAssertOn(AstNode* nodep) { // Add a internal if to check assertions are on. // Don't make this a AND term, as it's unlikely to need to test this. + FileLine* fl = nodep->fileline(); AstNode* newp - = new AstIf(nodep->fileline(), + = new AstIf(fl, // If assertions are off, have constant propagation rip them out later // This allows syntax errors and such to be detected normally. (v3Global.opt.assertOn() - ? (AstNode*)(new AstCMath(nodep->fileline(), "Verilated::assertOn()", 1)) - : (AstNode*)(new AstConst(nodep->fileline(), AstConst::LogicFalse()))), + ? static_cast(new AstCMath(fl, "Verilated::assertOn()", 1)) + : static_cast(new AstConst(fl, AstConst::LogicFalse()))), nodep, NULL); newp->user1(true); // Don't assert/cover this if return newp; diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 48201d22a..de6a4ca32 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -419,8 +419,8 @@ void AstNode::replaceWith(AstNode* newp) { } void AstNRelinker::dump(std::ostream& str) const { - str<<" BK="<<(uint32_t*)m_backp; - str<<" ITER="<<(uint32_t*)m_iterpp; + str<<" BK="<(m_backp); + str<<" ITER="<(m_iterpp); str<<" CHG="<<(m_chg==RELINK_NEXT?"[NEXT] ":""); str<<(m_chg==RELINK_OP1?"[OP1] ":""); str<<(m_chg==RELINK_OP2?"[OP2] ":""); @@ -670,13 +670,13 @@ void AstNode::deleteNode() { UASSERT(!m_backp, "Delete called on node with backlink still set"); editCountInc(); // Change links of old node so we coredump if used - this->m_nextp = (AstNode*)1; - this->m_backp = (AstNode*)1; - this->m_headtailp = (AstNode*)1; - this->m_op1p = (AstNode*)1; - this->m_op2p = (AstNode*)1; - this->m_op3p = (AstNode*)1; - this->m_op4p = (AstNode*)1; + this->m_nextp = reinterpret_cast(0x1); + this->m_backp = reinterpret_cast(0x1); + this->m_headtailp = reinterpret_cast(0x1); + this->m_op1p = reinterpret_cast(0x1); + this->m_op2p = reinterpret_cast(0x1); + this->m_op3p = reinterpret_cast(0x1); + this->m_op4p = reinterpret_cast(0x1); if ( #if !defined(VL_DEBUG) || defined(VL_LEAK_CHECKS) 1 @@ -1077,7 +1077,9 @@ void AstNode::v3errorEnd(std::ostringstream& str) const { nsstr<dump(nsstr); nsstr<(this)->dump(nsstr); + nsstr<v3errorEnd(nsstr); } diff --git a/src/V3Ast.h b/src/V3Ast.h index 084d20875..822103f08 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -1027,7 +1027,7 @@ std::ostream& operator<<(std::ostream& os, const V3Hash& rhs); // Prefetch a node. // The if() makes it faster, even though prefetch won't fault on null pointers #define ASTNODE_PREFETCH(nodep) \ - { if (nodep) { VL_PREFETCH_RD(&(nodep->m_nextp)); VL_PREFETCH_RD(&(nodep->m_iterpp)); }} + { if (nodep) { VL_PREFETCH_RD(&((nodep)->m_nextp)); VL_PREFETCH_RD(&((nodep)->m_iterpp)); }} class AstNode { // v ASTNODE_PREFETCH depends on below ordering of members @@ -1171,8 +1171,8 @@ public: static string dedotName(const string& namein); // Name with dots removed static string prettyName(const string& namein); // Name for printing out to the user static string encodeName(const string& namein); // Encode user name into internal C representation - static string encodeNumber(vlsint64_t numin); // Encode number into internal C representation - static string vcdName(const string& namein); // Name for printing out to vcd files + static string encodeNumber(vlsint64_t num); // Encode number into internal C representation + static string vcdName(const string& namein); // Name for printing out to vcd files string prettyName() const { return prettyName(name()); } string prettyTypeName() const; // "VARREF" for error messages virtual string prettyOperatorName() const { return "operator "+prettyTypeName(); } @@ -1347,13 +1347,13 @@ public: void checkTree(); // User Interface version void checkIter() const; void clearIter() { m_iterpp=NULL; } - void dumpPtrs(std::ostream& str=std::cout) const; - void dumpTree(std::ostream& str=std::cout, const string& indent=" ", int maxDepth=0); - void dumpTree(const string& indent, int maxDepth=0) { dumpTree(cout,indent,maxDepth); } - void dumpTreeGdb(); // For GDB only - void dumpTreeAndNext(std::ostream& str=std::cout, const string& indent=" ", int maxDepth=0); - void dumpTreeFile(const string& filename, bool append=false, bool doDump=true); - static void dumpTreeFileGdb(const char* filenamep=NULL); + void dumpPtrs(std::ostream& os=std::cout) const; + void dumpTree(std::ostream& os=std::cout, const string& indent=" ", int maxDepth=0); + void dumpTree(const string& indent, int maxDepth=0) { dumpTree(cout,indent,maxDepth); } + void dumpTreeGdb(); // For GDB only + void dumpTreeAndNext(std::ostream& os=std::cout, const string& indent=" ", int maxDepth=0); + void dumpTreeFile(const string& filename, bool append=false, bool doDump=true); + static void dumpTreeFileGdb(const char* filenamep=NULL); // METHODS - queries virtual bool isPure() const { return true; } // Else a $display, etc, that must be ordered with other displays @@ -1798,7 +1798,7 @@ public: bool widthSized() const { return !m_widthMin || m_widthMin==m_width; } bool generic() const { return m_generic; } void generic(bool flag) { m_generic = flag; } - AstNodeDType* dtypeDimensionp(int depth); + AstNodeDType* dtypeDimensionp(int dimension); std::pair dimensions(bool includeBasic); uint32_t arrayUnpackedElements(); // 1, or total multiplication of all dimensions static int uniqueNumInc() { return ++s_uniqueNum; } diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index c8065a0f8..e74dd2e5a 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -577,7 +577,9 @@ const char* AstScope::broken() const { void AstScope::cloneRelink() { if (m_aboveScopep && m_aboveScopep->clonep()) m_aboveScopep->clonep(); if (m_aboveCellp && m_aboveCellp->clonep()) m_aboveCellp->clonep(); - if (m_modp && ((AstNode*)m_modp)->clonep()) ((AstNode*)m_modp)->clonep(); + if (m_modp && static_cast(m_modp)->clonep()) { + static_cast(m_modp)->clonep(); + } } string AstScope::nameDotless() const { @@ -651,7 +653,7 @@ bool AstSenTree::hasCombo() const { void AstTypeTable::clearCache() { // When we mass-change widthMin in V3WidthCommit, we need to correct the table. // Just clear out the maps; the search functions will be used to rebuild the map - for (int i=0; i<(int)(AstBasicDTypeKwd::_ENUM_MAX); ++i) { + for (int i=0; i < static_cast(AstBasicDTypeKwd::_ENUM_MAX); ++i) { m_basicps[i] = NULL; } for (int isbit=0; isbit<_IDX0_MAX; ++isbit) { @@ -701,7 +703,7 @@ AstBasicDType* AstTypeTable::findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kw else if (kwd == AstBasicDTypeKwd::BIT) idx = IDX0_BIT; else fl->v3fatalSrc("Bad kwd for findLogicBitDType"); std::pair widths = make_pair(width,widthMin); - LogicMap& mapr = m_logicMap[idx][(int)numeric]; + LogicMap& mapr = m_logicMap[idx][static_cast(numeric)]; LogicMap::const_iterator it = mapr.find(widths); if (it != mapr.end()) return it->second; // @@ -991,7 +993,7 @@ void AstMTaskBody::dump(std::ostream& str) { } void AstTypeTable::dump(std::ostream& str) { this->AstNode::dump(str); - for (int i=0; i<(int)(AstBasicDTypeKwd::_ENUM_MAX); ++i) { + for (int i=0; i < static_cast(AstBasicDTypeKwd::_ENUM_MAX); ++i) { if (AstBasicDType* subnodep=m_basicps[i]) { str<=9) cout<<"-nodeDel: "<second & FLAG_ALLOCATED)) { - ((AstNode*)(nodep))->v3fatalSrc("Deleting AstNode object that was never tracked or already deleted"); + reinterpret_cast(nodep) + ->v3fatalSrc("Deleting AstNode object that was never tracked or already deleted"); } if (iter!=s_nodes.end()) s_nodes.erase(iter); } @@ -155,7 +156,9 @@ public: // may be varp() and other cross links that are bad. if (v3Global.opt.debugCheck()) { std::cerr<<"%Error: LeakedNode"<<(it->first->backp()?"Back: ":": "); - ((AstNode*)(it->first))->AstNode::dump(std::cerr); + AstNode* rawp = const_cast + (static_cast(it->first)); + rawp->AstNode::dump(std::cerr); std::cerr<(width); } }; @@ -248,7 +248,7 @@ private: } CdcVarVertex* makeVarVertex(AstVarScope* varscp) { - CdcVarVertex* vertexp = (CdcVarVertex*)(varscp->user1p()); + CdcVarVertex* vertexp = reinterpret_cast(varscp->user1p()); if (!vertexp) { UINFO(6,"New vertex "<varScp()->varp()->isPrimaryIn()) { // Show the source "input" statement if it exists for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) { - CdcEitherVertex* eFromVertexp = (CdcEitherVertex*)edgep->fromp(); + CdcEitherVertex* eFromVertexp = static_cast(edgep->fromp()); eFromVertexp->asyncPath(true); } return NULL; @@ -384,7 +384,7 @@ private: // Also ok if from flop, but partially trace the flop so more obvious to users if (vvertexp->fromFlop()) { for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) { - CdcEitherVertex* eFromVertexp = (CdcEitherVertex*)edgep->fromp(); + CdcEitherVertex* eFromVertexp = static_cast(edgep->fromp()); eFromVertexp->asyncPath(true); } return NULL; @@ -392,7 +392,7 @@ private: } for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) { - CdcEitherVertex* eFromVertexp = (CdcEitherVertex*)edgep->fromp(); + CdcEitherVertex* eFromVertexp = static_cast(edgep->fromp()); CdcEitherVertex* submarkp = traceAsyncRecurse(eFromVertexp, mark); if (submarkp && !mark_outp) mark_outp = submarkp; } @@ -407,7 +407,7 @@ private: *m_ofp<<"\n"; CdcEitherVertex* targetp = vertexp; // One example destination flop (of possibly many) for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) { - CdcEitherVertex* eToVertexp = (CdcEitherVertex*)edgep->top(); + CdcEitherVertex* eToVertexp = static_cast(edgep->top()); if (!eToVertexp) targetp = eToVertexp; if (CdcLogicVertex* vvertexp = dynamic_cast(eToVertexp)) { if (vvertexp->isFlop() // IE the target flop that is upsetting us @@ -434,7 +434,7 @@ private: string cont = prefix+sep; string nextsep = " "; for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) { - CdcEitherVertex* eFromVertexp = (CdcEitherVertex*)edgep->fromp(); + CdcEitherVertex* eFromVertexp = static_cast(edgep->fromp()); if (dumpAsyncRecurse(eFromVertexp, cont, nextsep, level+1)) { nextsep = " | "; } @@ -553,13 +553,13 @@ private: // Now combine domains of sources/dests if (traceDests) { for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) { - CdcEitherVertex* eToVertexp = (CdcEitherVertex*)edgep->top(); + CdcEitherVertex* eToVertexp = static_cast(edgep->top()); edgeDomainRecurse(eToVertexp, traceDests, level+1); if (eToVertexp->dstDomainp()) senouts.insert(eToVertexp->dstDomainp()); } } else { for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) { - CdcEitherVertex* eFromVertexp = (CdcEitherVertex*)edgep->fromp(); + CdcEitherVertex* eFromVertexp = static_cast(edgep->fromp()); edgeDomainRecurse(eFromVertexp, traceDests, level+1); if (eFromVertexp->srcDomainp()) senouts.insert(eFromVertexp->srcDomainp()); } diff --git a/src/V3Clean.cpp b/src/V3Clean.cpp index 8770fe20c..f6f06917e 100644 --- a/src/V3Clean.cpp +++ b/src/V3Clean.cpp @@ -98,7 +98,7 @@ private: nodep->user1(clean); } CleanState getCleanState(AstNode* nodep) { - return ((CleanState)nodep->user1()); + return static_cast(nodep->user1()); } bool isClean(AstNode* nodep) { CleanState clstate = getCleanState(nodep); diff --git a/src/V3ClkGater.cpp b/src/V3ClkGater.cpp index d9d8b7063..1fcf2fc0b 100644 --- a/src/V3ClkGater.cpp +++ b/src/V3ClkGater.cpp @@ -376,7 +376,7 @@ class GaterVisitor : public GaterBaseVisitor { m_pliVertexp = new GaterPliVertex(&m_graph); } if (m_stmtVscp) { // Already saw a variable, be sure to mark it! - GaterVarVertex* varVtxp = (GaterVarVertex*)(m_stmtVscp->user1p()); + GaterVarVertex* varVtxp = reinterpret_cast(m_stmtVscp->user1p()); new GaterEdge(&m_graph, m_pliVertexp, varVtxp, VU_PLI); } m_stmtInPli = true; // Mark all followon variables too @@ -689,9 +689,9 @@ class GaterVisitor : public GaterBaseVisitor { nodep->addNextHere(alwp); // Blow moved statements from old body - GaterBodyVisitor(nodep,exprp,true); + { GaterBodyVisitor vis(nodep,exprp,true); } // Blow old statements from new body - GaterBodyVisitor(alwp,exprp,false); + { GaterBodyVisitor vis(alwp,exprp,false); } ++m_statGaters; if (debug()>=9) alwp->dumpTree(cout," new: "); @@ -764,7 +764,7 @@ class GaterVisitor : public GaterBaseVisitor { } m_stmtVscp = vscp; // Find, or make new Vertex - GaterVarVertex* vertexp = (GaterVarVertex*)(vscp->user1p()); + GaterVarVertex* vertexp = reinterpret_cast(vscp->user1p()); if (!vertexp) { vertexp = new GaterVarVertex(&m_graph, vscp); vscp->user1p(vertexp); diff --git a/src/V3Clock.cpp b/src/V3Clock.cpp index 0e164a1d6..bfb369af1 100644 --- a/src/V3Clock.cpp +++ b/src/V3Clock.cpp @@ -71,7 +71,7 @@ private: VL_DEBUG_FUNC; // Declare debug() AstVarScope* getCreateLastClk(AstVarScope* vscp) { - if (vscp->user1p()) return ((AstVarScope*)vscp->user1p()); + if (vscp->user1p()) return static_cast(vscp->user1p()); AstVar* varp = vscp->varp(); if (!varp->width1()) varp->v3error("Unsupported: Clock edge on non-single bit signal: "<prettyName()); string newvarname = (string("__Vclklast__")+vscp->scopep()->nameDotless()+"__"+varp->name()); diff --git a/src/V3Combine.cpp b/src/V3Combine.cpp index 0a0e82ef5..be2020187 100644 --- a/src/V3Combine.cpp +++ b/src/V3Combine.cpp @@ -69,7 +69,7 @@ protected: // Also repair it for DPI functions; when make __common need to insure proper // flags get inherited from the old to new AstCFunc, and that AstText doesn't // get split between functions causing the text to have a danginling reference. - bool statementCombine() { return false && duplicateFunctionCombine(); } + bool statementCombine() { return false; } // duplicateFunctionCombine(); }; //###################################################################### diff --git a/src/V3Const.cpp b/src/V3Const.cpp index a96b0cbb7..b288bd916 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -242,13 +242,15 @@ private: bool operandHugeShiftL(const AstNodeBiop* nodep) { return (VN_IS(nodep->rhsp(), Const) && !VN_CAST_CONST(nodep->rhsp(), Const)->num().isFourState() - && VN_CAST_CONST(nodep->rhsp(), Const)->toUInt() >= (uint32_t)(nodep->width()) + && (VN_CAST_CONST(nodep->rhsp(), Const)->toUInt() + >= static_cast(nodep->width())) && isTPure(nodep->lhsp())); } bool operandHugeShiftR(const AstNodeBiop* nodep) { return (VN_IS(nodep->rhsp(), Const) && !VN_CAST_CONST(nodep->rhsp(), Const)->num().isFourState() - && VN_CAST_CONST(nodep->rhsp(), Const)->toUInt() >= (uint32_t)(nodep->lhsp()->width()) + && (VN_CAST_CONST(nodep->rhsp(), Const)->toUInt() + >= static_cast(nodep->lhsp()->width())) && isTPure(nodep->lhsp())); } bool operandIsTwo(const AstNode* nodep) { @@ -294,14 +296,14 @@ private: return (VN_IS(nodep->rhsp(), Const) && VN_IS(nodep->fromp(), NodeVarRef) && !VN_CAST_CONST(nodep->fromp(), NodeVarRef)->lvalue() - && ((int)(VN_CAST_CONST(nodep->rhsp(), Const)->toUInt()) + && (static_cast(VN_CAST_CONST(nodep->rhsp(), Const)->toUInt()) >= VN_CAST(nodep->fromp(), NodeVarRef)->varp()->widthWords())); } bool operandSelFull(const AstSel* nodep) { return (VN_IS(nodep->lsbp(), Const) && VN_IS(nodep->widthp(), Const) && nodep->lsbConst()==0 - && (int)nodep->widthConst()==nodep->fromp()->width()); + && static_cast(nodep->widthConst()) == nodep->fromp()->width()); } bool operandSelExtend(AstSel* nodep) { // A pattern created by []'s after offsets have been removed @@ -313,7 +315,7 @@ private: && VN_IS(nodep->lsbp(), Const) && VN_IS(nodep->widthp(), Const) && nodep->lsbConst()==0 - && (int)nodep->widthConst()==extendp->lhsp()->width() + && static_cast(nodep->widthConst()) == extendp->lhsp()->width() )) return false; replaceWChild(nodep, extendp->lhsp()); VL_DANGLING(nodep); return true; @@ -512,8 +514,7 @@ private: const AstConst* rwidth = VN_CAST_CONST(rhsp->widthp(), Const); if (!lstart || !rstart || !lwidth || !rwidth) return false; // too complicated int rend = (rstart->toSInt() + rwidth->toSInt()); - if (rend == lstart->toSInt()) return true; - return false; + return (rend == lstart->toSInt()); } bool ifMergeAdjacent(AstNode* lhsp, AstNode* rhsp) { // called by concatmergeable to determine if {lhsp, rhsp} make sense @@ -1184,7 +1185,8 @@ private: if (!VN_IS(VN_CAST_CONST(nodep, And)->rhsp(), ShiftR)) return false; const AstShiftR* shiftp = VN_CAST(VN_CAST_CONST(nodep, And)->rhsp(), ShiftR); if (!VN_IS(shiftp->rhsp(), Const)) return false; - if ((uint32_t)(nodep->width()) <= VN_CAST_CONST(shiftp->rhsp(), Const)->toUInt()) return false; + if (static_cast(nodep->width()) + <= VN_CAST_CONST(shiftp->rhsp(), Const)->toUInt()) return false; return true; } void replaceBoolShift(AstNode* nodep) { @@ -1366,7 +1368,7 @@ private: AstConcat* conp = VN_CAST(nodep->fromp(), Concat); AstNode* conLhsp = conp->lhsp(); AstNode* conRhsp = conp->rhsp(); - if ((int)nodep->lsbConst() >= conRhsp->width()) { + if (static_cast(nodep->lsbConst()) >= conRhsp->width()) { conLhsp->unlinkFrBack(); AstSel* newp = new AstSel(nodep->fileline(), conLhsp, @@ -1374,7 +1376,7 @@ private: nodep->widthConst()); nodep->replaceWith(newp); } - else if ((int)nodep->msbConst() < conRhsp->width()) { + else if (static_cast(nodep->msbConst()) < conRhsp->width()) { conRhsp->unlinkFrBack(); AstSel* newp = new AstSel(nodep->fileline(), conRhsp, diff --git a/src/V3Coverage.cpp b/src/V3Coverage.cpp index 5a6087fdc..ce8e47113 100644 --- a/src/V3Coverage.cpp +++ b/src/V3Coverage.cpp @@ -180,9 +180,7 @@ private: } } - void toggleVarBottom(AstNodeDType* dtypep, int depth, // per-iteration - const ToggleEnt& above, - AstVar* varp, AstVar* chgVarp) { // Constant + void toggleVarBottom(const ToggleEnt& above, const AstVar* varp) { AstCoverToggle* newp = new AstCoverToggle(varp->fileline(), newCoverInc(varp->fileline(), "", "v_toggle", @@ -202,15 +200,11 @@ private: ToggleEnt newent (above.m_comment+string("[")+cvtToStr(index_docs)+"]", new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true), index_code, 1), new AstSel(varp->fileline(), above.m_chgRefp->cloneTree(true), index_code, 1)); - toggleVarBottom(dtypep, depth+1, - newent, - varp, chgVarp); + toggleVarBottom(newent, varp); newent.cleanup(); } } else { - toggleVarBottom(dtypep, depth+1, - above, - varp, chgVarp); + toggleVarBottom(above, varp); } } else if (AstUnpackArrayDType* adtypep = VN_CAST(dtypep, UnpackArrayDType)) { diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index aaebac535..2c31e1998 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -585,8 +585,8 @@ public: } virtual void visit(AstReplicate* nodep) { if (nodep->lhsp()->widthMin() == 1 && !nodep->isWide()) { - if (((int)VN_CAST(nodep->rhsp(), Const)->toUInt() - * nodep->lhsp()->widthMin()) != nodep->widthMin()) + if ((static_cast(VN_CAST(nodep->rhsp(), Const)->toUInt()) + * nodep->lhsp()->widthMin()) != nodep->widthMin()) nodep->v3fatalSrc("Replicate non-constant or width miscomputed"); puts("VL_REPLICATE_"); emitIQW(nodep); @@ -687,7 +687,9 @@ public: } for (int word=VL_WORDS_I(upWidth)-1; word>=0; word--) { // Only 32 bits - llx + long long here just to appease CPP format warning - ofp()->printf(",0x%08" VL_PRI64 "x", (vluint64_t)(nodep->num().dataWord(word+chunks*EMITC_NUM_CONSTW))); + ofp()->printf(",0x%08" VL_PRI64 "x", + static_cast(nodep->num().dataWord + (word+chunks*EMITC_NUM_CONSTW))); } puts(")"); } @@ -708,7 +710,9 @@ public: } for (int word=EMITC_NUM_CONSTW-1; word>=0; word--) { // Only 32 bits - llx + long long here just to appease CPP format warning - ofp()->printf(",0x%08" VL_PRI64 "x", (vluint64_t)(nodep->num().dataWord(word+chunks*EMITC_NUM_CONSTW))); + ofp()->printf(",0x%08" VL_PRI64 "x", + static_cast(nodep->num().dataWord + (word+chunks*EMITC_NUM_CONSTW))); } puts(")"); } @@ -730,7 +734,7 @@ public: uint32_t num = nodep->toUInt(); // Only 32 bits - llx + long long here just to appease CPP format warning if (num<10) puts(cvtToStr(num)); - else ofp()->printf("0x%" VL_PRI64 "x", (vluint64_t)num); + else ofp()->printf("0x%" VL_PRI64 "x", static_cast(num)); // If signed, we'll do our own functions // But must be here, or <= comparisons etc may end up signed puts("U"); @@ -1164,7 +1168,7 @@ class EmitCImp : EmitCStmts { // METHODS // Low level - void emitVarReset(AstVar* modp); + void emitVarReset(AstVar* varp); void emitCellCtors(AstNodeModule* modp); void emitSensitives(); // Medium level @@ -1336,7 +1340,7 @@ void EmitCStmts::emitOpName(AstNode* nodep, const string& format, // , Commas suppressed if the previous field is suppressed string nextComma; bool needComma = false; -#define COMMA { if (nextComma!="") { puts(nextComma); nextComma=""; } } +#define COMMA { if (!nextComma.empty()) { puts(nextComma); nextComma=""; } } putbs(""); for (string::const_iterator pos = format.begin(); pos != format.end(); ++pos) { @@ -1675,7 +1679,8 @@ void EmitCImp::emitVarReset(AstVar* varp) { } bool zeroit = (varp->attrFileDescr() // Zero it out, so we don't core dump if never call $fopen || (varp->basicp() && varp->basicp()->isZeroInit()) - || (varp->name().size()>=1 && varp->name()[0]=='_' && v3Global.opt.underlineZero()) + || (v3Global.opt.underlineZero() + && !varp->name().empty() && varp->name()[0]=='_') || (v3Global.opt.xInitial() == "fast" || v3Global.opt.xInitial() == "0")); if (varp->isWide()) { // DOCUMENT: We randomize everything. If the user wants a _var to be zero, @@ -1877,7 +1882,7 @@ void EmitCImp::emitSavableImp(AstNodeModule* modp) { } } ofp()->printf( "vluint64_t __Vcheckval = VL_ULL(0x%" VL_PRI64 "x);\n", - (vluint64_t)hash.digestUInt64()); + static_cast(hash.digestUInt64())); if (de) { puts("os.readAssert(__Vcheckval);\n"); } else { diff --git a/src/V3EmitV.cpp b/src/V3EmitV.cpp index 4f74619c2..ca3b5ac68 100644 --- a/src/V3EmitV.cpp +++ b/src/V3EmitV.cpp @@ -550,9 +550,9 @@ class EmitVBaseVisitor : public EmitCBaseVisitor { } // Terminals virtual void visit(AstVarRef* nodep) { - if (nodep->varScopep()) + if (nodep->varScopep()) { putfs(nodep,nodep->varScopep()->prettyName()); - else { + } else { putfs(nodep,nodep->hiername()); puts(nodep->varp()->prettyName()); } diff --git a/src/V3EmitV.h b/src/V3EmitV.h index c22ceb30a..77fac73d3 100644 --- a/src/V3EmitV.h +++ b/src/V3EmitV.h @@ -34,7 +34,7 @@ public: static void emitv(); static void verilogForTree(AstNode* nodep, std::ostream& os=std::cout); static void verilogPrefixedTree(AstNode* nodep, std::ostream& os, const string& prefix, int flWidth, - AstSenTree* domainp, bool user3percent); + AstSenTree* domainp, bool user3mark); }; #endif // Guard diff --git a/src/V3EmitXml.cpp b/src/V3EmitXml.cpp index d8cf1caa8..3e4129a40 100644 --- a/src/V3EmitXml.cpp +++ b/src/V3EmitXml.cpp @@ -115,11 +115,11 @@ class EmitXmlFileVisitor : public AstNVisitor { virtual void visit(AstPin* nodep) { // What we call a pin in verilator is a port in the IEEE spec. outputTag(nodep, "port"); // IEEE: vpiPort - if (nodep->modVarp()->isInOnly()) + if (nodep->modVarp()->isInOnly()) { puts(" direction=\"in\""); - else if (nodep->modVarp()->isOutOnly()) + } else if (nodep->modVarp()->isOutOnly()) { puts(" direction=\"out\""); - else puts(" direction=\"inout\""); + } else puts(" direction=\"inout\""); puts(" portIndex=\""+cvtToStr(nodep->pinNum())+"\""); // IEEE: vpiPortIndex // Children includes vpiHighConn and vpiLowConn; we don't support port bits (yet?) outputChildrenEnd(nodep, "port"); diff --git a/src/V3Error.cpp b/src/V3Error.cpp index e11e79f2c..f67c75e5d 100644 --- a/src/V3Error.cpp +++ b/src/V3Error.cpp @@ -56,7 +56,7 @@ v3errorIniter v3errorInit; V3ErrorCode::V3ErrorCode(const char* msgp) { // Return error encoding for given string, or ERROR, which is a bad code for (int codei=V3ErrorCode::EC_MIN; codeiuser1SetOnce()) return; // Process once iterateChildren(nodep); // Remember, Sel's may have non-integer rhs, so need to optimize for that! - if (nodep->widthMin()!=(int)nodep->widthConst()) nodep->v3fatalSrc("Width mismatch"); + if (nodep->widthMin() != nodep->widthConst()) nodep->v3fatalSrc("Width mismatch"); if (VN_IS(nodep->backp(), NodeAssign) && nodep==VN_CAST(nodep->backp(), NodeAssign)->lhsp()) { // Sel is an LHS assignment select } else if (nodep->isWide()) { @@ -456,7 +456,7 @@ private: } bool expandWide(AstNodeAssign* nodep, AstSel* rhsp) { - if (nodep->widthMin()!=(int)rhsp->widthConst()) nodep->v3fatalSrc("Width mismatch"); + if (nodep->widthMin() != rhsp->widthConst()) nodep->v3fatalSrc("Width mismatch"); if (VN_IS(rhsp->lsbp(), Const) && VL_BITBIT_I(rhsp->lsbConst())==0) { int lsb = rhsp->lsbConst(); UINFO(8," Wordize ASSIGN(SEL,align) "<fileline(), - new AstConst(lhsp->fileline(), maskold.dataWord(w)), - oldvalp); + if (!ones) { + oldvalp = new AstAnd(lhsp->fileline(), + new AstConst(lhsp->fileline(), + maskold.dataWord(w)), + oldvalp); + } addWordAssign(nodep, w, destp, new AstOr(lhsp->fileline(), @@ -542,12 +545,16 @@ private: destp->deleteTree(); VL_DANGLING(destp); } else { UINFO(8," ASSIGNSEL(const,narrow) "<isQuad() && !rhsp->isQuad()) rhsp = new AstCCast(nodep->fileline(), rhsp, nodep); + if (destp->isQuad() && !rhsp->isQuad()) { + rhsp = new AstCCast(nodep->fileline(), rhsp, nodep); + } AstNode* oldvalp = destp->cloneTree(true); fixCloneLvalue(oldvalp); - if (!ones) oldvalp = new AstAnd(lhsp->fileline(), - new AstConst(lhsp->fileline(), maskold), - oldvalp); + if (!ones) { + oldvalp = new AstAnd(lhsp->fileline(), + new AstConst(lhsp->fileline(), maskold), + oldvalp); + } AstNode* newp = new AstOr(lhsp->fileline(), oldvalp, @@ -569,7 +576,7 @@ private: destp->cloneTree(true), newSelBitWord(lhsp->lsbp(), 0)); fixCloneLvalue(oldvalp); - if (!ones) + if (!ones) { oldvalp = new AstAnd(lhsp->fileline(), new AstNot(lhsp->fileline(), new AstShiftL(lhsp->fileline(), @@ -580,7 +587,7 @@ private: newSelBitBit(lhsp->lsbp()), VL_WORDSIZE)), oldvalp); - + } // Restrict the shift amount to 0-31, see bug804. AstNode* shiftp = new AstAnd(nodep->fileline(), lhsp->lsbp()->cloneTree(true), new AstConst(nodep->fileline(), VL_WORDSIZE-1)); @@ -618,10 +625,10 @@ private: fixCloneLvalue(oldvalp); V3Number maskwidth (nodep->fileline(), destp->widthMin()); - for (int bit=0; bit<(int)lhsp->widthConst(); bit++) maskwidth.setBit(bit,1); + for (int bit=0; bit < lhsp->widthConst(); bit++) maskwidth.setBit(bit,1); if (destp->isQuad() && !rhsp->isQuad()) rhsp = new AstCCast(nodep->fileline(), rhsp, nodep); - if (!ones) + if (!ones) { oldvalp = new AstAnd(lhsp->fileline(), new AstNot(lhsp->fileline(), new AstShiftL(lhsp->fileline(), @@ -630,6 +637,7 @@ private: lhsp->lsbp()->cloneTree(true), destp->width())), oldvalp); + } AstNode* newp = new AstOr(lhsp->fileline(), oldvalp, diff --git a/src/V3File.cpp b/src/V3File.cpp index d4baf5436..41c130002 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -54,8 +54,8 @@ // If change this code, run a test with the below size set very small //#define INFILTER_IPC_BUFSIZ 16 -#define INFILTER_IPC_BUFSIZ 64*1024 // For debug, try this as a small number -#define INFILTER_CACHE_MAX 64*1024 // Maximum bytes to cache if same file read twice +#define INFILTER_IPC_BUFSIZ (64*1024) // For debug, try this as a small number +#define INFILTER_CACHE_MAX (64*1024) // Maximum bytes to cache if same file read twice //###################################################################### // V3File Internal state @@ -124,8 +124,8 @@ public: } } void writeDepend(const string& filename); - void writeTimes(const string& filename, const string& cmdline); - bool checkTimes(const string& filename, const string& cmdline); + void writeTimes(const string& filename, const string& cmdlineIn); + bool checkTimes(const string& filename, const string& cmdlineIn); }; V3FileDependImp dependImp; // Depend implementation class @@ -180,7 +180,7 @@ inline void V3FileDependImp::writeTimes(const string& filename, const string& cm for (std::set::iterator iter=m_filenameList.begin(); iter!=m_filenameList.end(); ++iter) { // Read stats of files we create after we're done making them (execpt for this file, of course) - DependFile* dfp = (DependFile*)&(*iter); + DependFile* dfp = const_cast(&(*iter)); V3Options::fileNfsFlush(dfp->filename()); dfp->loadStats(); off_t showSize = iter->size(); @@ -232,6 +232,7 @@ inline bool V3FileDependImp::checkTimes(const string& filename, const string& cm string chkFilename; getline(*ifp, chkFilename, '"'); V3Options::fileNfsFlush(chkFilename); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) struct stat chkStat; int err = stat(chkFilename.c_str(), &chkStat); if (err!=0) { @@ -280,11 +281,11 @@ void V3File::addTgtDepend(const string& filename) { void V3File::writeDepend(const string& filename) { dependImp.writeDepend(filename); } -void V3File::writeTimes(const string& filename, const string& cmdline) { - dependImp.writeTimes(filename, cmdline); +void V3File::writeTimes(const string& filename, const string& cmdlineIn) { + dependImp.writeTimes(filename, cmdlineIn); } -bool V3File::checkTimes(const string& filename, const string& cmdline) { - return dependImp.checkTimes(filename, cmdline); +bool V3File::checkTimes(const string& filename, const string& cmdlineIn) { + return dependImp.checkTimes(filename, cmdlineIn); } void V3File::createMakeDir() { @@ -463,7 +464,7 @@ private: dup2(fd_stdout[P_WR], 1); // And stderr comes from parent - execl("/bin/sh", "sh", "-c", command.c_str(), (char*)NULL); + execl("/bin/sh", "sh", "-c", command.c_str(), static_cast(NULL)); // Don't use v3fatal, we don't share the common structures any more fprintf(stderr,"--pipe-filter: exec failed: %s\n",strerror(errno)); _exit(10); @@ -858,7 +859,7 @@ void V3OutFormatter::printf(const char *fmt...) { V3OutFile::V3OutFile(const string& filename, V3OutFormatter::Language lang) : V3OutFormatter(filename, lang) { - if ((m_fp = V3File::new_fopen_w(filename.c_str())) == NULL) { + if ((m_fp = V3File::new_fopen_w(filename)) == NULL) { v3fatal("Cannot write "< 64 bit number char out[size]; char* op = out+size-1; *--op = '\0'; // We build backwards - int num = no; + int num = fileno; do { - *--op = 'a'+num%26; - num /= 26; + *--op = 'a'+num%26; + num /= 26; } while (num); return op; } @@ -90,8 +90,8 @@ FileLine::FileLine(FileLine::EmptySecret) { m_warnOn=0; for (int codei=V3ErrorCode::EC_MIN; codeiwarnIsOff(code)) { - warnOff(code, true); - } + V3ErrorCode code = V3ErrorCode(codei); + if (fromp->warnIsOff(code)) { warnOff(code, true); } } } diff --git a/src/V3FileLine.h b/src/V3FileLine.h index 8c4db3d67..e5e5688c8 100644 --- a/src/V3FileLine.h +++ b/src/V3FileLine.h @@ -123,10 +123,10 @@ public: const string filebasenameNoExt() const; const string profileFuncname() const; const string xml() const { return "fl=\""+filenameLetters()+cvtToStr(lineno())+"\""; } - string lineDirectiveStrg(int enter_exit_level) const; + string lineDirectiveStrg(int enterExit) const; void warnOn(V3ErrorCode code, bool flag) { m_warnOn.set(code,flag); } // Turn on/off warning messages on this line. void warnOff(V3ErrorCode code, bool flag) { warnOn(code,!flag); } - bool warnOff(const string& code, bool flag); // Returns 1 if ok + bool warnOff(const string& msg, bool flag); // Returns 1 if ok bool warnIsOff(V3ErrorCode code) const; void warnLintOff(bool flag); void warnStyleOff(bool flag); diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index f3330481e..95d5b156b 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -230,9 +230,11 @@ private: } virtual void visit(AstNodeAssign* nodep) { m_substTreep = nodep->rhsp(); - if (!VN_IS(nodep->lhsp(), NodeVarRef)) - clearSimple("ASSIGN(non-VARREF)"); - else iterateChildren(nodep); + if (!VN_IS(nodep->lhsp(), NodeVarRef)) { + clearSimple("ASSIGN(non-VARREF)"); + } else { + iterateChildren(nodep); + } // We don't push logic other then assignments/NOTs into SenItems // This avoids a mess in computing what exactly a POSEDGE is // V3Const cleans up any NOTs by flipping the edges for us @@ -345,7 +347,7 @@ private: } GateVarVertex* makeVarVertex(AstVarScope* varscp) { - GateVarVertex* vertexp = (GateVarVertex*)(varscp->user1p()); + GateVarVertex* vertexp = reinterpret_cast(varscp->user1p()); if (!vertexp) { UINFO(6,"New vertex "<verticesNextp()) { - GateEitherVertex* evertexp = (GateEitherVertex*)vertexp; + GateEitherVertex* evertexp = static_cast(vertexp); if (!evertexp->user() && evertexp->consumed()) { consumedMarkRecurse(evertexp); } @@ -751,7 +753,7 @@ void GateVisitor::consumedMarkRecurse(GateEitherVertex* vertexp) { if (!vertexp->consumed()) vertexp->setConsumed("propagated"); // Walk sources and mark them too for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) { - GateEitherVertex* eFromVertexp = (GateEitherVertex*)edgep->fromp(); + GateEitherVertex* eFromVertexp = static_cast(edgep->fromp()); consumedMarkRecurse(eFromVertexp); } } @@ -1016,7 +1018,7 @@ public: if (AstNodeVarRef* lhsVarRefp = VN_CAST(lhsp, NodeVarRef)) { if (lhsVarRefp->varScopep() != consumerVarScopep) consumerVarScopep->v3fatalSrc("Consumer doesn't match lhs of assign"); if (AstNodeAssign* dup = m_hash.hashAndFindDupe(m_assignp,activep,m_ifCondp)) { - return (AstNodeVarRef*) dup->lhsp(); + return static_cast(dup->lhsp()); } } } @@ -1044,16 +1046,17 @@ private: m_depth++; if (vvertexp->inSize1()) { - AstNodeVarRef* dupVarRefp = (AstNodeVarRef*) vvertexp->iterateInEdges(*this, VNUser(vvertexp)).toNodep(); - + AstNodeVarRef* dupVarRefp = static_cast + (vvertexp->iterateInEdges(*this, VNUser(vvertexp)).toNodep()); if (dupVarRefp) { V3GraphEdge* edgep = vvertexp->inBeginp(); - GateLogicVertex* lvertexp = (GateLogicVertex*)edgep->fromp(); + GateLogicVertex* lvertexp = static_cast(edgep->fromp()); if (!vvertexp->dedupable()) vvertexp->varScp()->v3fatalSrc("GateLogicVertex* visit should have returned NULL if consumer var vertex is not dedupable."); GateOkVisitor okVisitor(lvertexp->nodep(), false, true); if (okVisitor.isSimple()) { AstVarScope* dupVarScopep = dupVarRefp->varScopep(); - GateVarVertex* dupVvertexp = (GateVarVertex*) (dupVarScopep->user1p()); + GateVarVertex* dupVvertexp + = reinterpret_cast(dupVarScopep->user1p()); UINFO(4,"replacing " << vvertexp << " with " << dupVvertexp << endl); ++m_numDeduped; // Replace all of this varvertex's consumers with dupVarRefp @@ -1089,7 +1092,7 @@ private: virtual VNUser visit(GateLogicVertex* lvertexp, VNUser vu) { lvertexp->iterateInEdges(*this); - GateVarVertex* consumerVvertexpp = (GateVarVertex*) vu.toGraphVertex(); + GateVarVertex* consumerVvertexpp = static_cast(vu.toGraphVertex()); if (lvertexp->dedupable() && consumerVvertexpp->dedupable()) { AstNode* nodep = lvertexp->nodep(); AstVarScope* consumerVarScopep = consumerVvertexpp->varScp(); @@ -1161,9 +1164,10 @@ private: const AstConst* cstart = VN_CAST(cur->lsbp(), Const); const AstConst* cwidth = VN_CAST(cur->widthp(), Const); if (!pstart || !pwidth || !cstart || !cwidth) return NULL; // too complicated - if (cur->lsbConst()+cur->widthConst() == pre->lsbConst()) - return new AstSel(curVarRefp->fileline(), curVarRefp->cloneTree(false), cur->lsbConst(), pre->widthConst()+cur->widthConst()); - else return NULL; + if (cur->lsbConst()+cur->widthConst() == pre->lsbConst()) { + return new AstSel(curVarRefp->fileline(), curVarRefp->cloneTree(false), + cur->lsbConst(), pre->widthConst()+cur->widthConst()); + } else return NULL; } virtual VNUser visit(GateVarVertex *vvertexp, VNUser) { @@ -1353,7 +1357,7 @@ private: m_seen_clk_vectors++; m_total_seen_clk_vectors++; } - GateClkDecompState* currState = (GateClkDecompState*) vu.c(); + GateClkDecompState* currState = reinterpret_cast(vu.c()); GateClkDecompState nextState(currState->m_offset, vsp); vvertexp->iterateCurrentOutEdges(*this, VNUser(&nextState)); if (vsp->varp()->width() > 1) { @@ -1364,7 +1368,7 @@ private: } virtual VNUser visit(GateLogicVertex* lvertexp, VNUser vu) { - GateClkDecompState* currState = (GateClkDecompState*) vu.c(); + GateClkDecompState* currState = reinterpret_cast(vu.c()); int clk_offset = currState->m_offset; if (const AstAssignW* assignp = VN_CAST(lvertexp->nodep(), AssignW)) { UINFO(9,"CLK DECOMP Logic (off = "< OrigEdgeList; // List of orig edges, see also GraphAcyc's decl V3GraphEdge* origEdgep() const { - OrigEdgeList* oEListp = ((OrigEdgeList*)userp()); + OrigEdgeList* oEListp = static_cast(userp()); if (!oEListp) v3fatalSrc("No original edge associated with acyc edge "<front()); } @@ -114,12 +114,12 @@ private: void buildGraph(V3Graph* origGraphp); void buildGraphIterate(V3GraphVertex* overtexp, GraphAcycVertex* avertexp); void simplify(bool allowCut); - void simplifyNone(GraphAcycVertex* vertexp); - void simplifyOne(GraphAcycVertex* vertexp); - void simplifyOut(GraphAcycVertex* vertexp); - void simplifyDup(GraphAcycVertex* vertexp); - void cutBasic(GraphAcycVertex* vertexp); - void cutBackward(GraphAcycVertex* vertexp); + void simplifyNone(GraphAcycVertex* avertexp); + void simplifyOne(GraphAcycVertex* avertexp); + void simplifyOut(GraphAcycVertex* avertexp); + void simplifyDup(GraphAcycVertex* avertexp); + void cutBasic(GraphAcycVertex* avertexp); + void cutBackward(GraphAcycVertex* avertexp); void deleteMarked(); void place(); void placeTryEdge(V3GraphEdge* edgep); @@ -144,8 +144,8 @@ private: m_origEdgeDelp.push_back(oep); toEdgep->userp(oep); } - OrigEdgeList* oEListp = (OrigEdgeList*)(toEdgep->userp()); - if (OrigEdgeList* addListp = (OrigEdgeList*)(addEdgep->userp())) { + OrigEdgeList* oEListp = static_cast(toEdgep->userp()); + if (OrigEdgeList* addListp = static_cast(addEdgep->userp())) { for (OrigEdgeList::iterator it = addListp->begin(); it != addListp->end(); ++it) { oEListp->push_back(*it); } @@ -158,7 +158,7 @@ private: // From the break edge, cut edges in original graph it represents UINFO(8,why<<" CUT "<fromp()<cut(); - OrigEdgeList* oEListp = (OrigEdgeList*)(breakEdgep->userp()); + OrigEdgeList* oEListp = static_cast(breakEdgep->userp()); if (!oEListp) v3fatalSrc("No original edge associated with cutting edge "<begin(); it != oEListp->end(); ++it) { @@ -169,7 +169,7 @@ private: } // Work Que void workPush(V3GraphVertex* vertexp) { - GraphAcycVertex* avertexp = (GraphAcycVertex*)vertexp; + GraphAcycVertex* avertexp = static_cast(vertexp); // Add vertex to list of nodes needing further optimization trials if (!avertexp->m_onWorkList) { avertexp->m_onWorkList = true; @@ -216,7 +216,7 @@ void GraphAcyc::buildGraph(V3Graph* origGraphp) { // Build edges between logic vertices for (V3GraphVertex* overtexp = origGraphp->verticesBeginp(); overtexp; overtexp=overtexp->verticesNextp()) { if (overtexp->color()) { - GraphAcycVertex* avertexp = (GraphAcycVertex*)(overtexp->userp()); + GraphAcycVertex* avertexp = static_cast(overtexp->userp()); buildGraphIterate(overtexp, avertexp); } } @@ -228,7 +228,7 @@ void GraphAcyc::buildGraphIterate(V3GraphVertex* overtexp, GraphAcycVertex* aver if (origFollowEdge(edgep)) { // not cut V3GraphVertex* toVertexp = edgep->top(); if (toVertexp->color()) { - GraphAcycVertex* toAVertexp = (GraphAcycVertex*)(toVertexp->userp()); + GraphAcycVertex* toAVertexp = static_cast(toVertexp->userp()); // Replicate the old edge into the new graph // There may be multiple edges between same pairs of vertices V3GraphEdge* breakEdgep = new GraphAcycEdge @@ -267,7 +267,7 @@ void GraphAcyc::deleteMarked() { // Delete nodes marked for removal for (V3GraphVertex* nextp, *vertexp = m_breakGraph.verticesBeginp(); vertexp; vertexp=nextp) { nextp = vertexp->verticesNextp(); - GraphAcycVertex* avertexp = (GraphAcycVertex*)vertexp; + GraphAcycVertex* avertexp = static_cast(vertexp); if (avertexp->isDelete()) { avertexp->unlinkDelete(&m_breakGraph); VL_DANGLING(avertexp); } @@ -377,7 +377,7 @@ void GraphAcyc::simplifyDup(GraphAcycVertex* avertexp) { for (V3GraphEdge* nextp, *edgep = avertexp->outBeginp(); edgep; edgep=nextp) { nextp = edgep->outNextp(); V3GraphVertex* outVertexp = edgep->top(); - V3GraphEdge* prevEdgep = (V3GraphEdge*)outVertexp->userp(); + V3GraphEdge* prevEdgep = static_cast(outVertexp->userp()); if (prevEdgep) { if (!prevEdgep->cutable()) { // !cutable duplicates prev !cutable: we can ignore it, redundant @@ -484,7 +484,8 @@ void GraphAcyc::placeTryEdge(V3GraphEdge* edgep) { // Vertex::m_user begin: number indicates this edge was completed // Try to assign ranks, presuming this edge is in place // If we come across user()==placestep, we've detected a loop and must back out - bool loop=placeIterate((GraphAcycVertex*)edgep->top(), edgep->fromp()->rank()+1); + bool loop = placeIterate(static_cast(edgep->top()), + edgep->fromp()->rank()+1); if (!loop) { // No loop, we can keep it as uncutable // Commit the new ranks we calculated @@ -523,7 +524,7 @@ bool GraphAcyc::placeIterate(GraphAcycVertex* vertexp, uint32_t currentRank) { // Follow all edges and increase their ranks for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) { if (edgep->weight() && !edgep->cutable()) { - if (placeIterate((GraphAcycVertex*)edgep->top(), currentRank+1)) { + if (placeIterate(static_cast(edgep->top()), currentRank+1)) { // We don't need to reset user(); we'll use a different placeStep for the next edge return true; // Loop detected } diff --git a/src/V3GraphAlg.cpp b/src/V3GraphAlg.cpp index 6e894aed6..72dddd31d 100644 --- a/src/V3GraphAlg.cpp +++ b/src/V3GraphAlg.cpp @@ -92,7 +92,7 @@ private: nextp = edgep->outNextp(); if (followEdge(edgep)) { V3GraphVertex* outVertexp = edgep->top(); - V3GraphEdge* prevEdgep = (V3GraphEdge*)outVertexp->userp(); + V3GraphEdge* prevEdgep = static_cast(outVertexp->userp()); if (!prevEdgep) { // No previous assignment outVertexp->userp(edgep); } else { // Duplicate @@ -427,7 +427,7 @@ private: //! Iterate through all connected nodes of a graph with a loop or loops. V3GraphVertex* vertexIterateAll(V3GraphVertex* vertexp) { - if (V3GraphVertex* newVertexp = (V3GraphVertex*)vertexp->userp()) { + if (V3GraphVertex* newVertexp = static_cast(vertexp->userp())) { return newVertexp; } else { newVertexp = vertexp->clone(m_loopGraphp); @@ -436,7 +436,7 @@ private: for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) { if (followEdge(edgep)) { - V3GraphEdge* newEdgep = (V3GraphEdge*)edgep->userp(); + V3GraphEdge* newEdgep = static_cast(edgep->userp()); if (!newEdgep) { V3GraphVertex* newTop = vertexIterateAll(edgep->top()); newEdgep = edgep->clone(m_loopGraphp, newVertexp, diff --git a/src/V3GraphDfa.cpp b/src/V3GraphDfa.cpp index 6464f987e..2dabb0c25 100644 --- a/src/V3GraphDfa.cpp +++ b/src/V3GraphDfa.cpp @@ -159,9 +159,7 @@ private: } // If we saw all of the nodes, then they have the same number of hits // (Else something in dfa1p that wasn't in dfa2p) - if (num1s != num2s) return false; - // Match - return true; + return (num1s == num2s); } void insertDfaOrigins(DfaVertex* dfaStatep) { diff --git a/src/V3GraphPathChecker.h b/src/V3GraphPathChecker.h index c83a298cb..7def99de2 100644 --- a/src/V3GraphPathChecker.h +++ b/src/V3GraphPathChecker.h @@ -58,7 +58,7 @@ class GraphPathChecker : GraphAlg { bool pathExistsInternal(const V3GraphVertex* ap, const V3GraphVertex* bp, unsigned* costp = NULL); - void initHalfCriticalPaths(GraphWay w, bool checkOnly); + void initHalfCriticalPaths(GraphWay way, bool checkOnly); void incGeneration() { ++m_generation; } VL_DEBUG_FUNC; // Declare debug() diff --git a/src/V3GraphTest.cpp b/src/V3GraphTest.cpp index 2413a4be8..0577e08e6 100644 --- a/src/V3GraphTest.cpp +++ b/src/V3GraphTest.cpp @@ -334,7 +334,7 @@ public: virtual string name() { return "import"; } virtual void runTest() { DfaGraph* gp = &m_graph; - if (V3GraphTest::debug()) gp->debug(9); + if (V3GraphTest::debug()) DfaGraph::debug(9); dotImport(); dump(); gp->acyclic(&V3GraphEdge::followAlwaysTrue); diff --git a/src/V3Inst.h b/src/V3Inst.h index a17b4f04d..11b54abc9 100644 --- a/src/V3Inst.h +++ b/src/V3Inst.h @@ -33,8 +33,8 @@ class V3Inst { public: static void instAll(AstNetlist* nodep); static void dearrayAll(AstNetlist* nodep); - static AstAssignW* pinReconnectSimple(AstPin* nodep, AstCell* cellp, - bool forTristate, bool alwaysCvt=false); + static AstAssignW* pinReconnectSimple(AstPin* pinp, AstCell* cellp, + bool forTristate, bool alwaysCvt=false); }; #endif // Guard diff --git a/src/V3LifePost.cpp b/src/V3LifePost.cpp index 620c3f5df..4c96754a9 100644 --- a/src/V3LifePost.cpp +++ b/src/V3LifePost.cpp @@ -60,7 +60,7 @@ private: virtual void visit(AstVarRef* nodep) { AstVarScope* vscp = nodep->varScopep(); if (!vscp) nodep->v3fatalSrc("Scope not assigned"); - if (AstVarScope* newvscp = (AstVarScope*)vscp->user4p()) { + if (AstVarScope* newvscp = reinterpret_cast(vscp->user4p())) { UINFO(9, " Replace "<fileline(), newvscp, nodep->lvalue()); nodep->replaceWith(newrefp); @@ -222,7 +222,7 @@ private: const std::set& dlyVarAssigns = m_writes[dlyVarp]; // Proof (1) const std::set& dlyVarReads = m_reads[dlyVarp]; - if (dlyVarReads.size() > 0) { + if (!dlyVarReads.empty()) { continue; // do not scrunch, go to next LifePostLocation } diff --git a/src/V3LinkCells.cpp b/src/V3LinkCells.cpp index 9556ee2e7..dcfd405a5 100644 --- a/src/V3LinkCells.cpp +++ b/src/V3LinkCells.cpp @@ -459,14 +459,14 @@ private: public: // CONSTUCTORS - LinkCellsVisitor(AstNetlist* rootp, V3InFilter* filterp, V3ParseSym* parseSymp) - : m_mods(rootp) { + LinkCellsVisitor(AstNetlist* nodep, V3InFilter* filterp, V3ParseSym* parseSymp) + : m_mods(nodep) { m_filterp = filterp; m_parseSymp = parseSymp; m_modp = NULL; m_libVertexp = NULL; m_topVertexp = NULL; - iterate(rootp); + iterate(nodep); } virtual ~LinkCellsVisitor() {} }; @@ -474,7 +474,7 @@ public: //###################################################################### // Link class functions -void V3LinkCells::link(AstNetlist* rootp, V3InFilter* filterp, V3ParseSym* parseSymp) { +void V3LinkCells::link(AstNetlist* nodep, V3InFilter* filterp, V3ParseSym* parseSymp) { UINFO(4,__FUNCTION__<<": "<= 6); + V3Global::dumpCheckGlobalTree("linkdot", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 6); } static void linkDotParamed(AstNetlist* nodep) { UINFO(2,__FUNCTION__<<": "<= 3); + V3Global::dumpCheckGlobalTree("paramlink", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3); } static void linkDotArrayed(AstNetlist* nodep) { UINFO(2,__FUNCTION__<<": "<= 6); + V3Global::dumpCheckGlobalTree("linkdot", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 6); } static void linkDotScope(AstNetlist* nodep) { UINFO(2,__FUNCTION__<<": "<= 3); + V3Global::dumpCheckGlobalTree("linkdot", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3); } }; diff --git a/src/V3LinkLValue.cpp b/src/V3LinkLValue.cpp index 41073c419..bd787a60a 100644 --- a/src/V3LinkLValue.cpp +++ b/src/V3LinkLValue.cpp @@ -271,10 +271,10 @@ public: //###################################################################### // Link class functions -void V3LinkLValue::linkLValue(AstNetlist* rootp) { +void V3LinkLValue::linkLValue(AstNetlist* nodep) { UINFO(4,__FUNCTION__<<": "<= 6); } diff --git a/src/V3LinkLevel.cpp b/src/V3LinkLevel.cpp index 139850f7d..b50a4fa6c 100644 --- a/src/V3LinkLevel.cpp +++ b/src/V3LinkLevel.cpp @@ -85,30 +85,30 @@ void V3LinkLevel::modSortByLevel() { //###################################################################### // Wrapping -void V3LinkLevel::wrapTop(AstNetlist* netlistp) { +void V3LinkLevel::wrapTop(AstNetlist* rootp) { UINFO(2,__FUNCTION__<<": "<modulesp(); - if (!oldmodp) netlistp->v3fatalSrc("No module found to process"); + AstNodeModule* oldmodp = rootp->modulesp(); + if (!oldmodp) rootp->v3fatalSrc("No module found to process"); AstNodeModule* newmodp = new AstModule(oldmodp->fileline(), string("TOP_")+oldmodp->name()); // Make the new module first in the list oldmodp->unlinkFrBackWithNext(); newmodp->addNext(oldmodp); newmodp->level(1); newmodp->modPublic(true); - netlistp->addModulep(newmodp); + rootp->addModulep(newmodp); // TODO the module creation above could be done after linkcells, but // the rest must be done after data type resolution - wrapTopCell(netlistp); - wrapTopPackages(netlistp); + wrapTopCell(rootp); + wrapTopPackages(rootp); } -void V3LinkLevel::wrapTopCell(AstNetlist* netlistp) { - AstNodeModule* newmodp = netlistp->modulesp(); - if (!newmodp || !newmodp->isTop()) netlistp->v3fatalSrc("No TOP module found to process"); +void V3LinkLevel::wrapTopCell(AstNetlist* rootp) { + AstNodeModule* newmodp = rootp->modulesp(); + if (!newmodp || !newmodp->isTop()) rootp->v3fatalSrc("No TOP module found to process"); AstNodeModule* oldmodp = VN_CAST(newmodp->nextp(), NodeModule); - if (!oldmodp) netlistp->v3fatalSrc("No module found to process"); + if (!oldmodp) rootp->v3fatalSrc("No module found to process"); // Add instance AstCell* cellp = new AstCell(newmodp->fileline(), @@ -148,12 +148,12 @@ void V3LinkLevel::wrapTopCell(AstNetlist* netlistp) { } } -void V3LinkLevel::wrapTopPackages(AstNetlist* netlistp) { +void V3LinkLevel::wrapTopPackages(AstNetlist* rootp) { // Instantiate all packages under the top wrapper // This way all later SCOPE based optimizations can ignore packages - AstNodeModule* newmodp = netlistp->modulesp(); - if (!newmodp || !newmodp->isTop()) netlistp->v3fatalSrc("No TOP module found to process"); - for (AstNodeModule* modp = netlistp->modulesp(); modp; modp=VN_CAST(modp->nextp(), NodeModule)) { + AstNodeModule* newmodp = rootp->modulesp(); + if (!newmodp || !newmodp->isTop()) rootp->v3fatalSrc("No TOP module found to process"); + for (AstNodeModule* modp = rootp->modulesp(); modp; modp=VN_CAST(modp->nextp(), NodeModule)) { if (VN_IS(modp, Package)) { AstCell* cellp = new AstCell(modp->fileline(), // Could add __03a__03a="::" to prevent conflict diff --git a/src/V3LinkLevel.h b/src/V3LinkLevel.h index 1af721372..268631c3f 100644 --- a/src/V3LinkLevel.h +++ b/src/V3LinkLevel.h @@ -31,11 +31,11 @@ class V3LinkLevel { private: - static void wrapTopCell(AstNetlist* nodep); - static void wrapTopPackages(AstNetlist* nodep); + static void wrapTopCell(AstNetlist* rootp); + static void wrapTopPackages(AstNetlist* rootp); public: static void modSortByLevel(); - static void wrapTop(AstNetlist* nodep); + static void wrapTop(AstNetlist* rootp); }; #endif // Guard diff --git a/src/V3LinkParse.h b/src/V3LinkParse.h index 243b846ab..39df59072 100644 --- a/src/V3LinkParse.h +++ b/src/V3LinkParse.h @@ -31,7 +31,7 @@ class V3LinkParse { public: - static void linkParse(AstNetlist* nodep); + static void linkParse(AstNetlist* rootp); }; #endif // Guard diff --git a/src/V3LinkResolve.h b/src/V3LinkResolve.h index 89b3e0eed..8da8bb998 100644 --- a/src/V3LinkResolve.h +++ b/src/V3LinkResolve.h @@ -31,7 +31,7 @@ class V3LinkResolve { public: - static void linkResolve(AstNetlist* nodep); + static void linkResolve(AstNetlist* rootp); }; #endif // Guard diff --git a/src/V3Localize.cpp b/src/V3Localize.cpp index a218cf0af..ff7353619 100644 --- a/src/V3Localize.cpp +++ b/src/V3Localize.cpp @@ -63,7 +63,7 @@ protected: }; // cppcheck-suppress unusedStructMember uint32_t m_flags; - VarFlags(AstNode* nodep) { m_flags = nodep->user2(); } + explicit VarFlags(AstNode* nodep) { m_flags = nodep->user2(); } void setNodeFlags(AstNode* nodep) { nodep->user2(m_flags); } }; }; @@ -215,7 +215,7 @@ private: clearOptimizable(nodep->varp(),"BVmultiF"); } // First varref in function must be assignment found earlier - AstVarRef* firstasn = (AstVarRef*)(nodep->varp()->user4p()); + AstVarRef* firstasn = static_cast(nodep->varp()->user4p()); if (firstasn && nodep!=firstasn) { clearStdOptimizable(nodep->varp(),"notFirstAsn"); nodep->varp()->user4p(NULL); diff --git a/src/V3Number.cpp b/src/V3Number.cpp index 85e443c33..ce68f79b0 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -490,7 +490,7 @@ string V3Number::displayed(FileLine*fl, const string& vformat) const { while ((bit%3)!=2) bit++; for (; bit>0; bit -= 3) { int v = bitsValue(bit-2, 3); - str += (char)('0'+v); + str += static_cast('0' + v); } return str; } @@ -501,8 +501,8 @@ string V3Number::displayed(FileLine*fl, const string& vformat) const { while ((bit%4)!=3) bit++; for (; bit>0; bit -= 4) { int v = bitsValue(bit-3, 4); - if (v>=10) str += (char)('a'+v-10); - else str += (char)('0'+v); + if (v>=10) str += static_cast('a' + v - 10); + else str += static_cast('0' + v); } return str; } @@ -521,8 +521,8 @@ string V3Number::displayed(FileLine*fl, const string& vformat) const { for (; bit>=0; bit -= 8) { int v = bitsValue(bit-7, 8); if (!start || v) { - str += (char)((v==0)?' ':v); - start = false; // Drop leading 0s + str += static_cast((v==0) ? ' ' : v); + start = false; // Drop leading 0s } else { if (fmtsize != "0") str += ' '; } @@ -555,7 +555,7 @@ string V3Number::displayed(FileLine*fl, const string& vformat) const { } int intfmtsize = atoi(fmtsize.c_str()); bool zeropad = fmtsize.length()>0 && fmtsize[0]=='0'; - while ((int)(str.length()) < intfmtsize) { + while (static_cast(str.length()) < intfmtsize) { if (zeropad) str.insert(0, "0"); else str.insert(0, " "); } @@ -572,23 +572,23 @@ string V3Number::displayed(FileLine*fl, const string& vformat) const { // 'p' // Packed - converted to another code by V3Width case 'u': { // Packed 2-state for (int i=0; i> 0) & 0xff); - str += (char)((m_value[i] >> 8) & 0xff); - str += (char)((m_value[i] >> 16) & 0xff); - str += (char)((m_value[i] >> 24) & 0xff); + str += static_cast((m_value[i] >> 0) & 0xff); + str += static_cast((m_value[i] >> 8) & 0xff); + str += static_cast((m_value[i] >> 16) & 0xff); + str += static_cast((m_value[i] >> 24) & 0xff); } return str; } case 'z': { // Packed 4-state for (int i=0; i> 0) & 0xff); - str += (char)((m_value[i] >> 8) & 0xff); - str += (char)((m_value[i] >> 16) & 0xff); - str += (char)((m_value[i] >> 24) & 0xff); - str += (char)((m_valueX[i] >> 0) & 0xff); - str += (char)((m_valueX[i] >> 8) & 0xff); - str += (char)((m_valueX[i] >> 16) & 0xff); - str += (char)((m_valueX[i] >> 24) & 0xff); + str += static_cast((m_value[i] >> 0) & 0xff); + str += static_cast((m_value[i] >> 8) & 0xff); + str += static_cast((m_value[i] >> 16) & 0xff); + str += static_cast((m_value[i] >> 24) & 0xff); + str += static_cast((m_valueX[i] >> 0) & 0xff); + str += static_cast((m_valueX[i] >> 8) & 0xff); + str += static_cast((m_valueX[i] >> 16) & 0xff); + str += static_cast((m_valueX[i] >> 24) & 0xff); } return str; } @@ -691,11 +691,11 @@ vlsint32_t V3Number::toSInt() const { uint32_t v = toUInt(); uint32_t signExtend = (-(v & (1UL<<(width()-1)))); uint32_t extended = v | signExtend; - return (vlsint32_t)(extended); + return static_cast(extended); } else { // Where we use this (widths, etc) and care about signedness, // we can reasonably assume the MSB isn't set on unsigned numbers. - return (vlsint32_t)toUInt(); + return static_cast(toUInt()); } } @@ -705,15 +705,16 @@ vluint64_t V3Number::toUQuad() const { for (int i=2; i(toUInt())); + return ((static_cast(m_value[1])<(m_value[0]))); } vlsint64_t V3Number::toSQuad() const { vluint64_t v = toUQuad(); vluint64_t signExtend = (-(v & (VL_ULL(1)<<(width()-1)))); vluint64_t extended = v | signExtend; - return (vlsint64_t)(extended); + return static_cast(extended); } string V3Number::toString() const { @@ -727,8 +728,8 @@ string V3Number::toString() const { for (; bit>=0; bit -= 8) { int v = bitsValue(bit-7, 8); if (!start || v) { - str += (char)((v==0)?' ':v); - start = false; // Drop leading 0s + str += static_cast((v==0) ? ' ' : v); + start = false; // Drop leading 0s } } return str; @@ -1069,7 +1070,7 @@ V3Number& V3Number::opStreamL(const V3Number& lhs, const V3Number& rhs) { m_fileline->v3warn(WIDTHCONCAT,"Unsized numbers/parameters not allowed in streams."); } // Slice size should never exceed the lhs width - int ssize = std::min(rhs.toUInt(), (unsigned)lhs.width()); + int ssize = std::min(rhs.toUInt(), static_cast(lhs.width())); for (int istart=0; istartwidth(); bit++) { - if (bit >= (int)rhsval) { + if (bit >= static_cast(rhsval)) { setBit(bit,lhs.bitIs((bit - rhsval) % this->width())); } } @@ -1288,7 +1289,7 @@ V3Number& V3Number::opShiftR(const V3Number& lhs, const V3Number& rhs) { if (rhs.bitIs1(bit)) return *this; // shift of over 2^32 must be zero } uint32_t rhsval = rhs.toUInt(); - if (rhsval < (uint32_t)lhs.width()) { + if (rhsval < static_cast(lhs.width())) { for (int bit=0; bitwidth(); bit++) { setBit(bit,lhs.bitIs(bit + rhsval)); } @@ -1310,7 +1311,7 @@ V3Number& V3Number::opShiftRS(const V3Number& lhs, const V3Number& rhs, uint32_t return *this; // shift of over 2^32 must be -1/0 } uint32_t rhsval = rhs.toUInt(); - if (rhsval < (uint32_t)lhs.width()) { + if (rhsval < static_cast(lhs.width())) { for (int bit=0; bitwidth(); bit++) { setBit(bit,lhs.bitIsExtend(bit + rhsval, lbits)); } @@ -1331,8 +1332,8 @@ V3Number& V3Number::opShiftL(const V3Number& lhs, const V3Number& rhs) { } uint32_t rhsval = rhs.toUInt(); for (int bit=0; bitwidth(); bit++) { - if (bit >= (int)rhsval) { - setBit(bit,lhs.bitIs(bit - rhsval)); + if (bit >= static_cast(rhsval)) { + setBit(bit, lhs.bitIs(bit - rhsval)); } } return *this; @@ -1391,7 +1392,8 @@ V3Number& V3Number::opMul(const V3Number& lhs, const V3Number& rhs) { } else { for (int lword=0; lword(lhs.m_value[lword]) + * static_cast(rhs.m_value[rword]); for (int qword=lword+rword; qwordwords(); qword++) { mul += (vluint64_t)(m_value[qword]); m_value[qword] = (mul & VL_ULL(0xffffffff)); @@ -1494,9 +1496,10 @@ V3Number& V3Number::opModDivGuts(const V3Number& lhs, const V3Number& rhs, bool 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<(lhs.m_value[j])); + m_value[j] = unw64 / static_cast(rhs.m_value[0]); + k = unw64 - (static_cast(m_value[j]) + * static_cast(rhs.m_value[0])); } UINFO(9, " opmoddiv-1w "<= 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) @@ -1565,7 +1569,7 @@ V3Number& V3Number::opModDivGuts(const V3Number& lhs, const V3Number& rhs, bool this->m_value[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); } @@ -1684,15 +1688,15 @@ V3Number& V3Number::opSel(const V3Number& lhs, const V3Number& msb, const V3Numb V3Number& V3Number::opSel(const V3Number& lhs, uint32_t msbval, uint32_t lsbval) { setZero(); - int ibit=lsbval; + int ibit = lsbval; for(int bit=0; bitwidth(); bit++) { if (ibit>=0 && ibit(msbval)) { + setBit(bit, lhs.bitIs(ibit)); } else { - setBit(bit,'x'); + setBit(bit, 'x'); } - ibit++; + ++ibit; } //UINFO(0,"RANGE "<(args[i].c_str()); } parseOptsList(fl, optdir, args.size(), argv); } diff --git a/src/V3Options.h b/src/V3Options.h index 2d44a10f0..69f896423 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -27,10 +27,10 @@ #include "V3Global.h" #include "V3LangCode.h" -#include -#include #include #include +#include +#include class V3OptionsImp; class FileLine; @@ -214,7 +214,7 @@ class V3Options { private: // METHODS - void addArg(const string& flag); + void addArg(const string& arg); void addDefine(const string& defline, bool allowPlus); void addFuture(const string& flag); void addIncDirUser(const string& incdir); // User requested @@ -238,9 +238,9 @@ class V3Options { ~V3Options(); void setDebugMode(int level); void setDebugSrcLevel(const string& srcfile, int level); - int debugSrcLevel(const string& srcfile, int default_level=V3Error::debugDefault()); + int debugSrcLevel(const string& srcfile_path, int default_level=V3Error::debugDefault()); void setDumpTreeLevel(const string& srcfile, int level); - int dumpTreeLevel(const string& srcfile); + int dumpTreeLevel(const string& srcfile_path); // METHODS void addCppFile(const string& filename); diff --git a/src/V3Order.cpp b/src/V3Order.cpp index 3a794b871..e08c3fa39 100644 --- a/src/V3Order.cpp +++ b/src/V3Order.cpp @@ -749,7 +749,7 @@ private: m_orderUserps.push_back(newup); varscp->user1p(newup); } - OrderUser* up = (OrderUser*)(varscp->user1p()); + OrderUser* up = reinterpret_cast(varscp->user1p()); OrderVarVertex* varVxp = up->newVarUserVertex(&m_graph, m_scopep, varscp, type, createdp); return varVxp; } @@ -1059,7 +1059,8 @@ private: // clock_enable attribute: user's worring about it for us con = false; } - if (m_inClkAss && (varscp->varp()->attrClocker()) != AstVarAttrClocker::CLOCKER_YES) { + if (m_inClkAss && (varscp->varp()->attrClocker() + != AstVarAttrClocker::CLOCKER_YES)) { con = false; UINFO(4, "nodep used as clock_enable "<nodep()<varp()->attrClocker() == AstVarAttrClocker::CLOCKER_YES) + if (varscp->varp()->attrClocker() + == AstVarAttrClocker::CLOCKER_YES) { new OrderEdge(&m_graph, m_logicVxp, varVxp, WEIGHT_NORMAL); - else + } else { new OrderComboCutEdge(&m_graph, m_logicVxp, varVxp); + } } // For m_inPost: // Add edge consumed_var_POST->logic_vertex @@ -1354,7 +1357,7 @@ void OrderVisitor::processInputsInIterate(OrderEitherVertex* vertexp, VertexVec& // Also, determine if this vertex is an input int inonly = 1; // 0=no, 1=maybe, 2=yes until a no for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) { - OrderEitherVertex* frVertexp = (OrderEitherVertex*)edgep->fromp(); + OrderEitherVertex* frVertexp = static_cast(edgep->fromp()); processInputsInIterate(frVertexp, todoVec); if (frVertexp->isFromInput()) { if (inonly==1) inonly = 2; @@ -1393,7 +1396,7 @@ void OrderVisitor::processInputsOutIterate(OrderEitherVertex* vertexp, VertexVec { // Propagate PrimaryIn through simple assignments, followint target of vertex for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) { - OrderEitherVertex* toVertexp = (OrderEitherVertex*)edgep->top(); + OrderEitherVertex* toVertexp = static_cast(edgep->top()); if (OrderVarStdVertex* vvertexp = dynamic_cast(toVertexp)) { processInputsInIterate(vvertexp, todoVec); } @@ -1506,7 +1509,7 @@ void OrderVisitor::processDomainsIterate(OrderEitherVertex* vertexp) { } if (!domainp) { for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) { - OrderEitherVertex* fromVertexp = (OrderEitherVertex*)edgep->fromp(); + OrderEitherVertex* fromVertexp = static_cast(edgep->fromp()); if (edgep->weight() && fromVertexp->domainMatters() ) { @@ -1721,7 +1724,7 @@ void OrderVisitor::processMoveDoneOne(OrderMoveVertex* vertexp) { // Mark our outputs as one closer to ready for (V3GraphEdge* edgep = vertexp->outBeginp(), *nextp; edgep; edgep=nextp) { nextp = edgep->outNextp(); - OrderMoveVertex* toVertexp = (OrderMoveVertex*)edgep->top(); + OrderMoveVertex* toVertexp = static_cast(edgep->top()); UINFO(9," Clear to "<<(toVertexp->inEmpty()?"[EMP] ":" ") <(tv.tv_sec)*1000000 + tv.tv_usec; diff --git a/src/V3Os.h b/src/V3Os.h index ebaf6298d..ab6a62761 100644 --- a/src/V3Os.h +++ b/src/V3Os.h @@ -43,7 +43,7 @@ public: return filenameNonExt(filenameNonDir(filename)); } static string filenameDir(const string& filename); ///< Return directory part of filename static string filenameSubstitute(const string& filename); ///< Return filename with env vars removed - static string filenameRealPath(const string& fn); ///< Return realpath of filename + static string filenameRealPath(const string& filename); ///< Return realpath of filename static bool filenameIsRel(const string& filename); ///< True if relative // METHODS (directory utilities) diff --git a/src/V3Param.cpp b/src/V3Param.cpp index d47b67f93..cf56ce15e 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -618,25 +618,26 @@ void ParamVisitor::visitCell(AstCell* nodep) { && VN_IS(exprp, VarRef) && VN_CAST(exprp, VarRef)->varp() && VN_CAST(exprp, VarRef)->varp()->subDTypep() - && VN_IS(VN_CAST(exprp, VarRef)->varp()->subDTypep(), IfaceRefDType)) + && VN_IS(VN_CAST(exprp, VarRef)->varp()->subDTypep(), IfaceRefDType)) { pinIrefp = VN_CAST(VN_CAST(exprp, VarRef)->varp()->subDTypep(), IfaceRefDType); - else if (exprp - && exprp->op1p() - && VN_IS(exprp->op1p(), VarRef) - && VN_CAST(exprp->op1p(), VarRef)->varp() - && VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep() - && VN_CAST(VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep(), UnpackArrayDType) - && VN_CAST(VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep() - && VN_CAST(VN_CAST(VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType)) + } else if (exprp + && exprp->op1p() + && VN_IS(exprp->op1p(), VarRef) + && VN_CAST(exprp->op1p(), VarRef)->varp() + && VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep() + && VN_CAST(VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep(), UnpackArrayDType) + && VN_CAST(VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep() + && VN_CAST(VN_CAST(VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType)) { pinIrefp = VN_CAST(VN_CAST(VN_CAST(exprp->op1p(), VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType); - else if (exprp - && VN_IS(exprp, VarRef) - && VN_CAST(exprp, VarRef)->varp() - && VN_CAST(exprp, VarRef)->varp()->subDTypep() - && VN_CAST(VN_CAST(exprp, VarRef)->varp()->subDTypep(), UnpackArrayDType) - && VN_CAST(VN_CAST(exprp, VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep() - && VN_CAST(VN_CAST(VN_CAST(exprp, VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType)) + } else if (exprp + && VN_IS(exprp, VarRef) + && VN_CAST(exprp, VarRef)->varp() + && VN_CAST(exprp, VarRef)->varp()->subDTypep() + && VN_CAST(VN_CAST(exprp, VarRef)->varp()->subDTypep(), UnpackArrayDType) + && VN_CAST(VN_CAST(exprp, VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep() + && VN_CAST(VN_CAST(VN_CAST(exprp, VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType)) { pinIrefp = VN_CAST(VN_CAST(VN_CAST(exprp, VarRef)->varp()->subDTypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType); + } UINFO(9," portIfaceRef "<warnResetDefault(); // Reenable warnings on each file lexDestroy(); // Restart from clean slate. - lexNew(debugFlex()>=9); + lexNew(); // Lex it if (bisonParse()) v3fatal("Cannot continue\n"); diff --git a/src/V3ParseImp.h b/src/V3ParseImp.h index 12e6a29c7..333c5df92 100644 --- a/src/V3ParseImp.h +++ b/src/V3ParseImp.h @@ -200,7 +200,7 @@ public: int bisonParse(); // Interactions with lexer - void lexNew(int debug); + void lexNew(); void lexDestroy(); void statePop(); // Parser -> lexer communication static int stateVerilogRecent(); // Parser -> lexer communication diff --git a/src/V3ParseLex.cpp b/src/V3ParseLex.cpp index 9b6c6f981..d590b4452 100644 --- a/src/V3ParseLex.cpp +++ b/src/V3ParseLex.cpp @@ -47,19 +47,22 @@ public: ~V3Lexer() {} // METHODS void statePop() { - yy_pop_state(); + yy_pop_state(); } void unputString(const char* textp, size_t length) { - // Add characters to input stream in back-to-front order - const char* cp = textp; - for (cp += length - 1; length--; cp--) { - unput(*cp); - } + // Add characters to input stream in back-to-front order + const char* cp = textp; + for (cp += length - 1; length--; cp--) { + unput(*cp); + } } }; -void V3ParseImp::statePop() { parsep()->m_lexerp->statePop(); } -void V3ParseImp::unputString(const char* textp, size_t length) { parsep()->m_lexerp->unputString(textp, length); } +void V3ParseImp::statePop() { parsep()->m_lexerp->statePop(); } + +void V3ParseImp::unputString(const char* textp, size_t length) { + parsep()->m_lexerp->unputString(textp, length); +} int V3ParseImp::yylexReadTok() { // Call yylex() remembering last non-whitespace token @@ -71,8 +74,8 @@ int V3ParseImp::yylexReadTok() { //###################################################################### // Read class functions -void V3ParseImp::lexNew(int debug) { - if (m_lexerp) delete m_lexerp; // Restart from clean slate. +void V3ParseImp::lexNew() { + if (m_lexerp) delete m_lexerp; // Restart from clean slate. m_lexerp = new V3Lexer(); if (debugFlex()>=9) { m_lexerp->set_debug(~0); } } diff --git a/src/V3Partition.cpp b/src/V3Partition.cpp index ce23d2d96..a6d309d4e 100644 --- a/src/V3Partition.cpp +++ b/src/V3Partition.cpp @@ -551,7 +551,7 @@ public: logcost = ceil(logcost); logcost = logcost / 20.0; - uint32_t stepCost = (uint32_t)(exp(logcost)); + uint32_t stepCost = static_cast(exp(logcost)); UASSERT_STATIC(stepCost >= cost, "stepped cost error exceeded"); UASSERT_STATIC(stepCost <= ((cost * 11 / 10)), "stepped cost error exceeded"); return stepCost; @@ -822,8 +822,7 @@ class MTaskEdge : public V3GraphEdge, public MergeCandidate { public: // CONSTRUCTORS MTaskEdge(V3Graph* graphp, LogicMTask* fromp, LogicMTask* top, int weight) - : V3GraphEdge(graphp, fromp, top, weight), - MergeCandidate() { + : V3GraphEdge(graphp, fromp, top, weight) { fromp->addRelative(GraphWay::FORWARD, top); top->addRelative(GraphWay::REVERSE, fromp); } @@ -2204,10 +2203,10 @@ private: public: // CONSTRUCTORS - PartPackMTasks(V3Graph* mtasksp, - uint32_t nThreads = v3Global.opt.threads(), - unsigned sandbagNumerator = 30, - unsigned sandbagDenom = 100) + explicit PartPackMTasks(V3Graph* mtasksp, + uint32_t nThreads = v3Global.opt.threads(), + unsigned sandbagNumerator = 30, + unsigned sandbagDenom = 100) : m_mtasksp(mtasksp) , m_nThreads(nThreads) , m_sandbagNumerator(sandbagNumerator) @@ -2296,6 +2295,7 @@ public: <<" on thread "<priority() > bestMtaskp->priority()))) { bestTime = timeBegin; bestTh = th; @@ -2304,6 +2304,7 @@ public: } } + if (!bestMtaskp) v3fatalSrc("Should have found some task"); UINFO(6, "Will schedule "<name() <<" onto thread "<cost(); diff --git a/src/V3Partition.h b/src/V3Partition.h index eec43a459..3212be710 100644 --- a/src/V3Partition.h +++ b/src/V3Partition.h @@ -60,7 +60,7 @@ public: static void hashGraphDebug(const V3Graph* graphp, const char* debugName); // Print debug stats about graphp whose nodes must be AbstractMTask's. - static void debugMTaskGraphStats(const V3Graph* graphp, const string& name); + static void debugMTaskGraphStats(const V3Graph* graphp, const string& stage); // Operate on the final ExecMTask graph, immediately prior to code // generation time. diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 128c769b7..811c7e2d1 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -230,11 +230,11 @@ public: string getline(); void insertUnreadback(const string& text) { m_lineCmt += text; } void insertUnreadbackAtBol(const string& text); - void addLineComment(int enter_exit_level); + void addLineComment(int enterExit); // METHODS, callbacks - virtual void comment(const string& cmt); // Comment detected (if keepComments==2) - virtual void include(const string& filename); // Request a include file be processed + virtual void comment(const string& text); // Comment detected (if keepComments==2) + virtual void include(const string& filename); // Request a include file be processed virtual void undef(const string& name); virtual void undefineall(); virtual void define(FileLine* fl, const string& name, const string& value, @@ -242,7 +242,7 @@ public: virtual string removeDefines(const string& text); // Remove defines in a text string // CONSTRUCTORS - V3PreProcImp() : V3PreProc() { + V3PreProcImp() { m_debug = 0; m_states.push(ps_TOP); m_off = 0; @@ -299,8 +299,7 @@ void V3PreProcImp::undefineall() { } bool V3PreProcImp::defExists(const string& name) { DefinesMap::iterator iter = m_defines.find(name); - if (iter == m_defines.end()) return false; - return true; + return (iter != m_defines.end()); } string V3PreProcImp::defValue(const string& name) { DefinesMap::iterator iter = m_defines.find(name); @@ -338,9 +337,9 @@ void V3PreProcImp::define(FileLine* fl, const string& name, const string& value, m_defines.insert(make_pair(name, V3Define(fl, value, params, cmdline))); } -string V3PreProcImp::removeDefines(const string& sym) { +string V3PreProcImp::removeDefines(const string& text) { string val = "0_never_match"; - string rtnsym = sym; + string rtnsym = text; for (int loopprevent=0; loopprevent<100; loopprevent++) { string xsym = rtnsym; if (xsym.substr(0,1)=="`") xsym.replace(0,1,""); @@ -793,9 +792,9 @@ void V3PreProcImp::insertUnreadbackAtBol(const string& text) { insertUnreadback(text); } -void V3PreProcImp::addLineComment(int enter_exit_level) { +void V3PreProcImp::addLineComment(int enterExit) { if (lineDirectives()) { - insertUnreadbackAtBol(m_lexp->curFilelinep()->lineDirectiveStrg(enter_exit_level)); + insertUnreadbackAtBol(m_lexp->curFilelinep()->lineDirectiveStrg(enterExit)); } } @@ -854,7 +853,8 @@ void V3PreProcImp::debugToken(int tok, const char* cmtp) { while ((pos = buf.find('\r')) != string::npos) { buf.replace(pos, 1, "\\r"); } fprintf(stderr, "%d: %s %s %s(%d) dr%d: <%d>%-10s: %s\n", m_lexp->m_tokFilelinep->lineno(), cmtp, m_off?"of":"on", - procStateName(state()), (int)m_states.size(), (int)m_defRefs.size(), + procStateName(state()), static_cast(m_states.size()), + static_cast(m_defRefs.size()), m_lexp->currentStartState(), tokenName(tok), buf.c_str()); } } @@ -889,7 +889,9 @@ int V3PreProcImp::getStateToken() { // We're off or processed the comment specially. If there are newlines // in it, we also return the newlines as TEXT so that the linenumber // count is maintained for downstream tools - for (size_t len=0; len<(size_t)yyourleng(); len++) { if (yyourtext()[len]=='\n') m_lineAdd++; } + for (size_t len=0; len(yyourleng()); len++) { + if (yyourtext()[len]=='\n') m_lineAdd++; + } goto next_tok; } if (tok==VP_LINE) { @@ -1416,11 +1418,14 @@ int V3PreProcImp::getFinalToken(string& buf) { if (m_finAtBol && !(tok==VP_TEXT && buf=="\n") && m_preprocp->lineDirectives()) { if (int outBehind = m_lexp->m_tokFilelinep->lineno() - m_finFilelinep->lineno()) { - if (debug()>=5) fprintf(stderr,"%d: FIN: readjust, fin at %d request at %d\n", - m_lexp->m_tokFilelinep->lineno(), - m_finFilelinep->lineno(), m_lexp->m_tokFilelinep->lineno()); + if (debug()>=5) { + fprintf(stderr, "%d: FIN: readjust, fin at %d request at %d\n", + m_lexp->m_tokFilelinep->lineno(), + m_finFilelinep->lineno(), m_lexp->m_tokFilelinep->lineno()); + } m_finFilelinep = m_finFilelinep->create(m_lexp->m_tokFilelinep->filename(),m_lexp->m_tokFilelinep->lineno()); - if (outBehind > 0 && outBehind <= (int)V3PreProc::NEWLINES_VS_TICKLINE) { + if (outBehind > 0 + && (outBehind <= static_cast(V3PreProc::NEWLINES_VS_TICKLINE))) { // Output stream is behind, send newlines to get back in sync // (Most likely because we're completing a disabled `endif) if (m_preprocp->keepWhitespace()) { diff --git a/src/V3PreProc.h b/src/V3PreProc.h index 901abc23d..f73dcd8c5 100644 --- a/src/V3PreProc.h +++ b/src/V3PreProc.h @@ -100,7 +100,7 @@ protected: }; void configure(FileLine* fl); public: - static V3PreProc* createPreProc(FileLine* fileline); + static V3PreProc* createPreProc(FileLine* fl); virtual ~V3PreProc() {} }; diff --git a/src/V3PreShell.h b/src/V3PreShell.h index 64cf9d3bd..553aaf6fd 100644 --- a/src/V3PreShell.h +++ b/src/V3PreShell.h @@ -36,9 +36,9 @@ class V3PreShell { // Static class for calling preprocessor public: static void boot(char** env); - static bool preproc(FileLine* fileline, const string& module, V3InFilter* filterp, - V3ParseImp* parsep, const string& errmsg); - static void preprocInclude(FileLine* fileline, const string& module); + static bool preproc(FileLine* fl, const string& modname, V3InFilter* filterp, + V3ParseImp* parsep, const string& errmsg); + static void preprocInclude(FileLine* fl, const string& modname); static string dependFiles() { return ""; } // Perl only static void defineCmdLine(const string& name, const string& value); static void undef(const string& name); diff --git a/src/V3Scope.cpp b/src/V3Scope.cpp index 3845bd4f7..7391fab1b 100644 --- a/src/V3Scope.cpp +++ b/src/V3Scope.cpp @@ -106,7 +106,9 @@ private: UINFO(4," MOD AT "<fileline(), + m_scopep = new AstScope((m_aboveCellp ? static_cast(m_aboveCellp) + : static_cast(nodep)) + ->fileline(), nodep, scopename, m_aboveScopep, m_aboveCellp); if (VN_IS(nodep, Package)) m_packageScopes.insert(make_pair(VN_CAST(nodep, Package), m_scopep)); diff --git a/src/V3Slice.cpp b/src/V3Slice.cpp index 2ae85dbae..9efd179ed 100644 --- a/src/V3Slice.cpp +++ b/src/V3Slice.cpp @@ -226,10 +226,10 @@ class SliceVisitor : public AstNVisitor { public: // CONSTUCTORS - explicit SliceVisitor(AstNetlist* rootp) { + explicit SliceVisitor(AstNetlist* nodep) { m_assignp = NULL; m_assignError = false; - iterate(rootp); + iterate(nodep); } virtual ~SliceVisitor() {} }; @@ -237,10 +237,10 @@ public: //###################################################################### // Link class functions -void V3Slice::sliceAll(AstNetlist* rootp) { +void V3Slice::sliceAll(AstNetlist* nodep) { UINFO(2,__FUNCTION__<<": "<= 3); } diff --git a/src/V3Split.cpp b/src/V3Split.cpp index 758b87dc1..b0d82cee1 100644 --- a/src/V3Split.cpp +++ b/src/V3Split.cpp @@ -183,8 +183,7 @@ public: static bool followCyclic(const V3GraphEdge* edgep) { const SplitEdge* oedgep = dynamic_cast(edgep); if (!oedgep) v3fatalSrc("Following edge of non-SplitEdge type"); - if (oedgep->ignoreThisStep()) return false; - return true; + return (!oedgep->ignoreThisStep()); } virtual string dotStyle() const { return ignoreThisStep() ? "dotted" : V3GraphEdge::dotStyle(); @@ -335,7 +334,7 @@ protected: if (!vertexp->outBeginp() && dynamic_cast(vertexp)) { if (debug() >= 9) { - SplitVarStdVertex* stdp = (SplitVarStdVertex*)(vertexp); + SplitVarStdVertex* stdp = static_cast(vertexp); UINFO(0, "Will prune deps on var "<nodep()<nodep()->dumpTree(cout, "- "); } @@ -388,10 +387,10 @@ protected: // Create vertexes for variable if (!vscp->user1p()) { - SplitVarStdVertex* vstdp = new SplitVarStdVertex(&m_graph, vscp); + SplitVarStdVertex* vstdp = new SplitVarStdVertex(&m_graph, vscp); vscp->user1p(vstdp); } - SplitVarStdVertex* vstdp = (SplitVarStdVertex*) vscp->user1p(); + SplitVarStdVertex* vstdp = reinterpret_cast(vscp->user1p()); // SPEEDUP: We add duplicate edges, that should be fixed if (m_inDly && nodep->lvalue()) { @@ -402,7 +401,8 @@ protected: vscp->user2p(vpostp); new SplitPostEdge(&m_graph, vstdp, vpostp); } - SplitVarPostVertex* vpostp = (SplitVarPostVertex*)vscp->user2p(); + SplitVarPostVertex* vpostp + = reinterpret_cast(vscp->user2p()); // Add edges for (VStack::iterator it = m_stmtStackps.begin(); it != m_stmtStackps.end(); ++it) { new SplitLVEdge(&m_graph, vpostp, *it); @@ -451,11 +451,9 @@ private: class ReorderVisitor : public SplitReorderBaseVisitor { // CONSTRUCTORS public: - explicit ReorderVisitor(AstNetlist* nodep) - : SplitReorderBaseVisitor() { - iterate(nodep); - } - + explicit ReorderVisitor(AstNetlist* nodep) { + iterate(nodep); + } virtual ~ReorderVisitor() {} // METHODS @@ -480,7 +478,7 @@ protected: // Vertex::m_user begin: true indicates logic for this step m_graph.userClearVertices(); for (AstNode* nextp=nodep; nextp; nextp=nextp->nextp()) { - SplitLogicVertex* vvertexp = (SplitLogicVertex*)nextp->user3p(); + SplitLogicVertex* vvertexp = reinterpret_cast(nextp->user3p()); vvertexp->user(true); } @@ -513,7 +511,7 @@ protected: // Add hard orderings between all nodes of same color, in the order they appeared vl_unordered_map lastOfColor; for (AstNode* nextp=nodep; nextp; nextp=nextp->nextp()) { - SplitLogicVertex* vvertexp = (SplitLogicVertex*)nextp->user3p(); + SplitLogicVertex* vvertexp = reinterpret_cast(nextp->user3p()); uint32_t color = vvertexp->color(); if (!color) nextp->v3fatalSrc("No node color assigned"); if (lastOfColor[color]) { @@ -539,7 +537,7 @@ protected: RankNodeMap rankMap; int currOrder = 0; // Existing sequence number of assignment for (AstNode* nextp=nodep; nextp; nextp=nextp->nextp()) { - SplitLogicVertex* vvertexp = (SplitLogicVertex*)nextp->user3p(); + SplitLogicVertex* vvertexp = reinterpret_cast(nextp->user3p()); rankMap.insert(make_pair(vvertexp->rank(), nextp)); nextp->user4(++currOrder); // Record current ordering } @@ -593,9 +591,11 @@ protected: cleanupBlockGraph(nodep); reorderBlock(nodep); // Delete old vertexes and edges only applying to this block - while (firstp->backp()->nextp()==firstp) firstp = firstp->backp(); // Walk back to first in list + // First, walk back to first in list + while (firstp->backp()->nextp()==firstp) firstp = firstp->backp(); for (AstNode* nextp=firstp; nextp; nextp=nextp->nextp()) { - SplitLogicVertex* vvertexp = (SplitLogicVertex*)nextp->user3p(); + SplitLogicVertex* vvertexp + = reinterpret_cast(nextp->user3p()); vvertexp->unlinkDelete(&m_graph); } } @@ -662,7 +662,7 @@ protected: virtual void visit(AstNode* nodep) { if (nodep->user3p()) { - SplitLogicVertex* vertexp = (SplitLogicVertex*)(nodep->user3p()); + SplitLogicVertex* vertexp = reinterpret_cast(nodep->user3p()); uint32_t color = vertexp->color(); m_colors.insert(color); UINFO(8, " SVL " << vertexp << " has color " << color << "\n"); @@ -754,7 +754,7 @@ protected: if (!nodep->user3p()) nodep->v3fatalSrc("null user3p in V3Split leaf"); // Clone the leaf into its new always block - SplitLogicVertex* vxp = (SplitLogicVertex*)(nodep->user3p()); + SplitLogicVertex* vxp = reinterpret_cast(nodep->user3p()); uint32_t color = vxp->color(); AstNode* clonedp = nodep->cloneTree(false); m_addAfter[color]->addNextHere(clonedp); @@ -846,8 +846,7 @@ private: // CONSTRUCTORS public: explicit SplitVisitor(AstNetlist* nodep) - : SplitReorderBaseVisitor() - , m_curIfConditional(NULL) { + : m_curIfConditional(NULL) { iterate(nodep); // Splice newly-split blocks into the tree. Remove placeholders diff --git a/src/V3StatsReport.cpp b/src/V3StatsReport.cpp index dfefc9258..8016290f4 100644 --- a/src/V3StatsReport.cpp +++ b/src/V3StatsReport.cpp @@ -48,7 +48,7 @@ class StatsReport { os<(datap); } else { // If there are large inserts it would be more efficient to avoid this copy // by copying bytes in the loop below from either m_remainder or the data // as appropriate. - tempData = m_remainder + string((const char*)datap,length); - chunkLen = tempData.length(); - chunkp = (const uint8_t*)tempData.data(); + tempData = m_remainder + string(static_cast(datap), length); + chunkLen = tempData.length(); + chunkp = reinterpret_cast(tempData.data()); } // See wikipedia SHA-1 algorithm summary @@ -170,15 +174,15 @@ void VHashSha1::insert(const void* datap, size_t length) { posEnd = posBegin + 64; // 64 byte round input data, being careful to swap on big, keep on little for (int roundByte = 0; posBegin < posEnd; posBegin += 4) { - w[roundByte++] = ((uint32_t) chunkp[posBegin + 3] - | (((uint32_t) chunkp[posBegin + 2]) << 8) - | (((uint32_t) chunkp[posBegin + 1]) << 16) - | (((uint32_t) chunkp[posBegin]) << 24)); + w[roundByte++] = (static_cast(chunkp[posBegin + 3]) + | (static_cast(chunkp[posBegin + 2]) << 8) + | (static_cast(chunkp[posBegin + 1]) << 16) + | (static_cast(chunkp[posBegin]) << 24)); } sha1Block(m_inthash, w); } - m_remainder = string((const char*)(chunkp+posBegin), chunkLen-posEnd); + m_remainder = string(reinterpret_cast(chunkp+posBegin), chunkLen-posEnd); } void VHashSha1::finalize() { @@ -192,7 +196,8 @@ void VHashSha1::finalize() { for (int i=0; i<16; ++i) w[i] = 0; size_t blockPos = 0; for (; blockPos < m_remainder.length(); ++blockPos) { - w[blockPos >> 2] |= ((uint32_t) m_remainder[blockPos]) << ((3 - (blockPos & 3)) << 3); + w[blockPos >> 2] |= ((static_cast(m_remainder[blockPos])) + << ((3 - (blockPos & 3)) << 3)); } w[blockPos >> 2] |= 0x80 << ((3 - (blockPos & 3)) << 3); if (m_remainder.length() >= 56) { @@ -248,9 +253,9 @@ string VHashSha1::digestSymbol() { for (; pos < (160/8) - 2; pos += 3) { out += digits[((binhash[pos] >> 2) & 0x3f)]; out += digits[((binhash[pos] & 0x3) << 4) - | ((int) (binhash[pos + 1] & 0xf0) >> 4)]; + | (static_cast(binhash[pos + 1] & 0xf0) >> 4)]; out += digits[((binhash[pos + 1] & 0xf) << 2) - | ((int) (binhash[pos + 2] & 0xc0) >> 6)]; + | (static_cast(binhash[pos + 2] & 0xc0) >> 6)]; out += digits[((binhash[pos + 2] & 0x3f))]; } if (0) { // Not needed for 160 bit hash @@ -260,7 +265,7 @@ string VHashSha1::digestSymbol() { else { out += digits[((binhash[pos] >> 2) & 0x3f)]; out += digits[((binhash[pos] & 0x3) << 4) - | ((int) (binhash[pos + 1] & 0xf0) >> 4)]; + | (static_cast(binhash[pos + 1] & 0xf0) >> 4)]; out += digits[((binhash[pos + 1] & 0xf) << 2)]; } return out; diff --git a/src/V3Subst.cpp b/src/V3Subst.cpp index 96bf0afcb..04a01bd10 100644 --- a/src/V3Subst.cpp +++ b/src/V3Subst.cpp @@ -83,7 +83,6 @@ public: // CONSTRUCTORS explicit SubstVarEntry(AstVar* varp) { // Construction for when a var is used m_varp = varp; - m_whole.m_use = false; m_wordAssign = false; m_wordUse = false; m_words.resize(varp->widthWords()); @@ -116,11 +115,11 @@ public: m_words[word].m_step = step; } } - void assignWordComplex(int step, int word) { + void assignWordComplex(int word) { if (!wordNumOk(word) || getWordAssignp(word) || m_words[word].m_complex) m_whole.m_complex = true; m_words[word].m_complex = true; } - void assignComplex(int step) { + void assignComplex() { m_whole.m_complex = true; } void consumeWhole() { //==consumeComplex as we don't know the difference @@ -187,7 +186,7 @@ private: // METHODS SubstVarEntry* findEntryp(AstVarRef* nodep) { - return (SubstVarEntry*)(nodep->varp()->user1p()); // Might be NULL + return reinterpret_cast(nodep->varp()->user1p()); // Might be NULL } // VISITORS virtual void visit(AstVarRef* nodep) { @@ -249,7 +248,7 @@ private: nodep->varp()->user1p(entryp); return entryp; } else { - SubstVarEntry* entryp = (SubstVarEntry*)(nodep->varp()->user1p()); + SubstVarEntry* entryp = reinterpret_cast(nodep->varp()->user1p()); return entryp; } } @@ -269,7 +268,7 @@ private: hit = true; if (m_ops > SUBST_MAX_OPS_SUBST) { UINFO(8," ASSIGNtooDeep "<assignComplex(m_assignStep); + entryp->assignComplex(); } else { UINFO(8," ASSIGNwhole "<assignWhole(m_assignStep, nodep); @@ -285,7 +284,7 @@ private: hit = true; if (m_ops > SUBST_MAX_OPS_SUBST) { UINFO(8," ASSIGNtooDeep "<assignWordComplex(m_assignStep, word); + entryp->assignWordComplex(word); } else { UINFO(8," ASSIGNword"<assignWord(m_assignStep, word, nodep); @@ -346,7 +345,7 @@ private: SubstVarEntry* entryp = getEntryp(nodep); if (nodep->lvalue()) { UINFO(8," ASSIGNcpx "<assignComplex(m_assignStep); + entryp->assignComplex(); } else if (AstNode* substp = entryp->substWhole(nodep)) { // Check that the RHS hasn't changed value since we recorded it. SubstUseVisitor visitor (substp, entryp->getWholeStep()); diff --git a/src/V3TSP.cpp b/src/V3TSP.cpp index 2536aa827..028fce0f7 100644 --- a/src/V3TSP.cpp +++ b/src/V3TSP.cpp @@ -430,7 +430,7 @@ void V3TSP::tspSort(const V3TSP::StateVec& states, V3TSP::StateVec* resultp) { // Make this TSP implementation work for graphs of size 0 or 1 // which, unfortunately, is a special case as the following // code assumes >= 2 nodes. - if (states.size() == 0) { + if (states.empty()) { return; } if (states.size() == 1) { @@ -550,7 +550,7 @@ public: unsigned xabs, yabs; xabs = diff(otherp->m_xpos, m_xpos); yabs = diff(otherp->m_ypos, m_ypos); - return (int)(0.5 + sqrt(xabs*xabs + yabs*yabs)); + return lround(sqrt(xabs*xabs + yabs*yabs)); } unsigned xpos() const { return m_xpos; diff --git a/src/V3Table.cpp b/src/V3Table.cpp index 8edb7b27c..d5d8adf4f 100644 --- a/src/V3Table.cpp +++ b/src/V3Table.cpp @@ -119,8 +119,8 @@ private: // Calc data storage in bytes size_t chgWidth = m_outVarps.size(); // Width of one change-it-vector if (chgWidth<8) chgWidth = 8; - double space = (pow((double)2,((double)(m_inWidth))) - *(double)(m_outWidth+chgWidth)); + double space = (pow(static_cast(2.0), static_cast(m_inWidth)) + * static_cast(m_outWidth + chgWidth)); // Instruction count bytes (ok, it's space also not time :) double bytesPerInst = 4; double time = (chkvis.instrCount()*bytesPerInst + chkvis.dataCount()) + 1; // +1 so won't div by zero @@ -377,9 +377,10 @@ private: AstNode* arhsp = new AstArraySel(nodep->fileline(), new AstVarRef(nodep->fileline(), m_tableVarps[outnum], false), new AstVarRef(nodep->fileline(), indexVscp, false)); - AstNode* outasnp = (m_assignDly - ? (AstNode*)(new AstAssignDly(nodep->fileline(), alhsp, arhsp)) - : (AstNode*)(new AstAssign(nodep->fileline(), alhsp, arhsp))); + AstNode* outasnp + = (m_assignDly + ? static_cast(new AstAssignDly(nodep->fileline(), alhsp, arhsp)) + : static_cast(new AstAssign(nodep->fileline(), alhsp, arhsp))); AstNode* outsetp = outasnp; // Is the value set in only some branches of the table? diff --git a/src/V3Task.cpp b/src/V3Task.cpp index 23d8454b6..406118d3b 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -767,7 +767,7 @@ private: string stmt = "return "+rtnvarp->name()+";\n"; dpip->addStmtsp(new AstCStmt(nodep->fileline(), stmt)); } - makePortList(nodep, rtnvarp, dpip); + makePortList(nodep, dpip); } void makeDpiImportProto(AstNodeFTask* nodep, AstVar* rtnvarp) { @@ -789,7 +789,7 @@ private: dpip->dpiImport(true); // Add DPI reference to top, since it's a global function m_topScopep->scopep()->addActivep(dpip); - makePortList(nodep, rtnvarp, dpip); + makePortList(nodep, dpip); } bool duplicatedDpiProto(AstNodeFTask* nodep, const string& dpiproto) { @@ -811,7 +811,7 @@ private: } } - void makePortList(AstNodeFTask* nodep, AstVar* rtnvarp, AstCFunc* dpip) { + void makePortList(AstNodeFTask* nodep, AstCFunc* dpip) { // Copy nodep's list of function I/O to the new dpip c function for (AstNode* stmtp = nodep->stmtsp(); stmtp; stmtp=stmtp->nextp()) { if (AstVar* portp = VN_CAST(stmtp, Var)) { @@ -963,7 +963,7 @@ private: rtnvarp->user2p(rtnvscp); } - string prefix = ""; + string prefix; if (nodep->dpiImport()) prefix = "__Vdpiimwrap_"; else if (nodep->dpiExport()) prefix = "__Vdpiexp_"; else if (ftaskNoInline) prefix = "__VnoInFunc_"; @@ -1292,7 +1292,7 @@ V3TaskConnects V3Task::taskConnects(AstNodeFTaskRef* nodep, AstNode* taskStmtsp) for (AstNode* stmtp = taskStmtsp; stmtp; stmtp=stmtp->nextp()) { if (AstVar* portp = VN_CAST(stmtp, Var)) { if (portp->isIO()) { - tconnects.push_back(make_pair(portp, (AstArg*)NULL)); + tconnects.push_back(make_pair(portp, static_cast(NULL))); nameToIndex.insert(make_pair(portp->name(), tpinnum)); // For name based connections tpinnum++; if (portp->attrSFormat()) { @@ -1330,7 +1330,7 @@ V3TaskConnects V3Task::taskConnects(AstNodeFTaskRef* nodep, AstNode* taskStmtsp) } else { // By pin number if (ppinnum >= tpinnum) { if (sformatp) { - tconnects.push_back(make_pair(sformatp, (AstArg*)NULL)); + tconnects.push_back(make_pair(sformatp, static_cast(NULL))); tconnects[ppinnum].second = argp; tpinnum++; } else { diff --git a/src/V3TraceDecl.cpp b/src/V3TraceDecl.cpp index 660b6fb31..4a9a55e29 100644 --- a/src/V3TraceDecl.cpp +++ b/src/V3TraceDecl.cpp @@ -71,7 +71,7 @@ private: } else if (!v3Global.opt.traceUnderscore()) { string prettyName = varp->prettyName(); - if (prettyName.size()>=1 && prettyName[0] == '_') + if (!prettyName.empty() && prettyName[0] == '_') return "Leading underscore"; if (prettyName.find("._") != string::npos) return "Inlined leading underscore"; @@ -192,7 +192,7 @@ private: virtual void visit(AstUnpackArrayDType* nodep) { // Note more specific dtypes above if (m_traVscp) { - if ((int)nodep->arrayUnpackedElements() > v3Global.opt.traceMaxArray()) { + if (static_cast(nodep->arrayUnpackedElements()) > v3Global.opt.traceMaxArray()) { addIgnore("Wide memory > --trace-max-array ents"); } else if (VN_IS(nodep->subDTypep()->skipRefp(), BasicDType) // Nothing lower than this array && m_traVscp->dtypep()->skipRefp() == nodep) { // Nothing above this array diff --git a/src/V3Tristate.cpp b/src/V3Tristate.cpp index 3ada7ebaa..4d039c61f 100644 --- a/src/V3Tristate.cpp +++ b/src/V3Tristate.cpp @@ -141,7 +141,7 @@ private: VL_DEBUG_FUNC; // Declare debug() TristateVertex* makeVertex(AstNode* nodep) { - TristateVertex* vertexp = (TristateVertex*)(nodep->user5p()); + TristateVertex* vertexp = reinterpret_cast(nodep->user5p()); if (!vertexp) { UINFO(6," New vertex "<=9) m_graph.dumpDotFilePrefixed("tri_pre__"+nodep->name()); UINFO(9," Walking "<verticesNextp()) { - graphWalkRecurseFwd((TristateVertex*)itp, 0); + graphWalkRecurseFwd(static_cast(itp), 0); } for (V3GraphVertex* itp = m_graph.verticesBeginp(); itp; itp=itp->verticesNextp()) { - graphWalkRecurseBack((TristateVertex*)itp, 0); + graphWalkRecurseBack(static_cast(itp), 0); } if (debug()>=9) m_graph.dumpDotFilePrefixed("tri_pos__"+nodep->name()); } @@ -238,15 +238,15 @@ public: new V3GraphEdge(&m_graph, makeVertex(fromp), makeVertex(top), 1); } bool isTristate(AstNode* nodep) { - TristateVertex* vertexp = (TristateVertex*)(nodep->user5p()); + TristateVertex* vertexp = reinterpret_cast(nodep->user5p()); return vertexp && vertexp->isTristate(); } bool feedsTri(AstNode* nodep) { - TristateVertex* vertexp = (TristateVertex*)(nodep->user5p()); + TristateVertex* vertexp = reinterpret_cast(nodep->user5p()); return vertexp && vertexp->feedsTri(); } void didProcess(AstNode* nodep) { - TristateVertex* vertexp = (TristateVertex*)(nodep->user5p()); + TristateVertex* vertexp = reinterpret_cast(nodep->user5p()); if (!vertexp) { // Not v3errorSrc as no reason to stop the world nodep->v3error("Unsupported tristate construct (not in propagation graph): "<prettyTypeName()); @@ -441,7 +441,7 @@ class TristateVisitor : public TristateBaseVisitor { } void setPullDirection(AstVar* varp, AstPull* pullp) { - AstPull* oldpullp = (AstPull*)varp->user3p(); + AstPull* oldpullp = static_cast(varp->user3p()); if (!oldpullp) { varp->user3p(pullp); //save off to indicate the pull direction } else { @@ -599,7 +599,7 @@ class TristateVisitor : public TristateBaseVisitor { // This is the final resolution of the tristate, so we apply // the pull direction to any undriven pins. V3Number pull(invarp->fileline(), lhsp->width()); - AstPull* pullp = (AstPull*)lhsp->user3p(); + AstPull* pullp = static_cast(lhsp->user3p()); if (pullp && pullp->direction() == 1) { pull.setAllBits1(); UINFO(9,"Has pullup "<user2() & U2_GRAPHING) return; // This pin is already expanded nodep->user2(U2_GRAPHING); // Find child module's new variables. - AstVar* enModVarp = (AstVar*) nodep->modVarp()->user1p(); + AstVar* enModVarp = static_cast(nodep->modVarp()->user1p()); if (!enModVarp) { if (nodep->exprp()) { // May have an output only that later connects to a tristate, so simplify now. @@ -1116,7 +1116,7 @@ class TristateVisitor : public TristateBaseVisitor { // Create new output pin AstAssignW* outAssignp = NULL; // If reconnected, the related assignment AstPin* outpinp = NULL; - AstVar* outModVarp = (AstVar*) nodep->modVarp()->user4p(); + AstVar* outModVarp = static_cast(nodep->modVarp()->user4p()); if (!outModVarp) { // At top, no need for __out as might be input only. Otherwise resolvable. if (!m_modp->isTop()) nodep->v3fatalSrc("Unlinked"); @@ -1176,7 +1176,7 @@ class TristateVisitor : public TristateBaseVisitor { // Propagate any pullups/pulldowns upwards if necessary if (exprrefp) { - if (AstPull* pullp = (AstPull*) nodep->modVarp()->user3p()) { + if (AstPull* pullp = static_cast(nodep->modVarp()->user3p())) { UINFO(9, "propagate pull on "<varp(), pullp); } diff --git a/src/V3Undriven.cpp b/src/V3Undriven.cpp index 7765736b3..2f836f47d 100644 --- a/src/V3Undriven.cpp +++ b/src/V3Undriven.cpp @@ -70,7 +70,8 @@ public: private: // METHODS - inline bool bitNumOk(int bit) const { return bit>=0 && (bit*FLAGS_PER_BIT < (int)m_flags.size()); } + inline bool bitNumOk(int bit) const { return bit>=0 + && (bit*FLAGS_PER_BIT < static_cast(m_flags.size())); } inline bool usedFlag(int bit) const { return m_usedWhole || m_flags[bit*FLAGS_PER_BIT + FLAG_USED]; } inline bool drivenFlag(int bit) const { return m_drivenWhole || m_flags[bit*FLAGS_PER_BIT + FLAG_DRIVEN]; } enum BitNamesWhich { BN_UNUSED, BN_UNDRIVEN, BN_BOTH }; @@ -248,7 +249,8 @@ private: else nodep->v3fatalSrc("Bad case"); return entryp; } else { - UndrivenVarEntry* entryp = (UndrivenVarEntry*)(which_user==1 ? nodep->user1p() : nodep->user2p()); + UndrivenVarEntry* entryp = reinterpret_cast + (which_user==1 ? nodep->user1p() : nodep->user2p()); return entryp; } } diff --git a/src/V3Unknown.cpp b/src/V3Unknown.cpp index 77035aabb..348b92f79 100644 --- a/src/V3Unknown.cpp +++ b/src/V3Unknown.cpp @@ -190,9 +190,9 @@ private: lhsp->deleteTree(); VL_DANGLING(lhsp); rhsp->deleteTree(); VL_DANGLING(rhsp); } else { - if (VN_IS(nodep, EqCase)) - newp = new AstEq(nodep->fileline(), lhsp, rhsp); - else newp = new AstNeq(nodep->fileline(), lhsp, rhsp); + if (VN_IS(nodep, EqCase)) { + newp = new AstEq(nodep->fileline(), lhsp, rhsp); + } else { newp = new AstNeq(nodep->fileline(), lhsp, rhsp); } } nodep->replaceWith(newp); nodep->deleteTree(); VL_DANGLING(nodep); @@ -225,9 +225,9 @@ private: AstNode* and1p = new AstAnd(nodep->fileline(), lhsp, new AstConst(nodep->fileline(), nummask)); AstNode* and2p = new AstConst(nodep->fileline(), numval); - if (VN_IS(nodep, EqWild)) + if (VN_IS(nodep, EqWild)) { newp = new AstEq(nodep->fileline(), and1p, and2p); - else newp = new AstNeq(nodep->fileline(), and1p, and2p); + } else { newp = new AstNeq(nodep->fileline(), and1p, and2p); } rhsp->deleteTree(); VL_DANGLING(rhsp); } nodep->replaceWith(newp); diff --git a/src/V3Width.cpp b/src/V3Width.cpp index a276d0b8f..c0202be5a 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -86,7 +86,9 @@ //###################################################################### enum Stage { PRELIM=1,FINAL=2,BOTH=3 }; // Numbers are a bitmask <0>=prelim, <1>=final -std::ostream& operator<<(std::ostream& str, const Stage& rhs) { return str<<("-PFB"[(int)rhs]); } +std::ostream& operator<<(std::ostream& str, const Stage& rhs) { + return str<<("-PFB"[static_cast(rhs)]); +} enum Determ { SELF, // Self-determined @@ -1644,9 +1646,9 @@ private: for (int i = 0; i < arrayType->elementsConst(); ++i) { AstNode* arrayRef = nodep->fromp()->cloneTree(false); AstNode* selector = new AstArraySel(fl, arrayRef, i); - if (!newp) + if (!newp) { newp = selector; - else { + } else { switch (methodId) { case ARRAY_OR: newp = new AstOr(fl, newp, selector); break; case ARRAY_AND: newp = new AstAnd(fl, newp, selector); break; diff --git a/src/V3WidthSel.cpp b/src/V3WidthSel.cpp index 71519b767..b9464f31f 100644 --- a/src/V3WidthSel.cpp +++ b/src/V3WidthSel.cpp @@ -69,11 +69,11 @@ private: AstNode* m_errp; // Node that was found, for error reporting if not known type AstNodeDType* m_dtypep; // Data type for the 'from' slice VNumRange m_fromRange; // Numeric range bounds for the 'from' slice - FromData(AstNode* errp, AstNodeDType* dtypep, VNumRange fromRange) + FromData(AstNode* errp, AstNodeDType* dtypep, const VNumRange& fromRange) { m_errp=errp; m_dtypep=dtypep; m_fromRange=fromRange; } ~FromData() {} }; - FromData fromDataForArray(AstNode* nodep, AstNode* basefromp, bool rangedSelect) { + FromData fromDataForArray(AstNode* nodep, AstNode* basefromp) { // What is the data type and information for this SEL-ish's from()? UINFO(9," fromData start ddtypep = "<lhsp()->unlinkFrBack(); AstNode* rhsp = nodep->rhsp()->unlinkFrBack(); // bit we're extracting if (debug()>=9) nodep->dumpTree(cout,"--SELBT2: "); - FromData fromdata = fromDataForArray(nodep, fromp, false); + FromData fromdata = fromDataForArray(nodep, fromp); AstNodeDType* ddtypep = fromdata.m_dtypep; VNumRange fromRange = fromdata.m_fromRange; UINFO(6," ddtypep "<toSInt(); vlsint32_t lsb = VN_CAST(lsbp, Const)->toSInt(); vlsint32_t elem = (msb>lsb) ? (msb-lsb+1) : (lsb-msb+1); - FromData fromdata = fromDataForArray(nodep, fromp, false); + FromData fromdata = fromDataForArray(nodep, fromp); AstNodeDType* ddtypep = fromdata.m_dtypep; VNumRange fromRange = fromdata.m_fromRange; if (VN_IS(ddtypep, UnpackArrayDType)) { @@ -331,7 +331,7 @@ private: newp->declElWidth(elwidth); newp->dtypeFrom(sliceDType(adtypep, msb, lsb)); //if (debug()>=9) newp->dumpTree(cout,"--EXTBTn: "); - if (newp->widthMin()!=(int)newp->widthConst()) nodep->v3fatalSrc("Width mismatch"); + if (newp->widthMin() != newp->widthConst()) nodep->v3fatalSrc("Width mismatch"); nodep->replaceWith(newp); pushDeletep(nodep); VL_DANGLING(nodep); } else if (VN_IS(ddtypep, BasicDType)) { @@ -402,7 +402,7 @@ private: int width = VN_CAST(widthp, Const)->toSInt(); if (width > (1<<28)) nodep->v3error("Width of :+ or :- is huge; vector of over 1billion bits: "<prettyName()); if (width<0) nodep->v3error("Width of :+ or :- is < 0: "<prettyName()); - FromData fromdata = fromDataForArray(nodep, fromp, width!=1); + FromData fromdata = fromDataForArray(nodep, fromp); AstNodeDType* ddtypep = fromdata.m_dtypep; VNumRange fromRange = fromdata.m_fromRange; if (VN_IS(ddtypep, BasicDType) diff --git a/src/Verilator.cpp b/src/Verilator.cpp index 37506f5e2..95b8a6617 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -566,7 +566,7 @@ int main(int argc, char** argv, char** env) { time_t randseed; time(&randseed); - srand( (int) randseed); + srand(static_cast(randseed)); // Post-constructor initialization of netlists v3Global.boot(); diff --git a/src/VlcMain.cpp b/src/VlcMain.cpp index 2b8af1a6b..611006729 100644 --- a/src/VlcMain.cpp +++ b/src/VlcMain.cpp @@ -171,7 +171,7 @@ int main(int argc, char** argv, char** env) { } V3Error::abortIfWarnings(); - if (top.opt.annotateOut() != "") { + if (!top.opt.annotateOut().empty()) { top.annotate(top.opt.annotateOut()); } @@ -180,7 +180,7 @@ int main(int argc, char** argv, char** env) { top.tests().dump(false); } - if (top.opt.writeFile() != "") { + if (!top.opt.writeFile().empty()) { top.writeCoverage(top.opt.writeFile()); V3Error::abortIfWarnings(); if (top.opt.unlink()) { diff --git a/src/VlcOptions.h b/src/VlcOptions.h index 1aab326e4..ac896eb80 100644 --- a/src/VlcOptions.h +++ b/src/VlcOptions.h @@ -26,9 +26,9 @@ #include "config_rev.h" -#include #include #include +#include //###################################################################### // V3Options - Command line options diff --git a/src/VlcTop.cpp b/src/VlcTop.cpp index 7d6d95226..84dc3e0b1 100644 --- a/src/VlcTop.cpp +++ b/src/VlcTop.cpp @@ -150,11 +150,11 @@ void VlcTop::annotateCalc() { const VlcPoint& point = m_points.pointNumber(it->second); string filename = point.filename(); int lineno = point.lineno(); - if (filename!="" && lineno!=0) { + if (!filename.empty() && lineno!=0) { int column = point.column(); VlcSource& source = sources().findNewSource(filename); string threshStr = point.thresh(); - unsigned thresh = (threshStr!="") ? atoi(threshStr.c_str()) : opt.annotateMin(); + unsigned thresh = (!threshStr.empty()) ? atoi(threshStr.c_str()) : opt.annotateMin(); bool ok = (point.count() >= thresh); UINFO(9, "AnnoCalc count "<{verbose} && !$btab; $btab = 1; } + elsif ($line =~ m!^\+(.*)!) { + my $len = length($1); + if ($len >= 100) { + print" Wide $line\n" if $Self->{verbose}; + $warns{$file} = "File modification adds a new >100 column line: $file"; + } + } } } if (keys %warns) {