Skip to content

Commit 62b668c

Browse files
committed
Match names more precisely in update_lit_checks.py
Previously the lit test update script interpreted module names as the names of import items and export names as the names of export items, but it is more precise to use the actual identifiers of the imported or exported items as the names instead. Update update_lit_checks.py to use a more correct regex to match names and to correctly use the identifiers of import and export items as their names. In some cases this can improve the readability of test output.
1 parent fb7d00b commit 62b668c

39 files changed

+392
-278
lines changed

scripts/update_lit_checks.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@
3737
CHECK_PREFIX_RE = re.compile(r'.*--check-prefix[= ](\S+).*')
3838
MODULE_RE = re.compile(r'^\(module.*$', re.MULTILINE)
3939

40-
ALL_ITEMS = '|'.join(['type', 'import', 'global', 'memory', 'data', 'table',
41-
'elem', 'tag', 'export', 'start', 'func'])
40+
DECL_ITEMS = '|'.join(['type', 'global', 'memory', 'data', 'table',
41+
'elem', 'tag', 'start', 'func'])
42+
IMPORT_ITEM = r'import\s*"[^"]*"\s*"[^"]*"\s*\((?:' + DECL_ITEMS + ')'
43+
EXPORT_ITEM = f'export\s*"[^"]*"\s*\((?:' + DECL_ITEMS + ')'
44+
ALL_ITEMS = DECL_ITEMS + '|' + IMPORT_ITEM + '|' + EXPORT_ITEM
4245

4346
# Regular names as well as the "declare" in (elem declare ... to get declarative
4447
# segments included in the output.
45-
ITEM_NAME = r'\$[^\s()]*|"[^\s()]*"|declare'
48+
ITEM_NAME = r'\$[^\s()]*|\$"[^"]*"|declare'
4649

4750
# FIXME: This does not handle nested string contents. For example,
4851
# (data (i32.const 10) "hello(")
@@ -55,6 +58,11 @@
5558
FUZZ_EXEC_FUNC = re.compile(r'^\[fuzz-exec\] calling (?P<name>\S*)$')
5659

5760

61+
def indentKindName(match):
62+
# Return the indent, kind, and name from an ITEM_RE match
63+
return (match[1], match[2].split()[0], match[3])
64+
65+
5866
def warn(msg):
5967
print(f'warning: {msg}', file=sys.stderr)
6068

@@ -141,7 +149,7 @@ def parse_output_modules(text):
141149
for module in split_modules(text):
142150
items = []
143151
for match in ITEM_RE.finditer(module):
144-
kind, name = match[2], match[3]
152+
_, kind, name = indentKindName(match)
145153
end = find_end(module, match.end(1))
146154
lines = module[match.start():end].split('\n')
147155
items.append(((kind, name), lines))
@@ -247,7 +255,7 @@ def update_test(args, test, lines, tmp):
247255
for line in lines:
248256
match = ITEM_RE.match(line)
249257
if match:
250-
kind, name = match[2], match[3]
258+
_, kind, name = indentKindName(match)
251259
named_items.append((kind, name))
252260

253261
script = script_name
@@ -286,7 +294,7 @@ def pad(line):
286294
output_lines.append(line)
287295
continue
288296

289-
indent, kind, name = match.groups()
297+
indent, kind, name = indentKindName(match)
290298

291299
for prefix, items in output.items():
292300
# If the output for this prefix contains an item with this

test/lit/basic/empty_imported_table.wast

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
;; RUN: cat %t.bin.nodebug.wast | filecheck %s --check-prefix=CHECK-BIN-NODEBUG
1111

1212
(module
13-
;; CHECK-TEXT: (import "env" "table" (table $timport$0 0 0 funcref))
14-
;; CHECK-BIN: (import "env" "table" (table $timport$0 0 0 funcref))
15-
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 0 0 funcref))
1613
(import "env" "table" (table 0 0 funcref))
14+
;; CHECK-TEXT: (import "env" "table" (table $timport$0 0 0 funcref))
15+
1716
;; CHECK-TEXT: (memory $0 0)
17+
;; CHECK-BIN: (import "env" "table" (table $timport$0 0 0 funcref))
18+
1819
;; CHECK-BIN: (memory $0 0)
20+
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 0 0 funcref))
21+
1922
;; CHECK-BIN-NODEBUG: (memory $0 0)
2023
(memory $0 0)
2124
)

