From 30318a6654f171b405f0f9e81a02498145e168f4 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Sat, 28 Oct 2023 11:24:04 +0100 Subject: [PATCH] C++11 cleanup --- include/verilated_trace_imp.h | 2 +- include/verilated_vpi.cpp | 6 ++---- src/V3Class.cpp | 18 +++++++----------- src/V3Config.cpp | 2 +- src/V3EmitCSyms.cpp | 35 ++++++++++++++++------------------- src/V3Fork.cpp | 4 ++-- src/V3Global.cpp | 2 +- src/V3HierBlock.cpp | 2 +- src/V3LinkDot.cpp | 2 +- src/V3LinkParse.cpp | 3 +-- src/V3Options.cpp | 2 +- src/V3Order.cpp | 2 +- src/V3Param.cpp | 5 ++--- src/V3Randomize.cpp | 2 +- src/V3Sched.cpp | 10 ++++------ src/V3SplitVar.cpp | 17 ++++++++--------- src/V3Task.cpp | 10 ++++------ src/V3UniqueNames.h | 2 +- src/VlcSource.h | 5 ++--- 19 files changed, 57 insertions(+), 74 deletions(-) diff --git a/include/verilated_trace_imp.h b/include/verilated_trace_imp.h index 62516432f..1bdef1291 100644 --- a/include/verilated_trace_imp.h +++ b/include/verilated_trace_imp.h @@ -453,7 +453,7 @@ void VerilatedTrace::dumpvars(int level, const std::string& for (auto& i : hierSpaced) { if (i == '.') i = ' '; } - m_dumpvars.push_back(std::make_pair(level, hierSpaced)); + m_dumpvars.emplace_back(level, hierSpaced); } } diff --git a/include/verilated_vpi.cpp b/include/verilated_vpi.cpp index 7e01fe5d2..3bab69be0 100644 --- a/include/verilated_vpi.cpp +++ b/include/verilated_vpi.cpp @@ -542,8 +542,7 @@ public: VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: vpi_register_cb reason=%d id=%" PRId64 " time=%" PRIu64 " obj=%p\n", cb_data_p->reason, id, time, cb_data_p->obj);); - s().m_futureCbs.emplace(std::piecewise_construct, - std::forward_as_tuple(std::make_pair(time, id)), + s().m_futureCbs.emplace(std::piecewise_construct, std::forward_as_tuple(time, id), std::forward_as_tuple(id, cb_data_p, nullptr)); } static void cbNextAdd(uint64_t id, const s_cb_data* cb_data_p, QData time) { @@ -551,8 +550,7 @@ public: VL_DEBUG_IF_PLI(VL_DBG_MSGF("- vpi: vpi_register_cb reason=%d(NEXT) id=%" PRId64 " time=%" PRIu64 " obj=%p\n", cb_data_p->reason, id, time, cb_data_p->obj);); - s().m_nextCbs.emplace(std::piecewise_construct, - std::forward_as_tuple(std::make_pair(time, id)), + s().m_nextCbs.emplace(std::piecewise_construct, std::forward_as_tuple(time, id), std::forward_as_tuple(id, cb_data_p, nullptr)); } static void cbReasonRemove(uint64_t id, uint32_t reason, QData time) { diff --git a/src/V3Class.cpp b/src/V3Class.cpp index ef0eddf9b..ba2b0ade5 100644 --- a/src/V3Class.cpp +++ b/src/V3Class.cpp @@ -122,13 +122,13 @@ private: // Move later, or we wouldn't keep iterating the class // We're really moving the VarScope but we might not // have a pointer to it yet - m_toScopeMoves.emplace_back(std::make_pair(nodep, m_packageScopep)); + m_toScopeMoves.emplace_back(nodep, m_packageScopep); } if (!m_ftaskp && nodep->lifetime().isStatic()) { - m_toPackageMoves.emplace_back(std::make_pair(nodep, m_classPackagep)); + m_toPackageMoves.emplace_back(nodep, m_classPackagep); // We're really moving the VarScope but we might not // have a pointer to it yet - m_toScopeMoves.emplace_back(std::make_pair(nodep, m_packageScopep)); + m_toScopeMoves.emplace_back(nodep, m_packageScopep); } } } @@ -144,7 +144,7 @@ private: m_ftaskp = nodep; iterateChildren(nodep); if (m_packageScopep && nodep->lifetime().isStatic()) { - m_toScopeMoves.emplace_back(std::make_pair(nodep, m_packageScopep)); + m_toScopeMoves.emplace_back(nodep, m_packageScopep); } } } @@ -153,7 +153,7 @@ private: // Don't move now, or wouldn't keep iterating the class // TODO move function statics only // if (m_classScopep) { - // m_toScopeMoves.push_back(std::make_pair(nodep, m_classScopep)); + // m_toScopeMoves.emplace_back(nodep, m_classScopep); //} } void visit(AstCoverDecl* nodep) override { @@ -164,16 +164,12 @@ private: void visit(AstInitial* nodep) override { // But not AstInitialAutomatic, which remains under the class iterateChildren(nodep); - if (m_packageScopep) { - m_toScopeMoves.emplace_back(std::make_pair(nodep, m_packageScopep)); - } + if (m_packageScopep) { m_toScopeMoves.emplace_back(nodep, m_packageScopep); } } void visit(AstInitialStatic* nodep) override { // But not AstInitialAutomatic, which remains under the class iterateChildren(nodep); - if (m_packageScopep) { - m_toScopeMoves.emplace_back(std::make_pair(nodep, m_packageScopep)); - } + if (m_packageScopep) { m_toScopeMoves.emplace_back(nodep, m_packageScopep); } } void setStructModulep(AstNodeUOrStructDType* const dtypep) { diff --git a/src/V3Config.cpp b/src/V3Config.cpp index 566021160..82aea8a9f 100644 --- a/src/V3Config.cpp +++ b/src/V3Config.cpp @@ -300,7 +300,7 @@ public: m_lastIgnore.it = m_ignLines.begin(); } void addIgnoreMatch(V3ErrorCode code, const string& match) { - m_waivers.push_back(std::make_pair(code, match)); + m_waivers.emplace_back(code, match); } void applyBlock(AstNodeBlock* nodep) { diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 93d027a42..79c12b996 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -240,12 +240,11 @@ class EmitCSyms final : EmitCBaseVisitorConst { // << scpSym << endl); if (v3Global.opt.vpi()) varHierarchyScopes(scpName); if (m_scopeNames.find(scpSym) == m_scopeNames.end()) { - m_scopeNames.insert(std::make_pair( - scpSym, ScopeData{scpSym, scpPretty, 0, "SCOPE_OTHER"})); + m_scopeNames.emplace(scpSym, + ScopeData{scpSym, scpPretty, 0, "SCOPE_OTHER"}); } - m_scopeVars.insert( - std::make_pair(scpSym + " " + varp->name(), - ScopeVarData{scpSym, varBasePretty, varp, modp, scopep})); + m_scopeVars.emplace(scpSym + " " + varp->name(), + ScopeVarData{scpSym, varBasePretty, varp, modp, scopep}); } } } @@ -312,24 +311,24 @@ class EmitCSyms final : EmitCBaseVisitorConst { const string name = nodep->scopep()->shortName() + "__DOT__" + nodep->name(); const string name_pretty = AstNode::vpiName(name); const int timeunit = m_modp->timeunit().powerOfTen(); - m_vpiScopeCandidates.insert( - std::make_pair(scopeSymString(name), - ScopeData{scopeSymString(name), name_pretty, timeunit, type})); + m_vpiScopeCandidates.emplace( + scopeSymString(name), + ScopeData{scopeSymString(name), name_pretty, timeunit, type}); } } void visit(AstScope* nodep) override { if (VN_IS(m_modp, Class)) return; // The ClassPackage is what is visible nameCheck(nodep); - m_scopes.emplace_back(std::make_pair(nodep, m_modp)); + m_scopes.emplace_back(nodep, m_modp); if (v3Global.opt.vpi() && !nodep->isTop()) { const string type = VN_IS(nodep->modp(), Package) ? "SCOPE_OTHER" : "SCOPE_MODULE"; const string name_pretty = AstNode::vpiName(nodep->shortName()); const int timeunit = m_modp->timeunit().powerOfTen(); - m_vpiScopeCandidates.insert(std::make_pair( + m_vpiScopeCandidates.emplace( scopeSymString(nodep->name()), - ScopeData{scopeSymString(nodep->name()), name_pretty, timeunit, type})); + ScopeData{scopeSymString(nodep->name()), name_pretty, timeunit, type}); } } void visit(AstScopeName* nodep) override { @@ -341,22 +340,20 @@ class EmitCSyms final : EmitCBaseVisitorConst { name, ScopeData{name, nodep->scopePrettySymName(), timeunit, "SCOPE_OTHER"}); if (nodep->dpiExport()) { UASSERT_OBJ(m_cfuncp, nodep, "ScopeName not under DPI function"); - m_scopeFuncs.insert(std::make_pair(name + " " + m_cfuncp->name(), - ScopeFuncData(nodep, m_cfuncp, m_modp))); + m_scopeFuncs.emplace(name + " " + m_cfuncp->name(), + ScopeFuncData(nodep, m_cfuncp, m_modp)); } else { if (m_scopeNames.find(nodep->scopeDpiName()) == m_scopeNames.end()) { - m_scopeNames.insert( - std::make_pair(nodep->scopeDpiName(), - ScopeData{nodep->scopeDpiName(), nodep->scopePrettyDpiName(), - timeunit, "SCOPE_OTHER"})); + m_scopeNames.emplace(nodep->scopeDpiName(), + ScopeData{nodep->scopeDpiName(), nodep->scopePrettyDpiName(), + timeunit, "SCOPE_OTHER"}); } } } void visit(AstVar* nodep) override { nameCheck(nodep); iterateChildrenConst(nodep); - if (nodep->isSigUserRdPublic() && !m_cfuncp) - m_modVars.emplace_back(std::make_pair(m_modp, nodep)); + if (nodep->isSigUserRdPublic() && !m_cfuncp) m_modVars.emplace_back(m_modp, nodep); } void visit(AstCoverDecl* nodep) override { // Assign numbers to all bins, so we know how big of an array to use diff --git a/src/V3Fork.cpp b/src/V3Fork.cpp index 09d12e4f4..a271874ae 100644 --- a/src/V3Fork.cpp +++ b/src/V3Fork.cpp @@ -290,7 +290,7 @@ private: ForkDynScopeFrame* pushDynScopeFrame(AstNode* procp) { ForkDynScopeFrame* const framep = new ForkDynScopeFrame{m_modp, procp, m_class_id++, m_id++}; - auto r = m_frames.emplace(std::make_pair(procp, framep)); + auto r = m_frames.emplace(procp, framep); UASSERT_OBJ(r.second, m_modp, "Procedure already contains a frame"); return framep; } @@ -321,7 +321,7 @@ private: } void bindNodeToDynScope(AstNode* nodep, ForkDynScopeFrame* frame) { - m_frames.emplace(std::make_pair(nodep, frame)); + m_frames.emplace(nodep, frame); } bool needsDynScope(const AstVarRef* refp) const { diff --git a/src/V3Global.cpp b/src/V3Global.cpp index f4ebc182a..905b2e63d 100644 --- a/src/V3Global.cpp +++ b/src/V3Global.cpp @@ -125,7 +125,7 @@ const std::string& V3Global::ptrToId(const void* p) { } else { os << "0"; } - it = m_ptrToId.insert(std::make_pair(p, os.str())).first; + it = m_ptrToId.emplace(p, os.str()).first; } return it->second; } diff --git a/src/V3HierBlock.cpp b/src/V3HierBlock.cpp index b21a6e099..e59a8cb36 100644 --- a/src/V3HierBlock.cpp +++ b/src/V3HierBlock.cpp @@ -134,7 +134,7 @@ V3HierBlock::StrGParams V3HierBlock::stringifyParams(const GParams& gparams, boo s = constp->num().ascii(true, true); s = VString::quoteAny(s, '\'', '\\'); } - strParams.push_back(std::make_pair(gparam->name(), s)); + strParams.emplace_back(gparam->name(), s); } } return strParams; diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index a3b5a350b..2726f2e97 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -442,7 +442,7 @@ public: // Track and later recurse interface modules void insertIfaceModSym(AstIface* nodep, VSymEnt* symp) { - m_ifaceModSyms.push_back(std::make_pair(nodep, symp)); + m_ifaceModSyms.emplace_back(nodep, symp); } void computeIfaceModSyms(); diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index 9c9b349e2..0f7fa35ac 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -534,8 +534,7 @@ private: } else { defp = new AstTypedef{nodep->fileline(), nodep->name(), nullptr, VFlagChildDType{}, dtypep}; - m_implTypedef.insert( - std::make_pair(std::make_pair(nodep->containerp(), defp->name()), defp)); + m_implTypedef.emplace(std::make_pair(nodep->containerp(), defp->name()), defp); backp->addNextHere(defp); } } diff --git a/src/V3Options.cpp b/src/V3Options.cpp index d64519e07..983e8243b 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -221,7 +221,7 @@ V3HierarchicalBlockOption::V3HierarchicalBlockOption(const string& opts) { cmdfl.v3error(hierBlock + " requires at least two comma-separated values"); } for (size_t i = 2; i + 1 < vals.size(); i += 2) { - const bool inserted = m_parameters.insert(std::make_pair(vals[i], vals[i + 1])).second; + const bool inserted = m_parameters.emplace(vals[i], vals[i + 1]).second; if (!inserted) { cmdfl.v3error("Module name '" + vals[i] + "' is duplicated in " + hierBlock); } diff --git a/src/V3Order.cpp b/src/V3Order.cpp index 27df6913c..3c8a3b86f 100644 --- a/src/V3Order.cpp +++ b/src/V3Order.cpp @@ -856,7 +856,7 @@ class OrderProcess final { string name = "_" + m_tag; name += domainp->isMulti() ? "_comb" : "_sequent"; name = name + "__" + scopep->nameDotless(); - const unsigned funcnum = m_funcNums.emplace(std::make_pair(modp, name), 0).first->second++; + const unsigned funcnum = m_funcNums[{modp, name}]++; name = name + "__" + cvtToStr(funcnum); if (v3Global.opt.profCFuncs()) { name += "__PROF__" + forWhatp->fileline()->profileFuncname(); diff --git a/src/V3Param.cpp b/src/V3Param.cpp index 4133df59f..dc7aed79c 100644 --- a/src/V3Param.cpp +++ b/src/V3Param.cpp @@ -90,8 +90,7 @@ class ParameterizedHierBlocks final { public: ParameterizedHierBlocks(const V3HierBlockOptSet& hierOpts, AstNetlist* nodep) { for (const auto& hierOpt : hierOpts) { - m_hierBlockOptsByOrigName.insert( - std::make_pair(hierOpt.second.origName(), &hierOpt.second)); + m_hierBlockOptsByOrigName.emplace(hierOpt.second.origName(), &hierOpt.second); const V3HierarchicalBlockOption::ParamStrMap& params = hierOpt.second.params(); ParamConstMap& consts = m_hierParams[&hierOpt.second]; for (V3HierarchicalBlockOption::ParamStrMap::const_iterator pIt = params.begin(); @@ -807,7 +806,7 @@ class ParamProcessor final { longnamer += ("_" + paramSmallName(srcModp, pinp->modVarp()) + paramValueNumber(pinIrefp)); any_overridesr = true; - ifaceRefRefs.push_back(std::make_pair(portIrefp, pinIrefp)); + ifaceRefRefs.emplace_back(portIrefp, pinIrefp); if (portIrefp->ifacep() != pinIrefp->ifacep() // Might be different only due to param cloning, so check names too && portIrefp->ifaceName() != pinIrefp->ifaceName()) { diff --git a/src/V3Randomize.cpp b/src/V3Randomize.cpp index 31f72fc1e..18eb63df2 100644 --- a/src/V3Randomize.cpp +++ b/src/V3Randomize.cpp @@ -182,7 +182,7 @@ private: if (it != m_randcDtypes.end()) return it->second; AstCDType* newp = new AstCDType{fl, name}; v3Global.rootp()->typeTablep()->addTypesp(newp); - m_randcDtypes.emplace(std::make_pair(name, newp)); + m_randcDtypes.emplace(name, newp); return newp; } diff --git a/src/V3Sched.cpp b/src/V3Sched.cpp index 7dabae60f..926379d97 100644 --- a/src/V3Sched.cpp +++ b/src/V3Sched.cpp @@ -278,13 +278,11 @@ EvalLoop createEvalLoop(AstNetlist* netlistp, // //============================================================================ // Split large function according to --output-split-cfuncs -std::map s_funcNums; // What split number to attach to a function - AstCFunc* splitCheckCreateNewSubFunc(AstCFunc* ofuncp) { - auto funcNumItMatch = s_funcNums.emplace(std::make_pair(ofuncp, 0)); - AstCFunc* const subFuncp = new AstCFunc{ - ofuncp->fileline(), ofuncp->name() + "__" + cvtToStr(funcNumItMatch.first->second++), - ofuncp->scopep()}; + static std::map funcNums; // What split number to attach to a function + const uint32_t funcNum = funcNums[ofuncp]++; + const std::string name = ofuncp->name() + "__" + cvtToStr(funcNum); + AstCFunc* const subFuncp = new AstCFunc{ofuncp->fileline(), name, ofuncp->scopep()}; subFuncp->dontCombine(true); subFuncp->isStatic(false); subFuncp->isLoose(true); diff --git a/src/V3SplitVar.cpp b/src/V3SplitVar.cpp index 8711f4bc6..54e6d5e76 100644 --- a/src/V3SplitVar.cpp +++ b/src/V3SplitVar.cpp @@ -317,8 +317,7 @@ private: public: // Register a variable to split void registerVar(AstVar* varp) { - const bool inserted - = m_map.insert(std::make_pair(varp, MapType::value_type::second_type())).second; + const bool inserted = m_map.emplace(varp, MapType::value_type::second_type()).second; UASSERT_OBJ(inserted, varp, "already registered"); } // Register the location where a variable is used. @@ -907,8 +906,8 @@ public: std::vector> points; // points.reserve(m_lhs.size() * 2 + 2); // 2 points will be added per one PackedVarRefEntry for (const PackedVarRefEntry& ref : m_lhs) { - points.emplace_back(std::make_pair(ref.lsb(), false)); // Start of a region - points.emplace_back(std::make_pair(ref.msb() + 1, true)); // End of a region + points.emplace_back(ref.lsb(), false); // Start of a region + points.emplace_back(ref.msb() + 1, true); // End of a region } if (skipUnused && !m_rhs.empty()) { // Range to be read must be kept, so add points here int lsb = m_basicp->hi() + 1; @@ -918,12 +917,12 @@ public: msb = std::max(msb, ref.msb()); } UASSERT_OBJ(lsb <= msb, m_basicp, "lsb:" << lsb << " msb:" << msb << " are wrong"); - points.emplace_back(std::make_pair(lsb, false)); - points.emplace_back(std::make_pair(msb + 1, true)); + points.emplace_back(lsb, false); + points.emplace_back(msb + 1, true); } if (!skipUnused) { // All bits are necessary - points.emplace_back(std::make_pair(m_basicp->lo(), false)); - points.emplace_back(std::make_pair(m_basicp->hi() + 1, true)); + points.emplace_back(m_basicp->lo(), false); + points.emplace_back(m_basicp->hi() + 1, true); } std::sort(points.begin(), points.end(), SortByFirst()); @@ -960,7 +959,7 @@ class SplitPackedVarVisitor final : public VNVisitor, public SplitVarImpl { warnNoSplit(nodep, nodep, reason); nodep->attrSplitVar(false); } else { // Finally find a good candidate - const bool inserted = m_refs.insert(std::make_pair(nodep, PackedVarRef{nodep})).second; + const bool inserted = m_refs.emplace(nodep, PackedVarRef{nodep}).second; if (inserted) UINFO(3, nodep->prettyNameQ() << " is added to candidate list.\n"); } } diff --git a/src/V3Task.cpp b/src/V3Task.cpp index 9bd96ef03..0bfa6cea0 100644 --- a/src/V3Task.cpp +++ b/src/V3Task.cpp @@ -174,8 +174,7 @@ private: if (AstVarScope* const vscp = VN_CAST(stmtp, VarScope)) { if (vscp->varp()->isFuncLocal() || vscp->varp()->isUsedLoopIdx()) { UINFO(9, " funcvsc " << vscp << endl); - m_varToScopeMap.insert( - std::make_pair(std::make_pair(nodep, vscp->varp()), vscp)); + m_varToScopeMap.emplace(std::make_pair(nodep, vscp->varp()), vscp); } } } @@ -1623,9 +1622,8 @@ V3TaskConnects V3Task::taskConnects(AstNodeFTaskRef* nodep, AstNode* taskStmtsp, for (AstNode* stmtp = taskStmtsp; stmtp; stmtp = stmtp->nextp()) { if (AstVar* const portp = VN_CAST(stmtp, Var)) { if (portp->isIO()) { - tconnects.push_back(std::make_pair(portp, static_cast(nullptr))); - nameToIndex.insert( - std::make_pair(portp->name(), tpinnum)); // For name based connections + tconnects.emplace_back(portp, static_cast(nullptr)); + nameToIndex.emplace(portp->name(), tpinnum); // For name based connections tpinnum++; if (portp->attrSFormat()) { sformatp = portp; @@ -1665,7 +1663,7 @@ V3TaskConnects V3Task::taskConnects(AstNodeFTaskRef* nodep, AstNode* taskStmtsp, } else { // By pin number if (ppinnum >= tpinnum) { if (sformatp) { - tconnects.push_back(std::make_pair(sformatp, static_cast(nullptr))); + tconnects.emplace_back(sformatp, static_cast(nullptr)); tconnects[ppinnum].second = argp; tpinnum++; } else { diff --git a/src/V3UniqueNames.h b/src/V3UniqueNames.h index 7c4aa4af2..30d4cd2fa 100644 --- a/src/V3UniqueNames.h +++ b/src/V3UniqueNames.h @@ -45,7 +45,7 @@ public: // Return argument, prepended with the prefix if any, then appended with a unique suffix each // time we are called with the same argument. std::string get(const std::string& name) { - const unsigned num = m_multiplicity.emplace(name, 0).first->second++; + const unsigned num = m_multiplicity[name]++; std::string result; if (!m_prefix.empty()) { result += m_prefix; diff --git a/src/VlcSource.h b/src/VlcSource.h index 788945787..523b60861 100644 --- a/src/VlcSource.h +++ b/src/VlcSource.h @@ -95,8 +95,7 @@ public: // METHODS void lineIncCount(int lineno, uint64_t count, bool ok, const VlcPoint* pointp) { auto lit = m_lines.find(lineno); - if (lit == m_lines.end()) - lit = m_lines.emplace(std::make_pair(lineno, VlcSourceCount{lineno})).first; + if (lit == m_lines.end()) lit = m_lines.emplace(lineno, VlcSourceCount{lineno}).first; VlcSourceCount& sc = lit->second; sc.incCount(count, ok); sc.insertPoint(pointp); @@ -131,7 +130,7 @@ public: if (iter != m_sources.end()) { return iter->second; } else { - iter = m_sources.insert(std::make_pair(name, VlcSource{name})).first; + iter = m_sources.emplace(name, VlcSource{name}).first; return iter->second; } }