From 9a722ccf62c45b8e4b161a1878fc445a78803609 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 11 Dec 2021 11:22:04 -0500 Subject: [PATCH] Internals: Cleanup of InitArray stuff. No functional change intended. --- src/V3AstNodes.cpp | 2 +- src/V3EmitCConstInit.h | 16 ++++++++++------ src/V3EmitCFunc.cpp | 2 +- src/V3EmitV.cpp | 2 +- src/V3EmitXml.cpp | 8 ++++---- test_regress/t/t_enum_large_methods.v | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index a1f2ad2d0..d64c9d81d 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -1344,7 +1344,7 @@ void AstIfaceRefDType::dumpSmall(std::ostream& str) const { void AstInitArray::dump(std::ostream& str) const { this->AstNode::dump(str); int n = 0; - const AstInitArray::KeyItemMap& mapr = map(); + const auto& mapr = map(); for (const auto& itr : mapr) { if (n++ > 5) { str << " ..."; diff --git a/src/V3EmitCConstInit.h b/src/V3EmitCConstInit.h index 0c2b680f1..d865bfd09 100644 --- a/src/V3EmitCConstInit.h +++ b/src/V3EmitCConstInit.h @@ -34,6 +34,15 @@ class EmitCConstInit VL_NOT_FINAL : public EmitCBaseVisitor { // METHODS VL_DEBUG_FUNC; // Declare debug() + uint32_t tabModulus(AstNodeDType* dtypep) { + const uint32_t elemBytes = dtypep->widthTotalBytes(); + return dtypep->isString() ? 1 // String + : elemBytes <= 2 ? 8 // CData, SData + : elemBytes <= 4 ? 4 // IData + : elemBytes <= 8 ? 2 // QData + : 1; + } + protected: // VISITORS virtual void visit(AstInitArray* nodep) override { @@ -41,12 +50,7 @@ protected: = VN_AS(nodep->dtypep()->skipRefp(), UnpackArrayDType); UASSERT_OBJ(dtypep, nodep, "Array initializer has non-array dtype"); const uint32_t size = dtypep->elementsConst(); - const uint32_t elemBytes = dtypep->subDTypep()->widthTotalBytes(); - const uint32_t tabMod = dtypep->subDTypep()->isString() ? 1 // String - : elemBytes <= 2 ? 8 // CData, SData - : elemBytes <= 4 ? 4 // IData - : elemBytes <= 8 ? 2 // QData - : 1; + const uint32_t tabMod = tabModulus(dtypep->subDTypep()); VL_RESTORER(m_inUnpacked); VL_RESTORER(m_unpackedWord); m_inUnpacked = true; diff --git a/src/V3EmitCFunc.cpp b/src/V3EmitCFunc.cpp index b60eca2db..ec73f0593 100644 --- a/src/V3EmitCFunc.cpp +++ b/src/V3EmitCFunc.cpp @@ -629,7 +629,7 @@ void EmitCFunc::emitVarReset(AstVar* varp) { emitSetVarConstant(varNameProtected + "[__Vi]", VN_AS(initarp->defaultp(), Const)); puts("}\n"); } - const AstInitArray::KeyItemMap& mapr = initarp->map(); + const auto& mapr = initarp->map(); for (const auto& itr : mapr) { AstNode* const valuep = itr.second->valuep(); emitSetVarConstant(varNameProtected + "[" + cvtToStr(itr.first) + "]", diff --git a/src/V3EmitV.cpp b/src/V3EmitV.cpp index ff043a143..18cab53b4 100644 --- a/src/V3EmitV.cpp +++ b/src/V3EmitV.cpp @@ -498,7 +498,7 @@ class EmitVBaseVisitor VL_NOT_FINAL : public EmitCBaseVisitor { virtual void visit(AstInitArray* nodep) override { putfs(nodep, "'{"); int comma = 0; - const AstInitArray::KeyItemMap& mapr = nodep->map(); + const auto& mapr = nodep->map(); for (const auto& itr : mapr) { if (comma++) putbs(", "); puts(cvtToStr(itr.first)); diff --git a/src/V3EmitXml.cpp b/src/V3EmitXml.cpp index e2af26418..aedc5fa4a 100644 --- a/src/V3EmitXml.cpp +++ b/src/V3EmitXml.cpp @@ -163,12 +163,12 @@ class EmitXmlFileVisitor final : public AstNVisitor { } virtual void visit(AstInitArray* nodep) override { puts("\n"); - const AstInitArray::KeyItemMap& map = nodep->map(); - for (AstInitArray::KeyItemMap::const_iterator it = map.begin(); it != map.end(); ++it) { + const auto& mapr = nodep->map(); + for (const auto& itr : mapr) { puts("first)); + puts(cvtToStr(itr.first)); puts("\">\n"); - iterateChildren(it->second); + iterateChildren(itr.second); puts("\n"); } puts("\n"); diff --git a/test_regress/t/t_enum_large_methods.v b/test_regress/t/t_enum_large_methods.v index bd9eb5da5..136f5f5cc 100644 --- a/test_regress/t/t_enum_large_methods.v +++ b/test_regress/t/t_enum_large_methods.v @@ -44,7 +44,7 @@ module t (/*AUTOARG*/ else if (cyc==20) begin e <= 'h11; // Unknown end - else if (cyc==20) begin + else if (cyc==21) begin `checks(e.name, ""); // Unknown end else if (cyc==99) begin