test/lit/basic/export-import.wast

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,26 @@
1414
;; CHECK-BIN: (type $v (func))
1515
(type $v (func))
1616
;; CHECK-TEXT: (import "env" "test2" (global $test2 i32))
17-
;; CHECK-BIN: (import "env" "test2" (global $test2 i32))
18-
;; CHECK-BIN-NODEBUG: (type $0 (func))
1917

20-
;; CHECK-BIN-NODEBUG: (import "env" "test2" (global $gimport$0 i32))
21-
(import "env" "test1" (func $test1))
2218
;; CHECK-TEXT: (import "env" "test1" (func $test1 (type $v)))
19+
;; CHECK-BIN: (import "env" "test2" (global $test2 i32))
20+
2321
;; CHECK-BIN: (import "env" "test1" (func $test1 (type $v)))
24-
;; CHECK-BIN-NODEBUG: (import "env" "test1" (func $fimport$0 (type $0)))
22+
(import "env" "test1" (func $test1))
2523
(import "env" "test2" (global $test2 i32))
2624
;; CHECK-TEXT: (export "test1" (func $test1))
2725
;; CHECK-BIN: (export "test1" (func $test1))
28-
;; CHECK-BIN-NODEBUG: (export "test1" (func $fimport$0))
2926
(export "test1" (func $test1))
3027
;; CHECK-TEXT: (export "test2" (global $test2))
3128
;; CHECK-BIN: (export "test2" (global $test2))
32-
;; CHECK-BIN-NODEBUG: (export "test2" (global $gimport$0))
3329
(export "test2" (global $test2))
3430
)
31+
;; CHECK-BIN-NODEBUG: (type $0 (func))
32+
33+
;; CHECK-BIN-NODEBUG: (import "env" "test2" (global $gimport$0 i32))
34+
35+
;; CHECK-BIN-NODEBUG: (import "env" "test1" (func $fimport$0 (type $0)))
36+
37+
;; CHECK-BIN-NODEBUG: (export "test1" (func $fimport$0))
38+
39+
;; CHECK-BIN-NODEBUG: (export "test2" (global $gimport$0))

test/lit/basic/hello_world.wat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
(memory $0 256 256)
2222
;; CHECK-TEXT: (export "add" (func $add))
2323
;; CHECK-BIN: (export "add" (func $add))
24-
;; CHECK-BIN-NODEBUG: (export "add" (func $0))
2524
(export "add" (func $add))
2625
;; CHECK-TEXT: (func $add (type $i32_i32_=>_i32) (param $x i32) (param $y i32) (result i32)
2726
;; CHECK-TEXT-NEXT: (i32.add
@@ -42,6 +41,8 @@
4241
)
4342
)
4443
)
44+
;; CHECK-BIN-NODEBUG: (export "add" (func $0))
45+
4546
;; CHECK-BIN-NODEBUG: (func $0 (type $0) (param $0 i32) (param $1 i32) (result i32)
4647
;; CHECK-BIN-NODEBUG-NEXT: (i32.add
4748
;; CHECK-BIN-NODEBUG-NEXT: (local.get $0)

test/lit/basic/imported_memory.wast

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
(module
1313
;; CHECK-TEXT: (import "env" "memory" (memory $0 256 256))
1414
;; CHECK-BIN: (import "env" "memory" (memory $0 256 256))
15-
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 256 256))
1615
(import "env" "memory" (memory $0 256 256))
17-
;; CHECK-TEXT: (import "env" "table" (table $timport$0 256 256 funcref))
18-
;; CHECK-BIN: (import "env" "table" (table $timport$0 256 256 funcref))
19-
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 256 256 funcref))
2016
(import "env" "table" (table 256 256 funcref))
2117
)
18+
;; CHECK-TEXT: (import "env" "table" (table $timport$0 256 256 funcref))
19+
20+
;; CHECK-BIN: (import "env" "table" (table $timport$0 256 256 funcref))
21+
22+
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 256 256))
23+
24+
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 256 256 funcref))

