mirror of
https://github.com/verilator/verilator.git
synced 2026-10-06 10:03:44 +02:00
Fix inconsistent naming of generate scope arrays (#3840)
This commit is contained in:
+72
-1
@@ -158,7 +158,6 @@ string AstNode::vcdName(const string& namein) {
|
||||
string AstNode::prettyName(const string& namein) {
|
||||
// This function is somewhat hot, so we short-circuit some compares
|
||||
string pretty;
|
||||
pretty = "";
|
||||
pretty.reserve(namein.length());
|
||||
for (const char* pos = namein.c_str(); *pos;) {
|
||||
if (pos[0] == '-' && pos[1] == '>') { // ->
|
||||
@@ -206,6 +205,78 @@ string AstNode::prettyName(const string& namein) {
|
||||
return pretty;
|
||||
}
|
||||
|
||||
string AstNode::vpiName(const string& namein) {
|
||||
// This is slightly different from prettyName, in that when we encounter escaped characters,
|
||||
// we change that identifier to an escaped identifier, wrapping it with '\' and ' '
|
||||
// as specified in LRM 23.6
|
||||
string pretty;
|
||||
pretty.reserve(namein.length());
|
||||
bool inEscapedIdent = false;
|
||||
int lastIdent = 0;
|
||||
|
||||
for (const char* pos = namein.c_str(); *pos;) {
|
||||
char specialChar = 0;
|
||||
if (pos[0] == '-' && pos[1] == '>') { // ->
|
||||
specialChar = '.';
|
||||
pos += 2;
|
||||
} else if (pos[0] == '_' && pos[1] == '_') { // __
|
||||
if (0 == std::strncmp(pos, "__BRA__", 7)) {
|
||||
specialChar = '[';
|
||||
pos += 7;
|
||||
} else if (0 == std::strncmp(pos, "__KET__", 7)) {
|
||||
specialChar = ']';
|
||||
pos += 7;
|
||||
} else if (0 == std::strncmp(pos, "__DOT__", 7)) {
|
||||
specialChar = '.';
|
||||
pos += 7;
|
||||
} else if (0 == std::strncmp(pos, "__PVT__", 7)) {
|
||||
pos += 7;
|
||||
continue;
|
||||
} else if (pos[0] == '_' && pos[1] == '_' && pos[2] == '0' && isxdigit(pos[3])
|
||||
&& isxdigit(pos[4])) {
|
||||
char value = 0;
|
||||
value += 16 * (isdigit(pos[3]) ? (pos[3] - '0') : (tolower(pos[3]) - 'a' + 10));
|
||||
value += (isdigit(pos[4]) ? (pos[4] - '0') : (tolower(pos[4]) - 'a' + 10));
|
||||
|
||||
// __ doesn't always imply escaped ident
|
||||
if (value != '_') inEscapedIdent = true;
|
||||
|
||||
pretty += value;
|
||||
pos += 5;
|
||||
continue;
|
||||
}
|
||||
} else if (pos[0] == '.') {
|
||||
specialChar = '.';
|
||||
++pos;
|
||||
}
|
||||
|
||||
if (specialChar) {
|
||||
if (inEscapedIdent && (specialChar == '[' || specialChar == '.')) {
|
||||
pretty += " ";
|
||||
pretty.insert(lastIdent, "\\");
|
||||
inEscapedIdent = false;
|
||||
}
|
||||
|
||||
pretty += specialChar;
|
||||
|
||||
if (specialChar == ']' || specialChar == '.') {
|
||||
lastIdent = pretty.length();
|
||||
inEscapedIdent = false;
|
||||
}
|
||||
} else {
|
||||
pretty += pos[0];
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
if (inEscapedIdent) {
|
||||
pretty += " ";
|
||||
pretty.insert(lastIdent, "\\");
|
||||
}
|
||||
if (pretty[0] == 'T' && pretty.substr(0, 4) == "TOP.") pretty.replace(0, 4, "");
|
||||
if (pretty[0] == 'T' && pretty.substr(0, 5) == "TOP->") pretty.replace(0, 5, "");
|
||||
return pretty;
|
||||
}
|
||||
|
||||
string AstNode::prettyTypeName() const {
|
||||
if (name() == "") return typeName();
|
||||
return std::string{typeName()} + " '" + prettyName() + "'";
|
||||
|
||||
Reference in New Issue
Block a user