Skip to content

Commit 203ea87

Browse files
committed
Fix verilog preprocessor bug when encountering windows newlines. #65
1 parent 1fdc24c commit 203ea87

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

systemrdl/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.13.0"
1+
__version__ = "1.13.1"

systemrdl/preprocessor/verilog_preprocessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def define_contents_scanner(self) -> str:
427427
# First, do a rough scan of the text to determine the max extent of the
428428
# define, solely based on escaped newlines.
429429
# Find the first newline without a backslash
430-
unescaped_newline_regex = re.compile(r'[^\\]$', re.MULTILINE)
430+
unescaped_newline_regex = re.compile(r'[^\\\r]\r?$', re.MULTILINE)
431431
m = unescaped_newline_regex.search(
432432
self._text,
433433
# Intentionally rewind the scan index by 1 character in case it is

test/test_preprocessor.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@parameterized_class([
88
{ "src": "rdl_testcases/preprocessor.rdl"},
9-
#{ "src": "rdl_testcases/preprocessor_CRLF.rdl"},
9+
{ "src": "rdl_testcases/preprocessor_CRLF.rdl"},
1010
])
1111
class TestPreprocessor(RDLSourceTestCase):
1212

@@ -44,21 +44,21 @@ def test_src_ref_translation(self):
4444
with self.subTest("top def"):
4545
src_ref = root.find_by_path("top").inst.def_src_ref
4646

47-
self.assertEqual(os.path.basename(src_ref.path), "preprocessor.rdl")
47+
self.assertEqual(os.path.basename(src_ref.path), os.path.basename(self.src))
4848
self.assertEqual(src_ref.line, 25)
4949
self.assertEqual(src_ref.line_selection, (18, 18))
5050

5151
with self.subTest("reg1 def"):
5252
src_ref = root.find_by_path("top.reg1").inst.def_src_ref
5353

54-
self.assertEqual(os.path.basename(src_ref.path), "preprocessor.rdl")
54+
self.assertEqual(os.path.basename(src_ref.path), os.path.basename(self.src))
5555
self.assertEqual(src_ref.line, 11)
5656
self.assertEqual(src_ref.line_selection, (10, 10))
5757

5858
with self.subTest("reg1 inst"):
5959
src_ref = root.find_by_path("top.reg1").inst.inst_src_ref
6060

61-
self.assertEqual(os.path.basename(src_ref.path), "preprocessor.rdl")
61+
self.assertEqual(os.path.basename(src_ref.path), os.path.basename(self.src))
6262
self.assertEqual(src_ref.line, 26)
6363
self.assertEqual(src_ref.line_selection, (10, 13))
6464

@@ -72,7 +72,7 @@ def test_src_ref_translation(self):
7272
with self.subTest("data0 inst"):
7373
src_ref = root.find_by_path("top.reg1.data0").inst.inst_src_ref
7474

75-
self.assertEqual(os.path.basename(src_ref.path), "preprocessor.rdl")
75+
self.assertEqual(os.path.basename(src_ref.path), os.path.basename(self.src))
7676
self.assertEqual(src_ref.line, 13)
7777
self.assertEqual(src_ref.line_selection, (12, 22))
7878

@@ -86,14 +86,14 @@ def test_src_ref_translation(self):
8686
with self.subTest("reg2 inst"):
8787
src_ref = root.find_by_path("top.reg2").inst.inst_src_ref
8888

89-
self.assertEqual(os.path.basename(src_ref.path), "preprocessor.rdl")
89+
self.assertEqual(os.path.basename(src_ref.path), os.path.basename(self.src))
9090
self.assertEqual(src_ref.line, 27)
9191
self.assertEqual(src_ref.line_selection, (11, 14))
9292

9393
with self.subTest("reg3 inst"):
9494
src_ref = root.find_by_path("top.reg3").inst.inst_src_ref
9595

96-
self.assertEqual(os.path.basename(src_ref.path), "preprocessor.rdl")
96+
self.assertEqual(os.path.basename(src_ref.path), os.path.basename(self.src))
9797
self.assertEqual(src_ref.line, 28)
9898
self.assertEqual(src_ref.line_selection, (4, 22))
9999

0 commit comments

Comments
 (0)