preprocessor: do not destroy double slash escaped identifiers
authorThomas Sailer <sailer@tsailer.ch>
Wed, 25 Aug 2021 19:34:26 +0000 (21:34 +0200)
committerZachary Snow <zachary.j.snow@gmail.com>
Thu, 16 Dec 2021 01:06:02 +0000 (18:06 -0700)
The preprocessor currently destroys double slash containing escaped
identifiers (for example \a//b ). This is due to next_token trying to
convert single line comments (//) into /* */ comments. This then leads
to an unintuitive error message like this:
ERROR: syntax error, unexpected '*'

This patch fixes the error by recognizing escaped identifiers and
returning them as single token. It also adds a testcase.

frontends/verilog/preproc.cc
tests/verilog/doubleslash.ys [new file with mode: 0644]

index 17f5675875269d6d8b16aa667bb81553ddf726f1..883531e7836f06b503bc13a58678fe3f3e47151c 100644 (file)
@@ -142,6 +142,16 @@ static std::string next_token(bool pass_newline = false)
                                return_char(ch);
                }
        }
+       else if (ch == '\\')
+       {
+               while ((ch = next_char()) != 0) {
+                       if (ch < 33 || ch > 126) {
+                               return_char(ch);
+                               break;
+                       }
+                       token += ch;
+               }
+       }
        else if (ch == '/')
        {
                if ((ch = next_char()) != 0) {
diff --git a/tests/verilog/doubleslash.ys b/tests/verilog/doubleslash.ys
new file mode 100644 (file)
index 0000000..8a51f12
--- /dev/null
@@ -0,0 +1,19 @@
+read_verilog -sv <<EOT
+module doubleslash
+  (input  logic   a,
+   input  logic   b,
+   output logic   z);
+
+  logic \a//b ;
+
+  assign \a//b = a & b;
+  assign z = ~\a//b ;
+
+endmodule : doubleslash
+EOT
+
+hierarchy
+proc
+opt -full
+
+write_verilog doubleslash.v