Skip to content

Commit

Permalink
Remove duplicates in verilator_coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Ryszard Rozak <rrozak@antmicro.com>
  • Loading branch information
RRozak committed Jan 20, 2025
1 parent 7dd9cfd commit fda3028
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/VlcSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class VlcPoint;

class VlcSourceCount final {
// TYPES
using PointsSet = std::set<const VlcPoint*>;
using PointsSet = std::set<VlcPoint*>;

// MEMBERS
const int m_lineno; ///< Line number
Expand All @@ -55,12 +55,12 @@ class VlcSourceCount final {
uint64_t minCount() const { return m_minCount; }

// METHODS
void insertPoint(const VlcPoint* pointp) {
void insertPoint(VlcPoint* pointp) {
m_maxCount = std::max(m_maxCount, pointp->count());
m_minCount = std::min(m_minCount, pointp->count());
m_points.emplace(pointp);
}
const PointsSet& points() { return m_points; }
PointsSet& points() { return m_points; }
};

//********************************************************************
Expand Down Expand Up @@ -90,7 +90,7 @@ class VlcSource final {
LinenoMap& lines() { return m_lines; }

// METHODS
void insertPoint(int lineno, const VlcPoint* pointp) {
void insertPoint(int lineno, VlcPoint* pointp) {
VlcSourceCount& sc = m_lines.emplace(lineno, lineno).first->second;
sc.insertPoint(pointp);
}
Expand Down
33 changes: 30 additions & 3 deletions src/VlcTop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,28 @@ void VlcTop::writeCoverage(const string& filename) {
os << "C '" << point.name() << "' " << point.count() << '\n';
}
}
std::string getKey(VlcPoint* const point) {
std::string comment = point->comment().substr(0, point->comment().find("="));
if (comment.find("toggle") != std::string::npos) {
return comment;
} else {
return std::to_string(point->lineno()) + std::to_string(point->column());
}
}
void processPoints(VlcSourceCount& sc) {
std::map<std::string, VlcPoint*> pointsMap;
std::set<VlcPoint*> toErase;
for (auto& point : sc.points()) {
std::string key = getKey(point);
if (pointsMap.find(key) == pointsMap.end()) {
pointsMap[key] = point;
} else {
pointsMap[key]->countInc(point->count());
toErase.insert(point);
}
}
for (auto& point : toErase) { sc.points().erase(point); }
}

void VlcTop::writeInfo(const string& filename) {
UINFO(2, "writeInfo " << filename << endl);
Expand Down Expand Up @@ -120,6 +142,7 @@ void VlcTop::writeInfo(const string& filename) {
int branchesHit = 0;
for (auto& li : lines) {
VlcSourceCount& sc = li.second;
processPoints(sc);
os << "DA:" << sc.lineno() << "," << sc.maxCount() << "\n";
int num_branches = sc.points().size();
if (num_branches == 1) continue;
Expand All @@ -129,9 +152,13 @@ void VlcTop::writeInfo(const string& filename) {
os << "BRDA:" << sc.lineno() << ",";
os << "0,";
const string cmt = point->comment().substr(0, point->comment().find("="));
os << cmt;

if (cmt.rfind("toggle_", 0) != 0) { os << "_" << point_num; }
if (cmt.rfind("toggle_", 0) != 0) {
std::string typeStr = cmt.substr(0, cmt.find("_"));
os << typeStr << "_" << point_num;
} else {
os << cmt;
}
os << ",";
os << point->count() << "\n";

Expand Down Expand Up @@ -212,7 +239,7 @@ void VlcTop::rank() {
void VlcTop::annotateCalc() {
// Calculate per-line information into filedata structure
for (const auto& i : m_points) {
const VlcPoint& point = m_points.pointNumber(i.second);
VlcPoint& point = m_points.pointNumber(i.second);
const string filename = point.filename();
const int lineno = point.lineno();
if (!filename.empty() && lineno != 0) {
Expand Down

0 comments on commit fda3028

Please sign in to comment.