summaryrefslogtreecommitdiff
path: root/scripts/update_lit_checks.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/update_lit_checks.py')
-rwxr-xr-xscripts/update_lit_checks.py58
1 files changed, 44 insertions, 14 deletions
diff --git a/scripts/update_lit_checks.py b/scripts/update_lit_checks.py
index bd3fbe208..083298f57 100755
--- a/scripts/update_lit_checks.py
+++ b/scripts/update_lit_checks.py
@@ -29,9 +29,9 @@ import tempfile
script_name = os.path.basename(__file__)
-NOTICE = (f';; NOTE: Assertions have been generated by {script_name} and ' +
- 'should not be edited.')
+NOTICE = (';; NOTE: Assertions have been generated by {script} and should not' +
+ ' be edited.')
RUN_LINE_RE = re.compile(r'^\s*;;\s*RUN:\s*(.*)$')
CHECK_PREFIX_RE = re.compile(r'.*--check-prefix[= ](\S+).*')
@@ -123,6 +123,10 @@ def main():
' directory. Default: bin/ of current directory (i.e. assume an'
' in-tree build).'))
parser.add_argument(
+ '--all-items', action='store_true',
+ help=('Emit checks for all module items, even those that do not appear'
+ ' in the input.'))
+ parser.add_argument(
'-f', '--force', action='store_true',
help=('Generate FileCheck patterns even for test files whose existing '
'patterns were not generated by this script.'))
@@ -137,6 +141,14 @@ def main():
tmp = tempfile.mktemp()
for test, lines in itertests(args):
+ all_items = args.all_items
+ if lines and script_name in lines[0]:
+ # Apply previously used options for this file
+ if '--all-items' in lines[0]:
+ all_items = True
+ # Skip the notice if it is already in the output
+ lines = lines[1:]
+
# List of (prefix, command)
run_list = []
for line in find_run_lines(test, lines):
@@ -156,7 +168,7 @@ def main():
run_list.append((check_prefix, commands[0]))
- # Map check prefixes to lists of ((kind, name), [lines])
+ # Map check prefixes to lists of ((kind, name), [line])
output_modules = {}
for prefix, command, in run_list:
output = run_command(args, test, tmp, command)
@@ -166,16 +178,16 @@ def main():
any_prefix = '|'.join(output_modules.keys())
check_line_re = re.compile(r'^\s*;;\s*(' + any_prefix +
r')(?:-NEXT|-LABEL|-NOT)?:.*$')
- output_lines = [NOTICE]
- def emit_checks(indent, prefix, lines):
- output_lines.append(f'{indent};; {prefix}: {lines[0]}')
- for line in lines[1:]:
- output_lines.append(f'{indent};; {prefix}-NEXT:{line}')
-
- # Skip the notice if it is already in the output
- if lines and script_name in lines[0]:
- lines = lines[1:]
+ # Filter out whitespace between check blocks
+ if lines:
+ filtered = [lines[0]]
+ for i in range(1, len(lines) - 1):
+ if lines[i] or not check_line_re.match(lines[i - 1]) or \
+ not check_line_re.match(lines[i + 1]):
+ filtered.append(lines[i])
+ filtered.append(lines[-1])
+ lines = filtered
named_items = []
for line in lines:
@@ -184,6 +196,16 @@ def main():
kind, name = match[2], match[3]
named_items.append((kind, name))
+ script = script_name
+ if all_items:
+ script += ' --all-items'
+ output_lines = [NOTICE.format(script=script)]
+
+ def emit_checks(indent, prefix, lines):
+ output_lines.append(f'{indent};; {prefix}: {lines[0]}')
+ for line in lines[1:]:
+ output_lines.append(f'{indent};; {prefix}-NEXT:{line}')
+
for line in lines:
# Skip pre-existing check lines; we will regenerate them.
if check_line_re.match(line):
@@ -201,17 +223,25 @@ def main():
has_item = True
break
if has_item:
+ first = True
while True:
kind_name, lines = items.pop(0)
- if kind_name in named_items:
+ if all_items or kind_name in named_items:
+ if not first:
+ output_lines.append('')
+ first = False
emit_checks(indent, prefix, lines)
if name and (kind, name) == kind_name:
break
output_lines.append(line)
# Output any remaining checks for each prefix
+ first = True
for prefix, items in output_modules.items():
for kind_name, lines in items:
- if kind_name in named_items:
+ if all_items or kind_name in named_items:
+ if not first:
+ output_lines.append('')
+ first = False
emit_checks('', prefix, lines)
if args.dry_run: