Skip to content

Commit

Permalink
Handle multidimensional arrays
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 22, 2025
1 parent a99a95b commit 60d3438
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/VlcTop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,35 @@ void VlcTop::writeInfo(const string& filename) {
while (std::isdigit(s[s.size() - 1 - indexLength])) { indexLength++; }
return indexLength;
}
static int compareStrippedRecurse(const string& s1, const string& s2) {
int indexLength1 = getIndexLength(s1);
int indexLength2 = getIndexLength(s2);
if (indexLength1 == 0 || indexLength2 == 0
|| s1[s1.size() - indexLength1 - 1] != '_'
|| s2[s2.size() - indexLength2 - 1] != '_') {
// at least one of them is not array variable
// compare strings in such a case
return s1.compare(s2);
}
const std::string s1WithoutIndex = s1.substr(0, s1.size() - indexLength1 - 1);
const std::string s2WithoutIndex = s2.substr(0, s2.size() - indexLength2 - 1);
int cmpStripped = compareStrippedRecurse(s1WithoutIndex, s2WithoutIndex);
if (cmpStripped == 0) {
const int index1 = std::stoi(s1.substr(s1.size() - indexLength1));
const int index2 = std::stoi(s2.substr(s2.size() - indexLength2));
return index1 < index2;
} else {
return cmpStripped;
}
}
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;
return compareStrippedRecurse(aStripped, bStripped) == -1;
}
};
std::sort(sortedPoints.begin(), sortedPoints.end(), PointCmp());
Expand Down

0 comments on commit 60d3438

Please sign in to comment.