test/lit/basic/imported_memory_growth.wast

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
(module
1313
;; CHECK-TEXT: (import "env" "memory" (memory $0 256))
1414
;; CHECK-BIN: (import "env" "memory" (memory $0 256))
15-
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 256))
1615
(import "env" "memory" (memory $0 256))
17-
;; CHECK-TEXT: (import "env" "table" (table $timport$0 256 funcref))
18-
;; CHECK-BIN: (import "env" "table" (table $timport$0 256 funcref))
19-
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 256 funcref))
2016
(import "env" "table" (table 256 funcref))
2117
)
18+
;; CHECK-TEXT: (import "env" "table" (table $timport$0 256 funcref))
19+
20+
;; CHECK-BIN: (import "env" "table" (table $timport$0 256 funcref))
21+
22+
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 256))
23+
24+
;; CHECK-BIN-NODEBUG: (import "env" "table" (table $timport$0 256 funcref))

test/lit/basic/memory-import.wast

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
(type $0 (func (result i32)))
1717
;; CHECK-TEXT: (import "env" "memory" (memory $0 1 1))
1818
;; CHECK-BIN: (import "env" "memory" (memory $0 1 1))
19-
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 1 1))
2019
(import "env" "memory" (memory $0 1 1))
2120

2221
;; CHECK-TEXT: (func $foo (type $0) (result i32)
@@ -35,6 +34,8 @@
3534
)
3635
)
3736
)
37+
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 1 1))
38+
3839
;; CHECK-BIN-NODEBUG: (func $0 (type $0) (result i32)
3940
;; CHECK-BIN-NODEBUG-NEXT: (i32.load offset=13
4041
;; CHECK-BIN-NODEBUG-NEXT: (i32.const 37)

test/lit/basic/memory-import64.wast

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
(type $0 (func (result i32)))
1717
;; CHECK-TEXT: (import "env" "memory" (memory $0 i64 1 1))
1818
;; CHECK-BIN: (import "env" "memory" (memory $0 i64 1 1))
19-
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 i64 1 1))
2019
(import "env" "memory" (memory $0 i64 1 1))
2120

2221
;; CHECK-TEXT: (func $foo (type $0) (result i32)
@@ -35,6 +34,8 @@
3534
)
3635
)
3736
)
37+
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 i64 1 1))
38+
3839
;; CHECK-BIN-NODEBUG: (func $0 (type $0) (result i32)
3940
;; CHECK-BIN-NODEBUG-NEXT: (i32.load offset=13
4041
;; CHECK-BIN-NODEBUG-NEXT: (i64.const 37)

test/lit/basic/min.wast

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
(memory $0 256 256)
3333
;; CHECK-TEXT: (export "floats" (func $floats))
3434
;; CHECK-BIN: (export "floats" (func $floats))
35-
;; CHECK-BIN-NODEBUG: (export "floats" (func $0))
3635
(export "floats" (func $floats))
3736

3837
;; CHECK-TEXT: (func $floats (type $0) (param $f f32) (result f32)
@@ -183,6 +182,8 @@
183182
)
184183
)
185184
)
185+
;; CHECK-BIN-NODEBUG: (export "floats" (func $0))
186+
186187
;; CHECK-BIN-NODEBUG: (func $0 (type $0) (param $0 f32) (result f32)
187188
;; CHECK-BIN-NODEBUG-NEXT: (local $1 f32)
188189
;; CHECK-BIN-NODEBUG-NEXT: (f32.add

test/lit/basic/multi-memories-basics.wast

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
(type $none_=>_i32 (func (result i32)))
1919
;; CHECK-TEXT: (import "env" "memory" (memory $importedMemory 1 1))
2020
;; CHECK-BIN: (import "env" "memory" (memory $importedMemory 1 1))
21-
;; CHECK-BIN-NODEBUG: (type $0 (func))
22-
23-
;; CHECK-BIN-NODEBUG: (type $1 (func (result i32)))
24-
25-
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 1 1))
2621
(import "env" "memory" (memory $importedMemory 1 1))
2722
;; CHECK-TEXT: (memory $memory1 1 500)
2823
;; CHECK-BIN: (memory $memory1 1 500)
@@ -367,6 +362,12 @@
367362
)
368363
)
369364
)
365+
;; CHECK-BIN-NODEBUG: (type $0 (func))
366+
367+
;; CHECK-BIN-NODEBUG: (type $1 (func (result i32)))
368+
369+
;; CHECK-BIN-NODEBUG: (import "env" "memory" (memory $mimport$0 1 1))
370+
370371
;; CHECK-BIN-NODEBUG: (memory $0 1 500)
371372

372373
;; CHECK-BIN-NODEBUG: (memory $1 1 800)

0 commit comments

Comments
 (0)