Fix identifiers that end with '_' on Windows (#4655)

This commit is contained in:
Anthony Donlon 2023-11-02 21:53:52 +00:00 committed by GitHub
parent ae6ec411d0
commit 2733d43ea7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 10 deletions

View File

@ -97,18 +97,17 @@ AstNode* AstNode::abovep() const {
string AstNode::encodeName(const string& namein) {
// Encode signal name raw from parser, then not called again on same signal
string out;
for (string::const_iterator pos = namein.begin(); pos != namein.end(); ++pos) {
out.reserve(namein.size());
for (auto pos = namein.begin(); pos != namein.end(); ++pos) {
if ((pos == namein.begin()) ? std::isalpha(pos[0]) // digits can't lead identifiers
: std::isalnum(pos[0])) {
out += pos[0];
} else if (pos[0] == '_') {
out += pos[0];
if (pos + 1 == namein.end()) break;
if (pos[1] == '_') {
out += "_";
out += "__05F"; // hex(_) = 0x5F
++pos;
if (pos == namein.end()) break;
} else {
out += pos[0];
out += "__05F"; // hex(_) = 0x5F
}
} else {
// Need the leading 0 so this will never collide with

View File

@ -11,9 +11,11 @@ $timescale 1ps $end
$var wire 1 # clk $end
$var wire 32 ( cyc [31:0] $end
$var wire 1 $ escaped_normal $end
$var wire 1 $ double__underscore $end
$var wire 1 $ 9num $end
$var wire 1 $ bra[ket]slash/dash-colon:9backslash\done $end
$var wire 1 % double__underscore $end
$var wire 1 $ underscore_at_the_end_ $end
$var wire 1 $ double__underscore_at_the_end__ $end
$var wire 1 & 9num $end
$var wire 1 ' bra[ket]slash/dash-colon:9backslash\done $end
$var wire 1 $ wire $end
$var wire 1 $ check_alias $end
$var wire 1 $ check:alias $end

View File

@ -21,6 +21,15 @@ module t (/*AUTOARG*/
output double__underscore ;
wire double__underscore = cyc[0];
wire underscore_at_the_end_ = cyc[0];
wire double__underscore_at_the_end__ = cyc[0];
// Only underscores, ignored in trace
wire _ = cyc[0];
wire __ = cyc[0];
wire ___ = cyc[0];
wire ____ = cyc[0];
// C doesn't allow leading non-alpha, so must escape
output \9num ;
wire \9num = cyc[0];
@ -45,7 +54,12 @@ module t (/*AUTOARG*/
cyc <= cyc + 1;
if (escaped_normal != cyc[0]) $stop;
if (\escaped_normal != cyc[0]) $stop;
if (double__underscore != cyc[0]) $stop;
if (underscore_at_the_end_ != cyc[0]) $stop;
if (double__underscore_at_the_end__ != cyc[0]) $stop;
if (_ != cyc[0]) $stop;
if (__ != cyc[0]) $stop;
if (___ != cyc[0]) $stop;
if (____ != cyc[0]) $stop;
if (\9num != cyc[0]) $stop;
if (\bra[ket]slash/dash-colon:9backslash\done != cyc[0]) $stop;
if (\wire != cyc[0]) $stop;