diff options
author | Thomas Lively <tlively@google.com> | 2024-01-02 12:08:33 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-02 12:08:33 -0800 |
commit | 95ed4f3f0bf0a463cee88a63c5becde4d28692ff (patch) | |
tree | 9aa47f97492132f134df4f30c33c7b143a03455b /scripts | |
parent | 98cef80eabe2171bb3076767d68b25a85d268c12 (diff) | |
download | binaryen-95ed4f3f0bf0a463cee88a63c5becde4d28692ff.tar.gz binaryen-95ed4f3f0bf0a463cee88a63c5becde4d28692ff.tar.bz2 binaryen-95ed4f3f0bf0a463cee88a63c5becde4d28692ff.zip |
Match names more precisely in update_lit_checks.py (#6190)
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.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/update_lit_checks.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/scripts/update_lit_checks.py b/scripts/update_lit_checks.py index 79af92ab9..345ff39d0 100755 --- a/scripts/update_lit_checks.py +++ b/scripts/update_lit_checks.py @@ -37,12 +37,15 @@ RUN_LINE_RE = re.compile(r'^\s*;;\s*RUN:\s*(.*)$') CHECK_PREFIX_RE = re.compile(r'.*--check-prefix[= ](\S+).*') MODULE_RE = re.compile(r'^\(module.*$', re.MULTILINE) -ALL_ITEMS = '|'.join(['type', 'import', 'global', 'memory', 'data', 'table', - 'elem', 'tag', 'export', 'start', 'func']) +DECL_ITEMS = '|'.join(['type', 'global', 'memory', 'data', 'table', + 'elem', 'tag', 'start', 'func']) +IMPORT_ITEM = r'import\s*"[^"]*"\s*"[^"]*"\s*\((?:' + DECL_ITEMS + ')' +EXPORT_ITEM = r'export\s*"[^"]*"\s*\((?:' + DECL_ITEMS + ')' +ALL_ITEMS = DECL_ITEMS + '|' + IMPORT_ITEM + '|' + EXPORT_ITEM # Regular names as well as the "declare" in (elem declare ... to get declarative # segments included in the output. -ITEM_NAME = r'\$[^\s()]*|"[^\s()]*"|declare' +ITEM_NAME = r'\$[^\s()]*|\$"[^"]*"|declare' # FIXME: This does not handle nested string contents. For example, # (data (i32.const 10) "hello(") @@ -55,6 +58,11 @@ ITEM_RE = re.compile(r'(?:^\s*\(rec\s*)?(^\s*)\((' + ALL_ITEMS + r')\s+(' + ITEM FUZZ_EXEC_FUNC = re.compile(r'^\[fuzz-exec\] calling (?P<name>\S*)$') +def indentKindName(match): + # Return the indent, kind, and name from an ITEM_RE match + return (match[1], match[2].split()[0], match[3]) + + def warn(msg): print(f'warning: {msg}', file=sys.stderr) @@ -141,7 +149,7 @@ def parse_output_modules(text): for module in split_modules(text): items = [] for match in ITEM_RE.finditer(module): - kind, name = match[2], match[3] + _, kind, name = indentKindName(match) end = find_end(module, match.end(1)) lines = module[match.start():end].split('\n') items.append(((kind, name), lines)) @@ -247,7 +255,7 @@ def update_test(args, test, lines, tmp): for line in lines: match = ITEM_RE.match(line) if match: - kind, name = match[2], match[3] + _, kind, name = indentKindName(match) named_items.append((kind, name)) script = script_name @@ -286,7 +294,7 @@ def update_test(args, test, lines, tmp): output_lines.append(line) continue - indent, kind, name = match.groups() + indent, kind, name = indentKindName(match) for prefix, items in output.items(): # If the output for this prefix contains an item with this |