diff --git a/Changes b/Changes index 5a47d8f3b..e10aaa4db 100644 --- a/Changes +++ b/Changes @@ -14,6 +14,8 @@ indicates the contributor was also the author of the fix; Thanks! *** Add --error-limit option. [Stefan Thiede] +*** Allow __ in cell names by quoting them in C. [Stefan Thiede] + **** Fix genvar to be signed, so "< 0" works properly. [Niranjan Prabhu] **** Fix assignments to inputs inside functions/tasks. [Patricio Kaplan] diff --git a/src/V3Ast.cpp b/src/V3Ast.cpp index 603764760..06d759017 100644 --- a/src/V3Ast.cpp +++ b/src/V3Ast.cpp @@ -83,6 +83,20 @@ void AstNode::init() { m_user5Cnt = 0; } +string AstNode::encodeName(const string& namein) { + string name2 = namein; + string out; + for (string::iterator pos = name2.begin(); pos != name2.end(); pos++) { + if (pos[0]=='_' && pos[1]=='_') { + out += "__ULUL_"; + pos++; + } else { + out += pos[0]; + } + } + return out; +} + string AstNode::shortName() const { string pretty = name(); string::size_type pos; @@ -114,6 +128,9 @@ string AstNode::prettyName(const string& namein) { while ((pos=pretty.find("__PVT__")) != string::npos) { pretty.replace(pos, 7, ""); } + while ((pos=pretty.find("__ULUL_")) != string::npos) { + pretty.replace(pos, 7, ""); + } return AstNode::dedotName(pretty); } diff --git a/src/V3Ast.h b/src/V3Ast.h index 42408a567..bc4aed501 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -558,6 +558,7 @@ public: string shortName() const; // Name with __PVT__ removed for concatenating scopes static string dedotName(const string& namein); // Name with dots removed static string prettyName(const string& namein); // Name for printing out to the user + static string encodeName(const string& namein); // Encode user name into internal C representation string prettyName() const { return prettyName(name()); } FileLine* fileline() const { return m_fileline; } int width() const { return m_width; } diff --git a/src/V3LinkCells.cpp b/src/V3LinkCells.cpp index d73064dd8..f850830d1 100644 --- a/src/V3LinkCells.cpp +++ b/src/V3LinkCells.cpp @@ -127,9 +127,6 @@ private: // Module: Pick up modnames, so we can resolve cells later m_modp = nodep; UINFO(2,"Link Module: "<name().find("__") != string::npos) { - nodep->v3error("Unsupported: Double underscores (__) in module names reserved for internal use: "<prettyName()); - } if (nodep->inLibrary()) { if (!m_libVertexp) m_libVertexp = new LibraryVertex(&m_graph); new V3GraphEdge(&m_graph, m_libVertexp, vertex(nodep), 1, false); diff --git a/src/verilog.l b/src/verilog.l index a54b5fb18..59b930f84 100644 --- a/src/verilog.l +++ b/src/verilog.l @@ -634,14 +634,18 @@ escid \\[^ \t\f\r\n]+ if (!isalnum(yytext[i])) yytext[i] = '_'; if (isalpha(yytext[1])) { - yylval.strp = V3Read::newString(yytext+1); // +1 to skip the backslash + yylval.strp = V3Read::newString( + AstNode::encodeName( + string(yytext+1))); // +1 to skip the backslash } else { - yylval.strp = V3Read::newString(yytext); // Need _ as "6..." isn't legal ID + yylval.strp = V3Read::newString( + AstNode::encodeName( + yytext)); // Need _ as "6..." isn't legal ID } return yaID; } - {id} { yylval.strp = V3Read::newString(yytext); + {id} { yylval.strp = V3Read::newString(AstNode::encodeName(string(yytext))); return yaID; }