| 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 |
| 11 from utils import shellcmd | 11 from utils import shellcmd |
| 12 | 12 |
| 13 | 13 |
| 14 def TargetAssemblerFlags(target): | 14 def TargetAssemblerFlags(target, sandboxed): |
| 15 # TODO(stichnot): -triple=i686-nacl should be used for a | |
| 16 # sandboxing test. This means there should be an args.sandbox | |
| 17 # argument that also gets passed through to pnacl-sz. | |
| 18 # TODO(reed kotler). Need to find out exactly we need to | 15 # TODO(reed kotler). Need to find out exactly we need to |
| 19 # add here for Mips32. | 16 # add here for Mips32. |
| 20 flags = { 'x8632': ['-triple=i686'], | 17 flags = { 'x8632': ['-triple=%s' % ('i686-nacl' if sandboxed else 'i686')], |
| 21 'arm32': ['-triple=armv7a', '-mcpu=cortex-a9', '-mattr=+neon'], | 18 'arm32': ['-triple=%s' % ( |
| 19 'armv7a-nacl' if sandboxed else 'armv7a'), |
| 20 '-mcpu=cortex-a9', '-mattr=+neon'], |
| 22 'mips32': ['-triple=mipsel' ] } | 21 'mips32': ['-triple=mipsel' ] } |
| 23 return flags[target] | 22 return flags[target] |
| 24 | 23 |
| 25 | 24 |
| 26 def TargetDisassemblerFlags(target): | 25 def TargetDisassemblerFlags(target): |
| 27 flags = { 'x8632': ['-Mintel'], | 26 flags = { 'x8632': ['-Mintel'], |
| 28 'arm32': [], | 27 'arm32': [], |
| 29 'mips32':[] } | 28 'mips32':[] } |
| 30 return flags[target] | 29 return flags[target] |
| 31 | 30 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 argparser.add_argument('--echo-cmd', required=False, | 81 argparser.add_argument('--echo-cmd', required=False, |
| 83 action='store_true', | 82 action='store_true', |
| 84 help='Trace command that generates ICE instructions') | 83 help='Trace command that generates ICE instructions') |
| 85 argparser.add_argument('--tbc', required=False, action='store_true', | 84 argparser.add_argument('--tbc', required=False, action='store_true', |
| 86 help='Input is textual bitcode (not .ll)') | 85 help='Input is textual bitcode (not .ll)') |
| 87 argparser.add_argument('--expect-fail', required=False, action='store_true', | 86 argparser.add_argument('--expect-fail', required=False, action='store_true', |
| 88 help='Negate success of run by using LLVM not') | 87 help='Negate success of run by using LLVM not') |
| 89 argparser.add_argument('--args', '-a', nargs=argparse.REMAINDER, | 88 argparser.add_argument('--args', '-a', nargs=argparse.REMAINDER, |
| 90 default=[], | 89 default=[], |
| 91 help='Remaining arguments are passed to pnacl-sz') | 90 help='Remaining arguments are passed to pnacl-sz') |
| 91 argparser.add_argument('--sandbox', required=False, action='store_true', |
| 92 help='Sandboxes the generated code.') |
| 92 | 93 |
| 93 args = argparser.parse_args() | 94 args = argparser.parse_args() |
| 94 pnacl_bin_path = args.pnacl_bin_path | 95 pnacl_bin_path = args.pnacl_bin_path |
| 95 llfile = args.input | 96 llfile = args.input |
| 96 | 97 |
| 97 if args.llvm and args.llvm_source: | 98 if args.llvm and args.llvm_source: |
| 98 raise RuntimeError("Can't specify both '--llvm' and '--llvm-source'") | 99 raise RuntimeError("Can't specify both '--llvm' and '--llvm-source'") |
| 99 | 100 |
| 100 if args.llvm_source and args.no_local_syms: | 101 if args.llvm_source and args.no_local_syms: |
| 101 raise RuntimeError("Can't specify both '--llvm-source' and " + | 102 raise RuntimeError("Can't specify both '--llvm-source' and " + |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 elif not args.llvm_source: | 115 elif not args.llvm_source: |
| 115 cmd = [os.path.join(pnacl_bin_path, 'llvm-as'), llfile, '-o', '-', '|', | 116 cmd = [os.path.join(pnacl_bin_path, 'llvm-as'), llfile, '-o', '-', '|', |
| 116 os.path.join(pnacl_bin_path, 'pnacl-freeze')] | 117 os.path.join(pnacl_bin_path, 'pnacl-freeze')] |
| 117 if not args.no_local_syms: | 118 if not args.no_local_syms: |
| 118 cmd += ['--allow-local-symbol-tables'] | 119 cmd += ['--allow-local-symbol-tables'] |
| 119 cmd += ['|'] | 120 cmd += ['|'] |
| 120 if args.expect_fail: | 121 if args.expect_fail: |
| 121 cmd += [os.path.join(pnacl_bin_path, 'not')] | 122 cmd += [os.path.join(pnacl_bin_path, 'not')] |
| 122 cmd += [args.pnacl_sz] | 123 cmd += [args.pnacl_sz] |
| 123 cmd += ['--target', args.target] | 124 cmd += ['--target', args.target] |
| 125 if args.sandbox: |
| 126 cmd += ['-sandbox'] |
| 124 if args.insts: | 127 if args.insts: |
| 125 # If the tests are based on '-verbose inst' output, force | 128 # If the tests are based on '-verbose inst' output, force |
| 126 # single-threaded translation because dump output does not get | 129 # single-threaded translation because dump output does not get |
| 127 # reassembled into order. | 130 # reassembled into order. |
| 128 cmd += ['-verbose', 'inst', '-notranslate', '-threads=0'] | 131 cmd += ['-verbose', 'inst', '-notranslate', '-threads=0'] |
| 129 if not args.llvm_source: | 132 if not args.llvm_source: |
| 130 cmd += ['--bitcode-format=pnacl'] | 133 cmd += ['--bitcode-format=pnacl'] |
| 131 if not args.no_local_syms: | 134 if not args.no_local_syms: |
| 132 cmd += ['--allow-local-symbol-tables'] | 135 cmd += ['--allow-local-symbol-tables'] |
| 133 if args.llvm or args.llvm_source: | 136 if args.llvm or args.llvm_source: |
| 134 cmd += ['--build-on-read=0'] | 137 cmd += ['--build-on-read=0'] |
| 135 else: | 138 else: |
| 136 cmd += ['--build-on-read=1'] | 139 cmd += ['--build-on-read=1'] |
| 137 cmd += ['--filetype=' + args.filetype] | 140 cmd += ['--filetype=' + args.filetype] |
| 138 cmd += args.args | 141 cmd += args.args |
| 139 if args.llvm_source: | 142 if args.llvm_source: |
| 140 cmd += [llfile] | 143 cmd += [llfile] |
| 141 asm_temp = None | 144 asm_temp = None |
| 142 if args.assemble or args.disassemble: | 145 if args.assemble or args.disassemble: |
| 143 # On windows we may need to close the file first before it can be | 146 # On windows we may need to close the file first before it can be |
| 144 # re-opened by the other tools, so don't do delete-on-close, | 147 # re-opened by the other tools, so don't do delete-on-close, |
| 145 # and instead manually delete. | 148 # and instead manually delete. |
| 146 asm_temp = tempfile.NamedTemporaryFile(delete=False) | 149 asm_temp = tempfile.NamedTemporaryFile(delete=False) |
| 147 asm_temp.close() | 150 asm_temp.close() |
| 148 if args.assemble and args.filetype != 'obj': | 151 if args.assemble and args.filetype != 'obj': |
| 149 cmd += (['|', os.path.join(pnacl_bin_path, 'llvm-mc')] + | 152 cmd += (['|', os.path.join(pnacl_bin_path, 'llvm-mc')] + |
| 150 TargetAssemblerFlags(args.target) + | 153 TargetAssemblerFlags(args.target, args.sandbox) + |
| 151 ['-filetype=obj', '-o', asm_temp.name]) | 154 ['-filetype=obj', '-o', asm_temp.name]) |
| 152 elif asm_temp: | 155 elif asm_temp: |
| 153 cmd += ['-o', asm_temp.name] | 156 cmd += ['-o', asm_temp.name] |
| 154 if args.disassemble: | 157 if args.disassemble: |
| 155 # Show wide instruction encodings, diassemble, and show relocs. | 158 # Show wide instruction encodings, diassemble, and show relocs. |
| 156 cmd += (['&&', os.path.join(pnacl_bin_path, 'le32-nacl-objdump')] + | 159 cmd += (['&&', os.path.join(pnacl_bin_path, 'le32-nacl-objdump')] + |
| 157 args.dis_flags + | 160 args.dis_flags + |
| 158 ['-w', '-d', '-r'] + TargetDisassemblerFlags(args.target) + | 161 ['-w', '-d', '-r'] + TargetDisassemblerFlags(args.target) + |
| 159 [asm_temp.name]) | 162 [asm_temp.name]) |
| 160 | 163 |
| 161 stdout_result = shellcmd(cmd, echo=args.echo_cmd) | 164 stdout_result = shellcmd(cmd, echo=args.echo_cmd) |
| 162 if not args.echo_cmd: | 165 if not args.echo_cmd: |
| 163 sys.stdout.write(stdout_result) | 166 sys.stdout.write(stdout_result) |
| 164 if asm_temp: | 167 if asm_temp: |
| 165 os.remove(asm_temp.name) | 168 os.remove(asm_temp.name) |
| 166 | 169 |
| 167 if __name__ == '__main__': | 170 if __name__ == '__main__': |
| 168 main() | 171 main() |
| OLD | NEW |