| OLD | NEW |
| 1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
| 2 | 2 |
| 3 import argparse | 3 import argparse |
| 4 import itertools | 4 import itertools |
| 5 import os | 5 import os |
| 6 import re | 6 import re |
| 7 import subprocess | 7 import subprocess |
| 8 import sys | 8 import sys |
| 9 import tempfile | 9 import tempfile |
| 10 | 10 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 argparser.add_argument('--target', default='x8632', dest='target', | 87 argparser.add_argument('--target', default='x8632', dest='target', |
| 88 choices=['x8632','x8664','arm32','mips32'], | 88 choices=['x8632','x8664','arm32','mips32'], |
| 89 help='Target architecture. Default %(default)s') | 89 help='Target architecture. Default %(default)s') |
| 90 argparser.add_argument('--echo-cmd', required=False, | 90 argparser.add_argument('--echo-cmd', required=False, |
| 91 action='store_true', | 91 action='store_true', |
| 92 help='Trace command that generates ICE instructions') | 92 help='Trace command that generates ICE instructions') |
| 93 argparser.add_argument('--tbc', required=False, action='store_true', | 93 argparser.add_argument('--tbc', required=False, action='store_true', |
| 94 help='Input is textual bitcode (not .ll)') | 94 help='Input is textual bitcode (not .ll)') |
| 95 argparser.add_argument('--expect-fail', required=False, action='store_true', | 95 argparser.add_argument('--expect-fail', required=False, action='store_true', |
| 96 help='Negate success of run by using LLVM not') | 96 help='Negate success of run by using LLVM not') |
| 97 argparser.add_argument('--allow-pnacl-reader-error-recovery', |
| 98 action='store_true', |
| 99 help='Continue parsing after first error') |
| 97 argparser.add_argument('--args', '-a', nargs=argparse.REMAINDER, | 100 argparser.add_argument('--args', '-a', nargs=argparse.REMAINDER, |
| 98 default=[], | 101 default=[], |
| 99 help='Remaining arguments are passed to pnacl-sz') | 102 help='Remaining arguments are passed to pnacl-sz') |
| 100 argparser.add_argument('--sandbox', required=False, action='store_true', | 103 argparser.add_argument('--sandbox', required=False, action='store_true', |
| 101 help='Sandboxes the generated code') | 104 help='Sandboxes the generated code') |
| 102 | 105 |
| 103 args = argparser.parse_args() | 106 args = argparser.parse_args() |
| 104 pnacl_bin_path = args.pnacl_bin_path | 107 pnacl_bin_path = args.pnacl_bin_path |
| 105 llfile = args.input | 108 llfile = args.input |
| 106 | 109 |
| 107 if args.llvm and args.llvm_source: | 110 if args.llvm and args.llvm_source: |
| 108 raise RuntimeError("Can't specify both '--llvm' and '--llvm-source'") | 111 raise RuntimeError("Can't specify both '--llvm' and '--llvm-source'") |
| 109 | 112 |
| 110 if args.llvm_source and args.no_local_syms: | 113 if args.llvm_source and args.no_local_syms: |
| 111 raise RuntimeError("Can't specify both '--llvm-source' and " + | 114 raise RuntimeError("Can't specify both '--llvm-source' and " + |
| 112 "'--no-local-syms'") | 115 "'--no-local-syms'") |
| 113 | 116 |
| 114 if args.llvm_source and args.tbc: | 117 if args.llvm_source and args.tbc: |
| 115 raise RuntimeError("Can't specify both '--tbc' and '--llvm-source'") | 118 raise RuntimeError("Can't specify both '--tbc' and '--llvm-source'") |
| 116 | 119 |
| 117 if args.llvm and args.tbc: | 120 if args.llvm and args.tbc: |
| 118 raise RuntimeError("Can't specify both '--tbc' and '--llvm'") | 121 raise RuntimeError("Can't specify both '--tbc' and '--llvm'") |
| 119 | 122 |
| 120 if args.forceasm: | 123 if args.forceasm: |
| 121 if args.filetype == 'asm': | 124 if args.expect_fail: |
| 125 args.forceasm = False |
| 126 elif args.filetype == 'asm': |
| 122 pass | 127 pass |
| 123 elif args.filetype == 'iasm': | 128 elif args.filetype == 'iasm': |
| 124 # TODO(sehr) implement forceasm for iasm. | 129 # TODO(sehr) implement forceasm for iasm. |
| 125 pass | 130 pass |
| 126 elif args.filetype == 'obj': | 131 elif args.filetype == 'obj': |
| 127 args.filetype = 'asm' | 132 args.filetype = 'asm' |
| 128 args.assemble = True | 133 args.assemble = True |
| 129 | 134 |
| 130 cmd = [] | 135 cmd = [] |
| 131 if args.tbc: | 136 if args.tbc: |
| 132 cmd = [os.path.join(pnacl_bin_path, 'pnacl-bcfuzz'), llfile, | 137 cmd = [os.path.join(pnacl_bin_path, 'pnacl-bcfuzz'), llfile, |
| 133 '-bitcode-as-text', '-output', '-', '|'] | 138 '-bitcode-as-text', '-output', '-', '|'] |
| 134 elif not args.llvm_source: | 139 elif not args.llvm_source: |
| 135 cmd = [os.path.join(pnacl_bin_path, 'llvm-as'), llfile, '-o', '-', '|', | 140 cmd = [os.path.join(pnacl_bin_path, 'llvm-as'), llfile, '-o', '-', '|', |
| 136 os.path.join(pnacl_bin_path, 'pnacl-freeze')] | 141 os.path.join(pnacl_bin_path, 'pnacl-freeze')] |
| 137 if not args.no_local_syms: | 142 if not args.no_local_syms: |
| 138 cmd += ['--allow-local-symbol-tables'] | 143 cmd += ['--allow-local-symbol-tables'] |
| 139 cmd += ['|'] | 144 cmd += ['|'] |
| 140 if args.expect_fail: | 145 if args.expect_fail: |
| 141 cmd += [os.path.join(pnacl_bin_path, 'not')] | 146 cmd += [os.path.join(pnacl_bin_path, 'not')] |
| 142 cmd += [args.pnacl_sz] | 147 cmd += [args.pnacl_sz] |
| 143 cmd += ['--target', args.target] | 148 cmd += ['--target', args.target] |
| 144 if args.sandbox: | 149 if args.sandbox: |
| 145 cmd += ['-sandbox'] | 150 cmd += ['-sandbox'] |
| 146 if args.insts: | 151 if args.insts: |
| 147 # If the tests are based on '-verbose inst' output, force | 152 # If the tests are based on '-verbose inst' output, force |
| 148 # single-threaded translation because dump output does not get | 153 # single-threaded translation because dump output does not get |
| 149 # reassembled into order. | 154 # reassembled into order. |
| 150 cmd += ['-verbose', 'inst,global_init', '-notranslate', '-threads=0'] | 155 cmd += ['-verbose', 'inst,global_init', '-notranslate', '-threads=0'] |
| 156 elif args.allow_pnacl_reader_error_recovery: |
| 157 cmd += ['-allow-pnacl-reader-error-recovery', '-threads=0'] |
| 151 if not args.llvm_source: | 158 if not args.llvm_source: |
| 152 cmd += ['--bitcode-format=pnacl'] | 159 cmd += ['--bitcode-format=pnacl'] |
| 153 if not args.no_local_syms: | 160 if not args.no_local_syms: |
| 154 cmd += ['--allow-local-symbol-tables'] | 161 cmd += ['--allow-local-symbol-tables'] |
| 155 if args.llvm or args.llvm_source: | 162 if args.llvm or args.llvm_source: |
| 156 cmd += ['--build-on-read=0'] | 163 cmd += ['--build-on-read=0'] |
| 157 else: | 164 else: |
| 158 cmd += ['--build-on-read=1'] | 165 cmd += ['--build-on-read=1'] |
| 159 cmd += ['--filetype=' + args.filetype] | 166 cmd += ['--filetype=' + args.filetype] |
| 160 script_name = os.path.basename(sys.argv[0]) | 167 script_name = os.path.basename(sys.argv[0]) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 [output_file_name]) | 208 [output_file_name]) |
| 202 | 209 |
| 203 stdout_result = shellcmd(cmd, echo=args.echo_cmd) | 210 stdout_result = shellcmd(cmd, echo=args.echo_cmd) |
| 204 if not args.echo_cmd: | 211 if not args.echo_cmd: |
| 205 sys.stdout.write(stdout_result) | 212 sys.stdout.write(stdout_result) |
| 206 if asm_temp and not keep_output_file: | 213 if asm_temp and not keep_output_file: |
| 207 os.remove(output_file_name) | 214 os.remove(output_file_name) |
| 208 | 215 |
| 209 if __name__ == '__main__': | 216 if __name__ == '__main__': |
| 210 main() | 217 main() |
| OLD | NEW |