From 5adc856950fb575f475e81496722aa47c5397666 Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Wed, 11 Aug 2021 16:22:52 +0100 Subject: [PATCH] Tests: ignore all hashes in files_identical Also add 'h' prefix to all printed hashes, to reduce ambiguity. No functional change. --- src/V3AstNodes.cpp | 16 ++++++++-------- src/V3EmitCImp.cpp | 2 +- src/V3Hash.cpp | 9 ++++++++- src/V3Hash.h | 1 + test_regress/driver.pl | 2 +- test_regress/t/t_xml_debugcheck.out | 10 +++++----- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index 7fbc3be71..661c40fca 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -1065,8 +1065,8 @@ AstVarScope* AstConstPool::findTable(AstInitArray* initp) { UASSERT_OBJ(VN_IS(valuep, Const), valuep, "Const pool table entry must be Const"); } // Try to find an existing table with the same content - const uint32_t hash = V3Hasher::uncachedHash(initp).value(); - const auto& er = m_tables.equal_range(hash); + const V3Hash hash = V3Hasher::uncachedHash(initp); + const auto& er = m_tables.equal_range(hash.value()); for (auto it = er.first; it != er.second; ++it) { AstVarScope* const varScopep = it->second; const AstInitArray* const init2p = VN_CAST(varScopep->varp()->valuep(), InitArray); @@ -1076,11 +1076,11 @@ AstVarScope* AstConstPool::findTable(AstInitArray* initp) { } // No such table yet, create it. string name = "TABLE_"; - name += cvtToHex(hash); + name += hash.toString(); name += "_"; name += cvtToStr(std::distance(er.first, er.second)); AstVarScope* const varScopep = createNewEntry(name, initp); - m_tables.emplace(hash, varScopep); + m_tables.emplace(hash.value(), varScopep); return varScopep; } @@ -1094,8 +1094,8 @@ static bool sameInit(const AstConst* ap, const AstConst* bp) { AstVarScope* AstConstPool::findConst(AstConst* initp, bool mergeDType) { // Try to find an existing constant with the same value - const uint32_t hash = initp->num().toHash().value(); - const auto& er = m_consts.equal_range(hash); + const V3Hash hash = initp->num().toHash(); + const auto& er = m_consts.equal_range(hash.value()); for (auto it = er.first; it != er.second; ++it) { AstVarScope* const varScopep = it->second; const AstConst* const init2p = VN_CAST(varScopep->varp()->valuep(), Const); @@ -1106,11 +1106,11 @@ AstVarScope* AstConstPool::findConst(AstConst* initp, bool mergeDType) { } // No such constant yet, create it. string name = "CONST_"; - name += cvtToHex(hash); + name += hash.toString(); name += "_"; name += cvtToStr(std::distance(er.first, er.second)); AstVarScope* const varScopep = createNewEntry(name, initp); - m_consts.emplace(hash, varScopep); + m_consts.emplace(hash.value(), varScopep); return varScopep; } diff --git a/src/V3EmitCImp.cpp b/src/V3EmitCImp.cpp index bc5627cf4..03b84a273 100644 --- a/src/V3EmitCImp.cpp +++ b/src/V3EmitCImp.cpp @@ -497,7 +497,7 @@ class EmitCImp final : EmitCFunc { // disambiguate them V3Hash hash; for (const string& name : *m_requiredHeadersp) { hash += name; } - m_subFileName = "DepSet_" + cvtToHex(hash.value()); + m_subFileName = "DepSet_" + hash.toString(); // Open output file openNextOutputFile(*m_requiredHeadersp, m_subFileName); // Emit functions in this dependency set diff --git a/src/V3Hash.cpp b/src/V3Hash.cpp index 35d924771..65059102a 100644 --- a/src/V3Hash.cpp +++ b/src/V3Hash.cpp @@ -19,10 +19,17 @@ #include #include #include +#include V3Hash::V3Hash(const std::string& val) : m_value{static_cast(std::hash{}(val))} {} std::ostream& operator<<(std::ostream& os, const V3Hash& rhs) { - return os << std::hex << std::setw(8) << std::setfill('0') << rhs.value(); + return os << 'h' << std::hex << std::setw(8) << std::setfill('0') << rhs.value(); +} + +std::string V3Hash::toString() const { + std::ostringstream os; + os << *this; + return os.str(); } diff --git a/src/V3Hash.h b/src/V3Hash.h index 06223567c..ef00d0a83 100644 --- a/src/V3Hash.h +++ b/src/V3Hash.h @@ -46,6 +46,7 @@ public: // METHODS uint32_t value() const { return m_value; } + std::string toString() const; // OPERATORS // Comparisons diff --git a/test_regress/driver.pl b/test_regress/driver.pl index 9073406bf..240049350 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -2192,7 +2192,7 @@ sub files_identical { $l1[$l] =~ s/Version: Verilator[^\n]+/Version: Verilator ###/mig; $l1[$l] =~ s/CPU Time: +[0-9.]+ seconds[^\n]+/CPU Time: ###/mig; $l1[$l] =~ s/\?v=[0-9.]+/?v=latest/mig; # warning URL - $l1[$l] =~ s/DepSet_[a-f0-9]+_/DepSet_#_/mg; + $l1[$l] =~ s/_h[0-9a-f]{8}_/_h########_/mg; if ($l1[$l] =~ s/Exiting due to.*/Exiting due to/mig) { splice @l1, $l+1; # Trunc rest last; diff --git a/test_regress/t/t_xml_debugcheck.out b/test_regress/t/t_xml_debugcheck.out index 2a62297bf..585eb915a 100644 --- a/test_regress/t/t_xml_debugcheck.out +++ b/test_regress/t/t_xml_debugcheck.out @@ -1501,12 +1501,12 @@ - - - - + + + + - +