Index: utils/update_llc_test_checks.py =================================================================== --- utils/update_llc_test_checks.py +++ utils/update_llc_test_checks.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 """A test case update script. @@ -9,7 +9,6 @@ import argparse import os # Used to advertise this file's name ("autogenerated_note"). -import string import subprocess import sys import re @@ -18,7 +17,7 @@ def llc(args, cmd_args, ir): with open(ir) as ir_file: stdout = subprocess.check_output(args.llc_binary + ' ' + cmd_args, - shell=True, stdin=ir_file) + shell=True, stdin=ir_file).decode() # Fix line endings to unix CR style. stdout = stdout.replace('\r\n', '\n') return stdout @@ -108,7 +107,7 @@ # whitespace in place. asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) # Expand the tabs used for indentation. - asm = string.expandtabs(asm, 2) + asm = str.expandtabs(asm, 2) # Detect shuffle asm comments and hide the operands in favor of the comments. asm = SCRUB_X86_SHUFFLES_RE.sub(r'\1 {{.*#+}} \2', asm) # Generically match the stack offset of a memory operand. @@ -131,7 +130,7 @@ # whitespace in place. asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) # Expand the tabs used for indentation. - asm = string.expandtabs(asm, 2) + asm = str.expandtabs(asm, 2) # Strip kill operands inserted into the asm. asm = SCRUB_KILL_COMMENT_RE.sub('', asm) # Strip trailing whitespace. @@ -143,7 +142,7 @@ # whitespace in place. asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) # Expand the tabs used for indentation. - asm = string.expandtabs(asm, 2) + asm = str.expandtabs(asm, 2) # Stripe unimportant comments asm = SCRUB_LOOP_COMMENT_RE.sub(r'', asm) # Strip trailing whitespace. @@ -155,7 +154,7 @@ # whitespace in place. asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) # Expand the tabs used for indentation. - asm = string.expandtabs(asm, 2) + asm = str.expandtabs(asm, 2) # Strip trailing whitespace. asm = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) return asm @@ -165,7 +164,7 @@ # whitespace in place. asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) # Expand the tabs used for indentation. - asm = string.expandtabs(asm, 2) + asm = str.expandtabs(asm, 2) # Strip trailing whitespace. asm = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) return asm @@ -175,7 +174,7 @@ # whitespace in place. asm = SCRUB_WHITESPACE_RE.sub(r' ', asm) # Expand the tabs used for indentation. - asm = string.expandtabs(asm, 2) + asm = str.expandtabs(asm, 2) # Strip trailing whitespace. asm = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', asm) return asm @@ -219,7 +218,7 @@ 's390x': (scrub_asm_systemz, ASM_FUNCTION_SYSTEMZ_RE), } handlers = None - for prefix, s in target_handlers.items(): + for prefix, s in list(target_handlers.items()): if triple.startswith(prefix): handlers = s break @@ -236,14 +235,14 @@ # We only use the last line of the function body for stress tests. scrubbed_body = '\n'.join(scrubbed_body.splitlines()[-1:]) if args.verbose: - print >>sys.stderr, 'Processing function: ' + func + print('Processing function: ' + func, file=sys.stderr) for l in scrubbed_body.splitlines(): - print >>sys.stderr, ' ' + l + print(' ' + l, file=sys.stderr) for prefix in prefixes: if func in func_dict[prefix] and func_dict[prefix][func] != scrubbed_body: if prefix == prefixes[-1]: - print >>sys.stderr, ('WARNING: Found conflicting asm under the ' - 'same prefix: %r!' % (prefix,)) + print(('WARNING: Found conflicting asm under the ' + 'same prefix: %r!' % (prefix,)), file=sys.stderr) else: func_dict[prefix][func] = None continue @@ -309,7 +308,7 @@ for test in args.tests: if args.verbose: - print >>sys.stderr, 'Scanning for RUN lines in test file: %s' % (test,) + print('Scanning for RUN lines in test file: %s' % (test,), file=sys.stderr) with open(test) as f: input_lines = [l.rstrip() for l in f] @@ -330,9 +329,9 @@ run_lines.append(l) if args.verbose: - print >>sys.stderr, 'Found %d RUN lines:' % (len(run_lines),) + print('Found %d RUN lines:' % (len(run_lines),), file=sys.stderr) for l in run_lines: - print >>sys.stderr, ' RUN: ' + l + print(' RUN: ' + l, file=sys.stderr) run_list = [] for l in run_lines: @@ -348,11 +347,11 @@ if len(commands) > 1: filecheck_cmd = commands[1] if not llc_cmd.startswith('llc '): - print >>sys.stderr, 'WARNING: Skipping non-llc RUN line: ' + l + print('WARNING: Skipping non-llc RUN line: ' + l, file=sys.stderr) continue if not filecheck_cmd.startswith('FileCheck '): - print >>sys.stderr, 'WARNING: Skipping non-FileChecked RUN line: ' + l + print('WARNING: Skipping non-FileChecked RUN line: ' + l, file=sys.stderr) continue llc_cmd_args = llc_cmd[len('llc'):].strip() @@ -374,12 +373,12 @@ func_dict.update({prefix: dict()}) for prefixes, llc_args, triple_in_cmd in run_list: if args.verbose: - print >>sys.stderr, 'Extracted LLC cmd: llc ' + llc_args - print >>sys.stderr, 'Extracted FileCheck prefixes: ' + str(prefixes) + print('Extracted LLC cmd: llc ' + llc_args, file=sys.stderr) + print('Extracted FileCheck prefixes: ' + str(prefixes), file=sys.stderr) raw_tool_output = llc(args, llc_args, test) if not (triple_in_cmd or triple_in_ir): - print >>sys.stderr, "Cannot find a triple. Assume 'x86'" + print("Cannot find a triple. Assume 'x86'", file=sys.stderr) build_function_body_dictionary(raw_tool_output, triple_in_cmd or triple_in_ir or 'x86', prefixes, func_dict, args) @@ -389,7 +388,7 @@ func_name = None prefix_set = set([prefix for p in run_list for prefix in p[0]]) if args.verbose: - print >>sys.stderr, 'Rewriting FileCheck prefixes: %s' % (prefix_set,) + print('Rewriting FileCheck prefixes: %s' % (prefix_set,), file=sys.stderr) output_lines = [] output_lines.append(autogenerated_note) @@ -433,9 +432,9 @@ is_in_function = is_in_function_start = True if args.verbose: - print>>sys.stderr, 'Writing %d lines to %s...' % (len(output_lines), test) + print('Writing %d lines to %s...' % (len(output_lines), test), file=sys.stderr) - with open(test, 'wb') as f: + with open(test, 'w') as f: f.writelines([l + '\n' for l in output_lines]) Index: utils/update_test_checks.py =================================================================== --- utils/update_test_checks.py +++ utils/update_test_checks.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 """A script to generate FileCheck statements for 'opt' regression tests. @@ -32,7 +32,6 @@ import argparse import itertools import os # Used to advertise this file's name ("autogenerated_note"). -import string import subprocess import sys import tempfile @@ -65,7 +64,7 @@ def invoke_tool(args, cmd_args, ir): with open(ir) as ir_file: stdout = subprocess.check_output(args.opt_binary + ' ' + cmd_args, - shell=True, stdin=ir_file) + shell=True, stdin=ir_file).decode() # Fix line endings to unix CR style. stdout = stdout.replace('\r\n', '\n') return stdout @@ -76,7 +75,7 @@ # whitespace in place. body = SCRUB_WHITESPACE_RE.sub(r' ', body) # Expand the tabs used for indentation. - body = string.expandtabs(body, 2) + body = str.expandtabs(body, 2) # Strip trailing whitespace. body = SCRUB_TRAILING_WHITESPACE_RE.sub(r'', body) return body @@ -94,14 +93,14 @@ # We only use the last line of the function body for stress tests. scrubbed_body = '\n'.join(scrubbed_body.splitlines()[-1:]) if verbose: - print >>sys.stderr, 'Processing function: ' + func + print('Processing function: ' + func, file=sys.stderr) for l in scrubbed_body.splitlines(): - print >>sys.stderr, ' ' + l + print(' ' + l, file=sys.stderr) for prefix in prefixes: if func in func_dict[prefix] and func_dict[prefix][func] != scrubbed_body: if prefix == prefixes[-1]: - print >>sys.stderr, ('WARNING: Found conflicting asm under the ' - 'same prefix: %r!' % (prefix,)) + print(('WARNING: Found conflicting asm under the ' + 'same prefix: %r!' % (prefix,)), file=sys.stderr) else: func_dict[prefix][func] = None continue @@ -244,12 +243,12 @@ opt_basename = os.path.basename(args.opt_binary) if (opt_basename != "opt"): - print >>sys.stderr, 'ERROR: Unexpected opt name: ' + opt_basename + print('ERROR: Unexpected opt name: ' + opt_basename, file=sys.stderr) sys.exit(1) for test in args.tests: if args.verbose: - print >>sys.stderr, 'Scanning for RUN lines in test file: %s' % (test,) + print('Scanning for RUN lines in test file: %s' % (test,), file=sys.stderr) with open(test) as f: input_lines = [l.rstrip() for l in f] @@ -263,20 +262,20 @@ run_lines.append(l) if args.verbose: - print >>sys.stderr, 'Found %d RUN lines:' % (len(run_lines),) + print('Found %d RUN lines:' % (len(run_lines),), file=sys.stderr) for l in run_lines: - print >>sys.stderr, ' RUN: ' + l + print(' RUN: ' + l, file=sys.stderr) prefix_list = [] for l in run_lines: (tool_cmd, filecheck_cmd) = tuple([cmd.strip() for cmd in l.split('|', 1)]) if not tool_cmd.startswith(opt_basename + ' '): - print >>sys.stderr, 'WARNING: Skipping non-%s RUN line: %s' % (opt_basename, l) + print('WARNING: Skipping non-%s RUN line: %s' % (opt_basename, l), file=sys.stderr) continue if not filecheck_cmd.startswith('FileCheck '): - print >>sys.stderr, 'WARNING: Skipping non-FileChecked RUN line: ' + l + print('WARNING: Skipping non-FileChecked RUN line: ' + l, file=sys.stderr) continue tool_cmd_args = tool_cmd[len(opt_basename):].strip() @@ -297,8 +296,8 @@ func_dict.update({prefix: dict()}) for prefixes, opt_args in prefix_list: if args.verbose: - print >>sys.stderr, 'Extracted opt cmd: ' + opt_basename + ' ' + opt_args - print >>sys.stderr, 'Extracted FileCheck prefixes: ' + str(prefixes) + print('Extracted opt cmd: ' + opt_basename + ' ' + opt_args, file=sys.stderr) + print('Extracted FileCheck prefixes: ' + str(prefixes), file=sys.stderr) raw_tool_output = invoke_tool(args, opt_args, test) build_function_body_dictionary(raw_tool_output, prefixes, func_dict, args.verbose, opt_basename) @@ -307,7 +306,7 @@ is_in_function_start = False prefix_set = set([prefix for prefixes, _ in prefix_list for prefix in prefixes]) if args.verbose: - print >>sys.stderr, 'Rewriting FileCheck prefixes: %s' % (prefix_set,) + print('Rewriting FileCheck prefixes: %s' % (prefix_set,), file=sys.stderr) output_lines = [] output_lines.append(autogenerated_note) @@ -354,12 +353,11 @@ is_in_function = is_in_function_start = True if args.verbose: - print>>sys.stderr, 'Writing %d lines to %s...' % (len(output_lines), test) + print('Writing %d lines to %s...' % (len(output_lines), test), file=sys.stderr) - with open(test, 'wb') as f: + with open(test, 'w') as f: f.writelines([l + '\n' for l in output_lines]) if __name__ == '__main__': main() -