diff --git a/src/VlcSource.h b/src/VlcSource.h index c56501299e..1027d89bdb 100644 --- a/src/VlcSource.h +++ b/src/VlcSource.h @@ -35,39 +35,7 @@ class VlcPoint; class VlcSourceCount final { // TYPES - struct PointCmp { - static int getIndexLength(const std::string& s) { - int indexLength = 0; - while (std::isdigit(s[s.size() - 1 - indexLength])) { indexLength++; } - return indexLength; - } - bool operator()(const VlcPoint* a, const VlcPoint* b) const { - if (a->comment().rfind("toggle", 0) != 0) { - // not toggle coverage, compare pointers - return a < b; - } - const std::string aStripped = a->commentStripped(); - const std::string bStripped = b->commentStripped(); - int aIndexLength = getIndexLength(aStripped); - int bIndexLength = getIndexLength(bStripped); - const std::string aWithoutIndex = aStripped.substr(0, aStripped.size() - aIndexLength); - const std::string bWithoutIndex = bStripped.substr(0, bStripped.size() - bIndexLength); - if (aWithoutIndex != bWithoutIndex) { - // different variables, compare pointers - return a < b; - } - if (aIndexLength == 0 || bIndexLength == 0) { - // probably a case like: - // reg clk, clk2; - // compare pointers, as done in old way - return a < b; - } - const int aIndex = std::stoi(aStripped.substr(aStripped.size() - aIndexLength)); - const int bIndex = std::stoi(bStripped.substr(bStripped.size() - bIndexLength)); - return aIndex < bIndex; - } - }; - using PointsSet = std::set; + using PointsSet = std::set; // MEMBERS const int m_lineno; ///< Line number diff --git a/src/VlcTop.cpp b/src/VlcTop.cpp index c845b7b28b..250c38f2e7 100644 --- a/src/VlcTop.cpp +++ b/src/VlcTop.cpp @@ -148,7 +148,46 @@ void VlcTop::writeInfo(const string& filename) { if (num_branches == 1) continue; branchesFound += num_branches; int point_num = 0; - for (const auto& point : sc.points()) { + std::vector sortedPoints(sc.points().begin(), sc.points().end()); + struct PointCmp { + static int getIndexLength(const std::string& s) { + int indexLength = 0; + while (std::isdigit(s[s.size() - 1 - indexLength])) { indexLength++; } + return indexLength; + } + bool operator()(const VlcPoint* a, const VlcPoint* b) const { + if (a->comment().rfind("toggle", 0) != 0) { + // not toggle coverage, compare pointers + return a < b; + } + const std::string aStripped = a->commentStripped(); + const std::string bStripped = b->commentStripped(); + int aIndexLength = getIndexLength(aStripped); + int bIndexLength = getIndexLength(bStripped); + const std::string aWithoutIndex + = aStripped.substr(0, aStripped.size() - aIndexLength); + const std::string bWithoutIndex + = bStripped.substr(0, bStripped.size() - bIndexLength); + if (aWithoutIndex != bWithoutIndex) { + // different variables, compare pointers + return a < b; + } + if (aIndexLength == 0 || bIndexLength == 0) { + // probably a case like: + // reg clk, clk2; + // compare pointers, as done in old way + return a < b; + } + const int aIndex + = std::stoi(aStripped.substr(aStripped.size() - aIndexLength)); + const int bIndex + = std::stoi(bStripped.substr(bStripped.size() - bIndexLength)); + return aIndex < bIndex; + } + }; + std::sort(sortedPoints.begin(), sortedPoints.end(), PointCmp()); + + for (const auto& point : sortedPoints) { os << "BRDA:" << sc.lineno() << ","; os << point_num << ","; const string cmt = point->commentStripped();