diff --git a/Makefile.in b/Makefile.in index f1b09115a..68f79c0ad 100644 --- a/Makefile.in +++ b/Makefile.in @@ -438,7 +438,7 @@ CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src cppcheck: $(CPPCHECK_DEP) %.cppcheck: %.cpp - $(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 $(CPPCHECK_INC) $< + $(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 -DVL_THREADED=1 $(CPPCHECK_INC) $< CLANGTIDY = clang-tidy CLANGTIDY_FLAGS = -config='' diff --git a/include/verilated.cpp b/include/verilated.cpp index 1d69650da..4566ef242 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -40,7 +40,8 @@ #endif // clang-format on -#define VL_VALUE_STRING_MAX_WIDTH 8192 ///< Max static char array for VL_VALUE_STRING +/// Max static char array for VL_VALUE_STRING +constexpr unsigned VL_VALUE_STRING_MAX_WIDTH = 8192; //=========================================================================== // Static sanity checks (when get C++11 can use static_assert) @@ -764,8 +765,8 @@ void _vl_vsformat(std::string& output, const char* formatp, va_list ap) VL_MT_SA if (!widthSet) width = VerilatedImp::timeFormatWidth(); output += _vl_vsformat_time(tmp, d, left, width); } else { - std::string fmt(pctp, pos - pctp + 1); - sprintf(tmp, fmt.c_str(), d); + std::string fmts(pctp, pos - pctp + 1); + sprintf(tmp, fmts.c_str(), d); output += tmp; } break; @@ -1699,7 +1700,7 @@ IData VL_ATOI_N(const std::string& str, int base) VL_PURE { str_mod.erase(std::remove(str_mod.begin(), str_mod.end(), '_'), str_mod.end()); errno = 0; - long v = std::strtol(str_mod.c_str(), nullptr, base); + auto v = std::strtol(str_mod.c_str(), nullptr, base); if (errno != 0) v = 0; return static_cast(v); } diff --git a/include/verilated_vcd_c.cpp b/include/verilated_vcd_c.cpp index 863195546..ce26b6c62 100644 --- a/include/verilated_vcd_c.cpp +++ b/include/verilated_vcd_c.cpp @@ -51,13 +51,14 @@ // This size comes form VCD allowing use of printable ASCII characters between // '!' and '~' inclusive, which are a total of 94 different values. Encoding a // 32 bit code hence needs a maximum of ceil(log94(2**32-1)) == 5 bytes. -#define VL_TRACE_MAX_VCD_CODE_SIZE 5 ///< Maximum length of a VCD string code +constexpr unsigned VL_TRACE_MAX_VCD_CODE_SIZE = 5; ///< Maximum length of a VCD string code + // We use 8 bytes per code in a suffix buffer array. // 1 byte optional separator + VL_TRACE_MAX_VCD_CODE_SIZE bytes for code // + 1 byte '\n' + 1 byte suffix size. This luckily comes out to a power of 2, // meaning the array can be aligned such that entries never straddle multiple // cache-lines. -#define VL_TRACE_SUFFIX_ENTRY_SIZE 8 ///< Size of a suffix entry +constexpr unsigned VL_TRACE_SUFFIX_ENTRY_SIZE = 8; ///< Size of a suffix entry //============================================================================= // Specialization of the generics for this trace format diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index bf4258854..63b34ec55 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -100,7 +100,7 @@ private: void dumpHeader(); - char* writeCode(char* writep, vluint32_t code); + static char* writeCode(char* writep, vluint32_t code); void finishLine(vluint32_t code, char* writep); diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 165195bbf..af90e2cbf 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -35,7 +35,7 @@ // Internal constants #define VL_DEBUG_IF_PLI VL_DEBUG_IF -#define VL_VPI_LINE_SIZE 8192 +constexpr unsigned VL_VPI_LINE_SIZE = 8192; //====================================================================== // Internal macros @@ -246,7 +246,7 @@ public: vluint32_t mask() const { return m_mask.u32; } vluint8_t mask_byte(int idx) { return m_mask.u8[idx & 3]; } vluint32_t entSize() const { return m_entSize; } - vluint32_t index() { return m_index; } + vluint32_t index() const { return m_index; } virtual vluint32_t type() const override { return (varp()->dims() > 1) ? vpiMemory : vpiReg; // but might be wire, logic } @@ -1606,7 +1606,6 @@ void vl_get_value(const VerilatedVar* varp, void* varDatap, p_vpi_value valuep, } _VL_VPI_ERROR(__FILE__, __LINE__, "%s: Unsupported format (%s) as requested for %s", VL_FUNC, VerilatedVpiError::strFromVpiVal(valuep->format), fullname); - return; } void vpi_get_value(vpiHandle object, p_vpi_value valuep) { @@ -1708,7 +1707,7 @@ vpiHandle vpi_put_value(vpiHandle object, p_vpi_value valuep, p_vpi_time /*time_ for (int i = 0; i < chars; ++i) { union { char byte[2]; - short half; + vluint16_t half; } val; idx = div(i * 3, 8); if (i < len) { diff --git a/src/V3Active.cpp b/src/V3Active.cpp index ad06c7280..7b0124922 100644 --- a/src/V3Active.cpp +++ b/src/V3Active.cpp @@ -129,7 +129,6 @@ public: return activep; } -public: // CONSTRUCTORS ActiveNamer() {} virtual ~ActiveNamer() override {} diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 4762b37fe..966902455 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -315,7 +315,7 @@ public: bool m_isRef; // Is it a reference? string m_type; // The base type, e.g.: "Foo_t"s string m_dims; // Array dimensions, e.g.: "[3][2][1]" - string render(const string& name) { + string render(const string& name) const { string out; out += m_type; out += " "; @@ -462,7 +462,7 @@ string AstVar::vlEnumDir() const { return out; } -string AstVar::vlPropDecl(string propName) const { +string AstVar::vlPropDecl(const string& propName) const { string out; std::vector ulims; // Unpacked dimension limits @@ -902,8 +902,9 @@ AstBasicDType* AstTypeTable::findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kw return newp; } -AstBasicDType* AstTypeTable::findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kwd, VNumRange range, - int widthMin, VSigning numeric) { +AstBasicDType* AstTypeTable::findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kwd, + const VNumRange& range, int widthMin, + VSigning numeric) { AstBasicDType* new1p = new AstBasicDType(fl, kwd, numeric, range, widthMin); AstBasicDType* newp = findInsertSameDType(new1p); if (newp != new1p) { diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index c5222666d..a1aba6567 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -2010,7 +2010,7 @@ public: string vlArgType(bool named, bool forReturn, bool forFunc, const string& namespc = "") const; string vlEnumType() const; // Return VerilatorVarType: VLVT_UINT32, etc string vlEnumDir() const; // Return VerilatorVarDir: VLVD_INOUT, etc - string vlPropDecl(string propName) const; // Return VerilatorVarProps declaration + string vlPropDecl(const string& propName) const; // Return VerilatorVarProps declaration void combineType(AstVarType type); virtual AstNodeDType* getChildDTypep() const override { return childDTypep(); } // op1 = Range of variable @@ -8840,7 +8840,7 @@ public: AstBasicDType* findBasicDType(FileLine* fl, AstBasicDTypeKwd kwd); AstBasicDType* findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kwd, int width, int widthMin, VSigning numeric); - AstBasicDType* findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kwd, VNumRange range, + AstBasicDType* findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kwd, const VNumRange& range, int widthMin, VSigning numeric); AstBasicDType* findInsertSameDType(AstBasicDType* nodep); void clearCache(); diff --git a/src/V3Broken.cpp b/src/V3Broken.cpp index b4e811342..4af93f4ec 100644 --- a/src/V3Broken.cpp +++ b/src/V3Broken.cpp @@ -49,6 +49,7 @@ private: enum { FLAG_LINKABLE = 0x04 }; // Is in netlist tree, can be linked to enum { FLAG_LEAKED = 0x08 }; // Known to have been leaked enum { FLAG_UNDER_NOW = 0x10 }; // Is in tree as parent of current node + public: // METHODS static void deleted(const AstNode* nodep) { @@ -188,7 +189,6 @@ public: } } -public: // CONSTRUCTORS BrokenTable() {} virtual ~BrokenTable() override {} @@ -239,7 +239,7 @@ public: class BrokenCheckVisitor : public AstNVisitor { private: - void checkWidthMin(const AstNode* nodep) { + static void checkWidthMin(const AstNode* nodep) { UASSERT_OBJ(nodep->width() == nodep->widthMin() || v3Global.widthMinUsage() != VWidthMinUsage::MATCHES_WIDTH, nodep, "Width != WidthMin"); diff --git a/src/V3Cdc.cpp b/src/V3Cdc.cpp index 6dac06e36..3e638c591 100644 --- a/src/V3Cdc.cpp +++ b/src/V3Cdc.cpp @@ -196,7 +196,7 @@ public: explicit CdcWidthVisitor(AstNode* nodep) { iterate(nodep); } virtual ~CdcWidthVisitor() override {} // ACCESSORS - int maxWidth() { + int maxWidth() const { size_t width = 1; width += m_maxFilenameLen; width += 1; // The : diff --git a/src/V3Changed.cpp b/src/V3Changed.cpp index e113ddf0a..df7e5d264 100644 --- a/src/V3Changed.cpp +++ b/src/V3Changed.cpp @@ -135,10 +135,10 @@ private: m_statep->m_numStmts += visitor.count(); } - virtual void visit(AstBasicDType* nodep) override { // + virtual void visit(AstBasicDType*) override { // newChangeDet(); } - virtual void visit(AstPackArrayDType* nodep) override { // + virtual void visit(AstPackArrayDType*) override { // newChangeDet(); } virtual void visit(AstUnpackArrayDType* nodep) override { diff --git a/src/V3Config.cpp b/src/V3Config.cpp index ba2acd323..a1e12f5f0 100644 --- a/src/V3Config.cpp +++ b/src/V3Config.cpp @@ -138,7 +138,7 @@ public: void setNoInline(bool set) { m_noinline = set; } void setPublic(bool set) { m_public = set; } - void apply(AstNodeFTask* ftaskp) { + void apply(AstNodeFTask* ftaskp) const { if (m_noinline) ftaskp->addStmtsp(new AstPragma(ftaskp->fileline(), AstPragmaType::NO_INLINE_TASK)); if (m_public) diff --git a/src/V3Coverage.cpp b/src/V3Coverage.cpp index 3651fa6e6..d795bb2bc 100644 --- a/src/V3Coverage.cpp +++ b/src/V3Coverage.cpp @@ -65,7 +65,7 @@ private: int m_handle = 0; // Opaque handle for index into line tracking const AstNode* m_nodep = nullptr; // Node establishing this state CheckState() {} - bool lineCoverageOn(const AstNode* nodep) { + bool lineCoverageOn(const AstNode* nodep) const { return m_on && !m_inModOff && nodep->fileline()->coverageOn() && v3Global.opt.coverageLine(); } diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 4dd03b268..926333b26 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -63,7 +63,7 @@ public: int splitSize() const { return m_splitSize; } void splitSizeInc(int count) { m_splitSize += count; } void splitSizeInc(AstNode* nodep) { splitSizeInc(EmitCBaseCounterVisitor(nodep).count()); } - bool splitNeeded() { + bool splitNeeded() const { return (splitSize() && v3Global.opt.outputSplit() && v3Global.opt.outputSplit() < splitSize()); } @@ -1222,18 +1222,16 @@ public: nodep->v3fatalSrc("Unknown node type reached emitter: " << nodep->prettyTypeName()); } - void init() { +public: + EmitCStmts() { m_suppressSemi = false; m_wideTempRefp = nullptr; m_labelNum = 0; m_splitSize = 0; m_splitFilenum = 0; } - -public: - EmitCStmts() { init(); } - EmitCStmts(AstNode* nodep, V3OutCFile* ofp, bool trackText = false) { - init(); + EmitCStmts(AstNode* nodep, V3OutCFile* ofp, bool trackText = false) + : EmitCStmts{} { m_ofp = ofp; m_trackText = trackText; iterate(nodep); @@ -2104,10 +2102,11 @@ void EmitCStmts::displayEmit(AstNode* nodep, bool isScan) { } // End puts(")"); - if (isStmt) + if (isStmt) { puts(";\n"); - else + } else { puts(" "); + } // Prep for next emitDispState.clear(); } diff --git a/src/V3EmitCMain.cpp b/src/V3EmitCMain.cpp index 279d8e48e..3d066bc1b 100644 --- a/src/V3EmitCMain.cpp +++ b/src/V3EmitCMain.cpp @@ -35,7 +35,7 @@ class EmitCMain : EmitCBaseVisitor { public: // CONSTRUCTORS - explicit EmitCMain(AstNetlist* nodep) { emitInt(); } + explicit EmitCMain(AstNetlist*) { emitInt(); } private: // MAIN METHOD diff --git a/src/V3EmitCMake.cpp b/src/V3EmitCMake.cpp index f7f088e3c..8139cd418 100644 --- a/src/V3EmitCMake.cpp +++ b/src/V3EmitCMake.cpp @@ -125,7 +125,11 @@ class CMakeEmitter { : "0"); *of << "\n### Sources...\n"; - std::vector classes_fast, classes_slow, support_fast, support_slow, global; + std::vector classes_fast; + std::vector classes_slow; + std::vector support_fast; + std::vector support_slow; + std::vector global; for (AstNodeFile* nodep = v3Global.rootp()->filesp(); nodep; nodep = VN_CAST(nodep->nextp(), NodeFile)) { AstCFile* cfilep = VN_CAST(nodep, CFile); diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 31e370a25..a9fae0745 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -120,7 +120,7 @@ class EmitCSyms : EmitCBaseVisitor { void emitDpiHdr(); void emitDpiImp(); - void nameCheck(AstNode* nodep) { + static void nameCheck(AstNode* nodep) { // Prevent GCC compile time error; name check all things that reach C++ code if (nodep->name() != "" && !(VN_IS(nodep, CFunc) @@ -139,7 +139,7 @@ class EmitCSyms : EmitCBaseVisitor { } } - string scopeSymString(const string& scpname) { + static string scopeSymString(const string& scpname) { string out = scpname; string::size_type pos; while ((pos = out.find("__PVT__")) != string::npos) out.replace(pos, 7, ""); @@ -150,7 +150,7 @@ class EmitCSyms : EmitCBaseVisitor { return out; } - string scopeDecodeIdentifier(const string& scpname) { + static string scopeDecodeIdentifier(const string& scpname) { string out = scpname; // Remove hierarchy string::size_type pos = out.rfind('.'); @@ -800,16 +800,16 @@ void EmitCSyms::emitSymImp() { if (varp->isParam()) { if (varp->vlEnumType() == "VLVT_STRING") { puts(", const_cast(static_cast("); - puts(varName.c_str()); + puts(varName); puts(".c_str())), "); } else { puts(", const_cast(static_cast(&("); - puts(varName.c_str()); + puts(varName); puts("))), "); } } else { puts(", &("); - puts(varName.c_str()); + puts(varName); puts("), "); } diff --git a/src/V3EmitV.cpp b/src/V3EmitV.cpp index f4702998f..3edcf44c9 100644 --- a/src/V3EmitV.cpp +++ b/src/V3EmitV.cpp @@ -147,7 +147,7 @@ class EmitVBaseVisitor : public EmitCBaseVisitor { iterateAndNextNull(nodep->rhsp()); if (!m_suppressSemi) puts(";\n"); } - virtual void visit(AstBreak* nodep) override { + virtual void visit(AstBreak*) override { putbs("break"); if (!m_suppressSemi) puts(";\n"); } @@ -201,7 +201,7 @@ class EmitVBaseVisitor : public EmitCBaseVisitor { puts(string("// ") + nodep->name() + "\n"); iterateChildren(nodep); } - virtual void visit(AstContinue* nodep) override { + virtual void visit(AstContinue*) override { putbs("continue"); if (!m_suppressSemi) puts(";\n"); } diff --git a/src/V3EmitXml.cpp b/src/V3EmitXml.cpp index 3d5e4e466..34b125bd8 100644 --- a/src/V3EmitXml.cpp +++ b/src/V3EmitXml.cpp @@ -144,19 +144,21 @@ class EmitXmlFileVisitor : public AstNVisitor { puts(" origName="); putsQuoted(nodep->origName()); // Attributes - if (nodep->attrClocker() == VVarAttrClocker::CLOCKER_YES) + if (nodep->attrClocker() == VVarAttrClocker::CLOCKER_YES) { puts(" clocker=\"true\""); - else if (nodep->attrClocker() == VVarAttrClocker::CLOCKER_NO) + } else if (nodep->attrClocker() == VVarAttrClocker::CLOCKER_NO) { puts(" clocker=\"false\""); + } if (nodep->attrClockEn()) puts(" clock_enable=\"true\""); if (nodep->attrIsolateAssign()) puts(" isolate_assignments=\"true\""); if (nodep->isSigPublic()) puts(" public=\"true\""); if (nodep->isSigUserRdPublic()) puts(" public_flat_rd=\"true\""); if (nodep->isSigUserRWPublic()) puts(" public_flat_rw=\"true\""); - if (nodep->isGParam()) + if (nodep->isGParam()) { puts(" param=\"true\""); - else if (nodep->isParam()) + } else if (nodep->isParam()) { puts(" localparam=\"true\""); + } if (nodep->attrScBv()) puts(" sc_bv=\"true\""); if (nodep->attrScClocked()) puts(" sc_clock=\"true\""); if (nodep->attrSFormat()) puts(" sformat=\"true\""); @@ -286,9 +288,7 @@ private: public: // CONSTRUCTORS ModuleFilesXmlVisitor(AstNetlist* nodep, std::ostream& os) - : m_os{os} - , m_modulesCovered{} - , m_nodeModules{} { + : m_os{os} { // Operate on whole netlist nodep->accept(*this); // Xml output diff --git a/src/V3Error.cpp b/src/V3Error.cpp index 14f2cd41d..ace1450a2 100644 --- a/src/V3Error.cpp +++ b/src/V3Error.cpp @@ -212,7 +212,7 @@ void V3Error::v3errorEnd(std::ostringstream& sstr, const string& locationStr) { s_messages.insert(msg); if (!locationStr.empty()) { string locationMsg = warnMore() + locationStr + "\n"; - size_t pos = msg.find("\n"); + size_t pos = msg.find('\n'); msg.insert(pos + 1, locationMsg); } // Output diff --git a/src/V3File.cpp b/src/V3File.cpp index 4281ce676..4f5607494 100644 --- a/src/V3File.cpp +++ b/src/V3File.cpp @@ -991,9 +991,9 @@ public: string protectIf(const string& old, bool doIt) { if (!v3Global.opt.protectIds() || old.empty() || !doIt) return old; const auto it = m_nameMap.find(old); - if (it != m_nameMap.end()) + if (it != m_nameMap.end()) { return it->second; - else { + } else { string out; if (v3Global.opt.debugProtect()) { // This lets us see the symbol being protected to debug cases diff --git a/src/V3Gate.cpp b/src/V3Gate.cpp index e227864d7..a7472ac38 100644 --- a/src/V3Gate.cpp +++ b/src/V3Gate.cpp @@ -1345,7 +1345,7 @@ private: } return VNUser(0); } - virtual VNUser visit(GateLogicVertex* lvertexp, VNUser vu) override { // + virtual VNUser visit(GateLogicVertex*, VNUser vu) override { // return VNUser(0); } diff --git a/src/V3Global.cpp b/src/V3Global.cpp index 914ac440b..2b8a627fe 100644 --- a/src/V3Global.cpp +++ b/src/V3Global.cpp @@ -39,7 +39,7 @@ void V3Global::shutdown() { VL_DO_CLEAR(delete m_hierPlanp, m_hierPlanp = nullptr); // delete nullptr is safe } -void V3Global::checkTree() { rootp()->checkTree(); } +void V3Global::checkTree() const { rootp()->checkTree(); } void V3Global::readFiles() { // NODE STATE diff --git a/src/V3Global.h b/src/V3Global.h index 351f0b2b5..7c307ba5c 100644 --- a/src/V3Global.h +++ b/src/V3Global.h @@ -108,7 +108,7 @@ public: // METHODS void readFiles(); - void checkTree(); + void checkTree() const; static void dumpCheckGlobalTree(const string& stagename, int newNumber = 0, bool doDump = true); void assertDTypesResolved(bool flag) { m_assertDTypesResolved = flag; } diff --git a/src/V3Graph.cpp b/src/V3Graph.cpp index e26121719..2ee8c5c9b 100644 --- a/src/V3Graph.cpp +++ b/src/V3Graph.cpp @@ -52,7 +52,7 @@ void V3GraphVertex::verticesPushBack(V3Graph* graphp) { m_vertices.pushBack(graphp->m_vertices, this); } -void V3GraphVertex::unlinkEdges(V3Graph* graphp) { +void V3GraphVertex::unlinkEdges(V3Graph*) { for (V3GraphEdge* edgep = outBeginp(); edgep; /*BELOW*/) { V3GraphEdge* nextp = edgep->outNextp(); edgep->unlinkDelete(); diff --git a/src/V3InstrCount.cpp b/src/V3InstrCount.cpp index 84fc8fac9..f01b10608 100644 --- a/src/V3InstrCount.cpp +++ b/src/V3InstrCount.cpp @@ -280,7 +280,7 @@ public: private: // METHODS - string indent() { return string(m_depth, ':') + " "; } + string indent() const { return string(m_depth, ':') + " "; } virtual void visit(AstNode* nodep) override { ++m_depth; if (unsigned costPlus1 = nodep->user4()) { diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 12212f3dd..2939484f4 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -717,7 +717,7 @@ class LinkDotFindVisitor : public AstNVisitor { int m_modBlockNum = 0; // Begin block number in module, 0=none seen // METHODS - int debug() { return LinkDotState::debug(); } + static int debug() { return LinkDotState::debug(); } void makeImplicitNew(AstClass* nodep) { AstFunc* newp = new AstFunc(nodep->fileline(), "new", nullptr, nullptr); @@ -1273,7 +1273,7 @@ private: LinkDotState* m_statep; // State to pass between visitors, including symbol table AstNodeModule* m_modp = nullptr; // Current module - int debug() { return LinkDotState::debug(); } + static int debug() { return LinkDotState::debug(); } void pinImplicitExprRecurse(AstNode* nodep) { // Under a pin, Check interconnect expression for a pin reference or a concat. @@ -1433,7 +1433,7 @@ class LinkDotScopeVisitor : public AstNVisitor { AstScope* m_scopep = nullptr; // The current scope VSymEnt* m_modSymp = nullptr; // Symbol entry for current module - int debug() { return LinkDotState::debug(); } + static int debug() { return LinkDotState::debug(); } // VISITs virtual void visit(AstNetlist* nodep) override { @@ -1586,7 +1586,7 @@ class LinkDotIfaceVisitor : public AstNVisitor { VSymEnt* m_curSymp; // Symbol Entry for current table, where to lookup/insert // METHODS - int debug() { return LinkDotState::debug(); } + static int debug() { return LinkDotState::debug(); } // VISITs virtual void visit(AstModport* nodep) override { @@ -1735,7 +1735,7 @@ private: } } m_ds; // State to preserve across recursions - int debug() { return LinkDotState::debug(); } + static int debug() { return LinkDotState::debug(); } // METHODS - Variables void createImplicitVar(VSymEnt* lookupSymp, AstVarRef* nodep, AstNodeModule* modp, @@ -2034,10 +2034,11 @@ private: AstNode* varEtcp = m_ds.m_dotp->lhsp()->unlinkFrBack(); AstNode* newp = new AstMemberSel(nodep->fileline(), varEtcp, VFlagChildDType(), nodep->name()); - if (m_ds.m_dotErr) + if (m_ds.m_dotErr) { nodep->unlinkFrBack(); // Avoid circular node loop on errors - else + } else { nodep->replaceWith(newp); + } VL_DO_DANGLING(pushDeletep(nodep), nodep); } else { // diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index e303bc78c..aeb1419d7 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -153,10 +153,11 @@ private: for (int i = msb; i != (lsb + increment); i += increment, offset_from_init++) { string name = nodep->name() + cvtToStr(i); AstNode* valuep = nullptr; - if (nodep->valuep()) + if (nodep->valuep()) { valuep = new AstAdd( nodep->fileline(), nodep->valuep()->cloneTree(true), new AstConst(nodep->fileline(), AstConst::Unsized32(), offset_from_init)); + } AstNode* newp = new AstEnumItem(nodep->fileline(), name, nullptr, valuep); if (addp) { addp = addp->addNextNull(newp); diff --git a/src/V3Number.cpp b/src/V3Number.cpp index bc4ca4cbc..902f1b2b6 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -1452,7 +1452,7 @@ V3Number& V3Number::opAtoN(const V3Number& lhs, int base) { str.erase(std::remove(str.begin(), str.end(), '_'), str.end()); errno = 0; - long v = std::strtol(str.c_str(), nullptr, base); + auto v = std::strtol(str.c_str(), nullptr, base); if (errno != 0) v = 0; return setLongS(static_cast(v)); } @@ -2161,11 +2161,7 @@ V3Number& V3Number::opExtendXZ(const V3Number& lhs, uint32_t lbits) { NUM_ASSERT_OP_ARGS1(lhs); NUM_ASSERT_LOGIC_ARGS1(lhs); setZero(); - for (int bit = 0; bit < width(); bit++) { - char extendWith = lhs.bitIsExtend(bit, lbits); - if (extendWith == '1' || extendWith == 1) extendWith = 0; - setBit(bit, lhs.bitIsExtend(bit, lbits)); - } + for (int bit = 0; bit < width(); bit++) { setBit(bit, lhs.bitIsExtend(bit, lbits)); } return *this; } diff --git a/src/V3Order.cpp b/src/V3Order.cpp index ebfb6d64e..3371c0aa2 100644 --- a/src/V3Order.cpp +++ b/src/V3Order.cpp @@ -398,7 +398,7 @@ public: explicit OrderClkAssVisitor(AstNode* nodep) { iterate(nodep); } virtual ~OrderClkAssVisitor() override {} // METHODS - bool isClkAss() { return m_clkAss; } + bool isClkAss() const { return m_clkAss; } }; //###################################################################### @@ -1958,9 +1958,10 @@ void OrderVisitor::process() { if (!v3Global.opt.mtasks()) { UINFO(2, " Construct Move Graph...\n"); processMoveBuildGraph(); - if (debug() >= 4) + if (debug() >= 4) { m_pomGraph.dumpDotFilePrefixed( "ordermv_start"); // Different prefix (ordermv) as it's not the same graph + } m_pomGraph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue); if (debug() >= 4) m_pomGraph.dumpDotFilePrefixed("ordermv_simpl"); diff --git a/src/V3Partition.cpp b/src/V3Partition.cpp index 58d1caa7a..d8937484e 100644 --- a/src/V3Partition.cpp +++ b/src/V3Partition.cpp @@ -873,14 +873,14 @@ public: m_totalGraphCost += vertexCost(vertexp); } } - void statsReport(const string& stage) { + void statsReport(const string& stage) const { V3Stats::addStat("MTask graph, " + stage + ", critical path cost", m_longestCpCost); V3Stats::addStat("MTask graph, " + stage + ", total graph cost", m_totalGraphCost); V3Stats::addStat("MTask graph, " + stage + ", mtask count", m_vertexCount); V3Stats::addStat("MTask graph, " + stage + ", edge count", m_edgeCount); V3Stats::addStat("MTask graph, " + stage + ", parallelism factor", parallelismFactor()); } - void debugReport() { + void debugReport() const { UINFO(0, " Critical path cost = " << m_longestCpCost << endl); UINFO(0, " Total graph cost = " << m_totalGraphCost << endl); UINFO(0, " MTask vertex count = " << m_vertexCount << endl); diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 08386e6cf..ec9047731 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -421,16 +421,18 @@ void V3PreProcImp::comment(const string& text) { bool vlcomment = false; if ((cp[0] == 'v' || cp[0] == 'V') && 0 == (strncmp(cp + 1, "erilator", 8))) { cp += strlen("verilator"); - if (*cp == '_') + if (*cp == '_') { fileline()->v3error("Extra underscore in meta-comment;" " use /*verilator {...}*/ not /*verilator_{...}*/"); + } vlcomment = true; } else if (0 == (strncmp(cp, "synopsys", strlen("synopsys")))) { cp += strlen("synopsys"); synth = true; - if (*cp == '_') + if (*cp == '_') { fileline()->v3error("Extra underscore in meta-comment;" " use /*synopsys {...}*/ not /*synopsys_{...}*/"); + } } else if (0 == (strncmp(cp, "cadence", strlen("cadence")))) { cp += strlen("cadence"); synth = true; diff --git a/src/V3PreShell.cpp b/src/V3PreShell.cpp index 60f0f4df7..b79a95348 100644 --- a/src/V3PreShell.cpp +++ b/src/V3PreShell.cpp @@ -110,6 +110,7 @@ protected: modfileline->language(v3Global.opt.fileLanguage(modfilename)); V3Parse::ppPushText( parsep, (string("`begin_keywords \"") + modfileline->language().ascii() + "\"\n")); + // FileLine tracks and frees modfileline } while (!s_preprocp->isEof()) { diff --git a/src/V3Slice.cpp b/src/V3Slice.cpp index 9730acdab..ccf559bbc 100644 --- a/src/V3Slice.cpp +++ b/src/V3Slice.cpp @@ -188,9 +188,9 @@ class SliceVisitor : public AstNVisitor { new AstArraySel(nodep->fileline(), nodep->rhsp()->cloneTree(false), index)), NodeBiop); - if (!logp) + if (!logp) { logp = clonep; - else { + } else { switch (nodep->type()) { case AstType::atEq: // FALLTHRU case AstType::atEqCase: diff --git a/src/V3Subst.cpp b/src/V3Subst.cpp index fea0122de..ac18e4d08 100644 --- a/src/V3Subst.cpp +++ b/src/V3Subst.cpp @@ -71,7 +71,7 @@ class SubstVarEntry { bool m_wordUse = false; // True if any individual word usage SubstVarWord m_whole; // Data for whole vector used at once std::vector m_words; // Data for every word, if multi word variable - int debug() { return SubstBaseVisitor::debug(); } + static int debug() { return SubstBaseVisitor::debug(); } public: // CONSTRUCTORS diff --git a/src/V3TraceDecl.cpp b/src/V3TraceDecl.cpp index 8d28ceede..9ee77694e 100644 --- a/src/V3TraceDecl.cpp +++ b/src/V3TraceDecl.cpp @@ -327,7 +327,7 @@ private: } } virtual void visit(AstEnumDType* nodep) override { iterate(nodep->skipRefp()); } - virtual void visit(AstNodeDType* nodep) override { + virtual void visit(AstNodeDType*) override { // Note more specific dtypes above if (!m_traVscp) return; addIgnore("Unsupported: data type"); diff --git a/src/V3Tristate.cpp b/src/V3Tristate.cpp index 164e1d9b6..84bb24574 100644 --- a/src/V3Tristate.cpp +++ b/src/V3Tristate.cpp @@ -943,7 +943,7 @@ class TristateVisitor : public TristateBaseVisitor { FileLine* fl = nodep->fileline(); V3Number oneIfEn = VN_CAST(constp->user1p(), Const) ->num(); // visit(AstConst) already split into en/ones - V3Number oneIfEnOne = constp->num(); + const V3Number& oneIfEnOne = constp->num(); AstVar* envarp = getCreateEnVarp(varrefp->varp()); AstNode* newp = new AstLogAnd( fl, new AstEq(fl, new AstConst(fl, oneIfEn), new AstVarRef(fl, envarp, false)), diff --git a/src/V3Unroll.cpp b/src/V3Unroll.cpp index c44e4520b..968a23c30 100644 --- a/src/V3Unroll.cpp +++ b/src/V3Unroll.cpp @@ -67,7 +67,7 @@ private: return false; } - int unrollCount() { + int unrollCount() const { return m_generate ? v3Global.opt.unrollCount() * 16 : v3Global.opt.unrollCount(); } diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 9083cb1af..8f86bf6d4 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -1820,11 +1820,13 @@ private: // TODO IEEE says assigning sized number that is not same size as enum is illegal } if (!itemp->valuep()) { - if (num.isEqZero() && itemp != nodep->itemsp()) + if (num.isEqZero() && itemp != nodep->itemsp()) { itemp->v3error("Enum value illegally wrapped around (IEEE 1800-2017 6.19)"); - if (num.isFourState()) + } + if (num.isFourState()) { itemp->v3error("Enum value that is unassigned cannot follow value with X/Zs " "(IEEE 1800-2017 6.19)"); + } if (!nodep->dtypep()->basicp() && !nodep->dtypep()->basicp()->keyword().isIntNumeric()) { itemp->v3error("Enum names without values only allowed on numeric types"); @@ -1835,9 +1837,10 @@ private: AstConst* constp = VN_CAST(itemp->valuep(), Const); if (constp->num().isFourState() && nodep->dtypep()->basicp() - && !nodep->dtypep()->basicp()->isFourstate()) + && !nodep->dtypep()->basicp()->isFourstate()) { itemp->v3error("Enum value with X/Zs cannot be assigned to non-fourstate type " "(IEEE 1800-2017 6.19)"); + } num.opAssign(constp->num()); // Look for duplicates if (inits.find(num) != inits.end()) { // IEEE says illegal diff --git a/src/V3WidthSel.cpp b/src/V3WidthSel.cpp index 0854675e9..0f726376e 100644 --- a/src/V3WidthSel.cpp +++ b/src/V3WidthSel.cpp @@ -275,9 +275,10 @@ private: } else if (VN_IS(ddtypep, BasicDType) && ddtypep->isString()) { // SELBIT(string, index) -> GETC(string, index) AstNodeVarRef* varrefp = VN_CAST(fromp, NodeVarRef); - if (!varrefp) + if (!varrefp) { nodep->v3warn(E_UNSUPPORTED, "Unsupported: String array operation on non-variable"); + } AstNode* newp; if (varrefp && varrefp->lvalue()) { newp = new AstGetcRefN(nodep->fileline(), fromp, rhsp);