Skip to content

Commit

Permalink
Sort points after aggregation
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <[email protected]>
  • Loading branch information
RRozak committed Jan 22, 2025
1 parent 7955f13 commit a99a95b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
34 changes: 1 addition & 33 deletions src/VlcSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VlcPoint*, PointCmp>;
using PointsSet = std::set<VlcPoint*>;

// MEMBERS
const int m_lineno; ///< Line number
Expand Down
41 changes: 40 additions & 1 deletion src/VlcTop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VlcPoint*> 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();
Expand Down

0 comments on commit a99a95b

Please sign in to comment.