|
37 | 37 | CHECK_PREFIX_RE = re.compile(r'.*--check-prefix[= ](\S+).*') |
38 | 38 | MODULE_RE = re.compile(r'^\(module.*$', re.MULTILINE) |
39 | 39 |
|
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 |
42 | 45 |
|
43 | 46 | # Regular names as well as the "declare" in (elem declare ... to get declarative |
44 | 47 | # segments included in the output. |
45 | | -ITEM_NAME = r'\$[^\s()]*|"[^\s()]*"|declare' |
| 48 | +ITEM_NAME = r'\$[^\s()]*|\$"[^"]*"|declare' |
46 | 49 |
|
47 | 50 | # FIXME: This does not handle nested string contents. For example, |
48 | 51 | # (data (i32.const 10) "hello(") |
|
55 | 58 | FUZZ_EXEC_FUNC = re.compile(r'^\[fuzz-exec\] calling (?P<name>\S*)$') |
56 | 59 |
|
57 | 60 |
|
| 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 | + |
58 | 66 | def warn(msg): |
59 | 67 | print(f'warning: {msg}', file=sys.stderr) |
60 | 68 |
|
@@ -141,7 +149,7 @@ def parse_output_modules(text): |
141 | 149 | for module in split_modules(text): |
142 | 150 | items = [] |
143 | 151 | for match in ITEM_RE.finditer(module): |
144 | | - kind, name = match[2], match[3] |
| 152 | + _, kind, name = indentKindName(match) |
145 | 153 | end = find_end(module, match.end(1)) |
146 | 154 | lines = module[match.start():end].split('\n') |
147 | 155 | items.append(((kind, name), lines)) |
@@ -247,7 +255,7 @@ def update_test(args, test, lines, tmp): |
247 | 255 | for line in lines: |
248 | 256 | match = ITEM_RE.match(line) |
249 | 257 | if match: |
250 | | - kind, name = match[2], match[3] |
| 258 | + _, kind, name = indentKindName(match) |
251 | 259 | named_items.append((kind, name)) |
252 | 260 |
|
253 | 261 | script = script_name |
@@ -286,7 +294,7 @@ def pad(line): |
286 | 294 | output_lines.append(line) |
287 | 295 | continue |
288 | 296 |
|
289 | | - indent, kind, name = match.groups() |
| 297 | + indent, kind, name = indentKindName(match) |
290 | 298 |
|
291 | 299 | for prefix, items in output.items(): |
292 | 300 | # If the output for this prefix contains an item with this |
|
0 commit comments