diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py --- a/llvm/utils/UpdateTestChecks/common.py +++ b/llvm/utils/UpdateTestChecks/common.py @@ -49,6 +49,8 @@ CHECK_PREFIX_RE = re.compile(r'--?check-prefix(?:es)?[= ](\S+)') PREFIX_RE = re.compile('^[a-zA-Z0-9_-]+$') CHECK_RE = re.compile(r'^\s*[;#]\s*([^:]+?)(?:-NEXT|-NOT|-DAG|-LABEL|-SAME)?:') +UTC_ARGS_KEY = 'UTC_ARGS:' +UTC_ARGS_CMD = re.compile(r'.*' + UTC_ARGS_KEY + '\s*(?P.*)\s*$') OPT_FUNCTION_RE = re.compile( r'^\s*define\s+(?:internal\s+)?[^@]*@(?P[\w-]+?)\s*' @@ -357,3 +359,26 @@ check_prefix(prefix) if prefixes.count(prefix) > 1: warn("Supplied prefix '%s' is not unique in the prefix list." % (prefix,)) + +def get_autogennote_suffix(parser, args): + autogenerated_note_args = '' + for k, v in args._get_kwargs(): + if parser.get_default(k) == v or k == 'tests': + continue + k = k.replace('_', '-') + if type(v) is bool: + autogenerated_note_args += '--%s' % (k) + else: + autogenerated_note_args += '--%s %s' % (k, v) + if autogenerated_note_args: + autogenerated_note_args = ' %s %s' % (UTC_ARGS_KEY, autogenerated_note_args) + return autogenerated_note_args + + +def check_for_command(line, parser, args, argv): + cmd_m = UTC_ARGS_CMD.match(line) + if cmd_m: + cmd = cmd_m.group('cmd').strip().split(' ') + argv += cmd + args = parser.parse_args(argv) + return args diff --git a/llvm/utils/update_test_checks.py b/llvm/utils/update_test_checks.py --- a/llvm/utils/update_test_checks.py +++ b/llvm/utils/update_test_checks.py @@ -70,6 +70,8 @@ help='Keep function signature information around for the check line') parser.add_argument('--scrub-attributes', action='store_true', help='Remove attribute annotations (#0) from the end of check line') + parser.add_argument('--turn', choices=['on', 'off'], default='on', + help='Initial state, check lines are upded only in "on" state') parser.add_argument('tests', nargs='+') args = parser.parse_args() @@ -94,6 +96,7 @@ # On Windows we must expand the patterns ourselves. test_paths = [test for pattern in args.tests for test in glob.glob(pattern)] for test in test_paths: + argv = sys.argv[:] if args.verbose: print('Scanning for RUN lines in test file: ' + test, file=sys.stderr) with open(test) as f: @@ -103,6 +106,9 @@ if 'autogenerated' in first_line and script_name not in first_line: common.warn("Skipping test which wasn't autogenerated by " + script_name, test) continue + if first_line and 'autogenerated' in first_line: + args = common.check_for_command(first_line, parser, args, argv) + autogenerated_note += common.get_autogennote_suffix(parser, args) if args.update_only: if not first_line or 'autogenerated' not in first_line: @@ -175,6 +181,14 @@ output_lines.append(autogenerated_note) for input_line in input_lines: + # Discard any previous script advertising. + if input_line.startswith(ADVERT): + continue + + args = common.check_for_command(input_line, parser, args, argv) + if args.turn == 'off': + output_lines.append(input_line) + continue if is_in_function_start: if input_line == '': continue @@ -201,10 +215,6 @@ is_in_function = False continue - # Discard any previous script advertising. - if input_line.startswith(ADVERT): - continue - # If it's outside a function, it just gets copied to the output. output_lines.append(input_line)