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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 help='Path to Binutils executables') | 49 help='Path to Binutils executables') |
50 argparser.add_argument('--assemble', required=False, | 50 argparser.add_argument('--assemble', required=False, |
51 action='store_true', | 51 action='store_true', |
52 help='Assemble the output') | 52 help='Assemble the output') |
53 argparser.add_argument('--disassemble', required=False, | 53 argparser.add_argument('--disassemble', required=False, |
54 action='store_true', | 54 action='store_true', |
55 help='Disassemble the assembled output') | 55 help='Disassemble the assembled output') |
56 argparser.add_argument('--dis-flags', required=False, | 56 argparser.add_argument('--dis-flags', required=False, |
57 action='append', default=[], | 57 action='append', default=[], |
58 help='Add a disassembler flag') | 58 help='Add a disassembler flag') |
| 59 argparser.add_argument('--filetype', default='iasm', dest='filetype', |
| 60 choices=['obj', 'asm', 'iasm'], |
| 61 help='Output file type. Default %(default)s.') |
59 argparser.add_argument('--echo-cmd', required=False, | 62 argparser.add_argument('--echo-cmd', required=False, |
60 action='store_true', | 63 action='store_true', |
61 help='Trace command that generates ICE instructions') | 64 help='Trace command that generates ICE instructions') |
62 argparser.add_argument('--args', '-a', nargs=argparse.REMAINDER, | 65 argparser.add_argument('--args', '-a', nargs=argparse.REMAINDER, |
63 default=[], | 66 default=[], |
64 help='Remaining arguments are passed to llvm2ice') | 67 help='Remaining arguments are passed to llvm2ice') |
65 | 68 |
66 args = argparser.parse_args() | 69 args = argparser.parse_args() |
67 llvm_bin_path = args.llvm_bin_path | 70 llvm_bin_path = args.llvm_bin_path |
68 binutils_bin_path = args.binutils_bin_path | 71 binutils_bin_path = args.binutils_bin_path |
(...skipping 20 matching lines...) Expand all Loading... |
89 # reassembled into order. | 92 # reassembled into order. |
90 cmd += ['-verbose', 'inst', '-notranslate', '-threads=0'] | 93 cmd += ['-verbose', 'inst', '-notranslate', '-threads=0'] |
91 if not args.llvm_source: | 94 if not args.llvm_source: |
92 cmd += ['--bitcode-format=pnacl'] | 95 cmd += ['--bitcode-format=pnacl'] |
93 if not args.no_local_syms: | 96 if not args.no_local_syms: |
94 cmd += ['--allow-local-symbol-tables'] | 97 cmd += ['--allow-local-symbol-tables'] |
95 if args.llvm or args.llvm_source: | 98 if args.llvm or args.llvm_source: |
96 cmd += ['--build-on-read=0'] | 99 cmd += ['--build-on-read=0'] |
97 else: | 100 else: |
98 cmd += ['--build-on-read=1'] | 101 cmd += ['--build-on-read=1'] |
| 102 cmd += ['--filetype=' + args.filetype] |
99 cmd += args.args | 103 cmd += args.args |
100 if args.llvm_source: | 104 if args.llvm_source: |
101 cmd += [llfile] | 105 cmd += [llfile] |
102 asm_temp = None | 106 asm_temp = None |
103 if args.assemble or args.disassemble: | 107 if args.assemble or args.disassemble: |
104 # On windows we may need to close the file first before it can be | 108 # On windows we may need to close the file first before it can be |
105 # re-opened by the other tools, so don't do delete-on-close, | 109 # re-opened by the other tools, so don't do delete-on-close, |
106 # and instead manually delete. | 110 # and instead manually delete. |
107 asm_temp = tempfile.NamedTemporaryFile(delete=False) | 111 asm_temp = tempfile.NamedTemporaryFile(delete=False) |
108 asm_temp.close() | 112 asm_temp.close() |
109 if args.assemble: | 113 if args.assemble and args.filetype != 'obj': |
110 cmd += ['|', os.path.join(llvm_bin_path, 'llvm-mc'), | 114 cmd += ['|', os.path.join(llvm_bin_path, 'llvm-mc'), |
111 '-triple=i686-none-nacl', | 115 '-triple=i686-none-nacl', |
112 '-filetype=obj', '-o', asm_temp.name] | 116 '-filetype=obj', '-o', asm_temp.name] |
| 117 elif asm_temp: |
| 118 cmd += ['-o', asm_temp.name] |
113 if args.disassemble: | 119 if args.disassemble: |
114 # Show wide instruction encodings, diassemble, and show relocs. | 120 # Show wide instruction encodings, diassemble, and show relocs. |
115 cmd += (['&&', os.path.join(binutils_bin_path, 'objdump')] + | 121 cmd += (['&&', os.path.join(binutils_bin_path, 'objdump')] + |
116 args.dis_flags + | 122 args.dis_flags + |
117 ['-w', '-d', '-r', '-Mintel', asm_temp.name]) | 123 ['-w', '-d', '-r', '-Mintel', asm_temp.name]) |
118 | 124 |
119 stdout_result = shellcmd(cmd, echo=args.echo_cmd) | 125 stdout_result = shellcmd(cmd, echo=args.echo_cmd) |
120 if not args.echo_cmd: | 126 if not args.echo_cmd: |
121 sys.stdout.write(stdout_result) | 127 sys.stdout.write(stdout_result) |
122 if asm_temp: | 128 if asm_temp: |
123 os.remove(asm_temp.name) | 129 os.remove(asm_temp.name) |
124 | 130 |
125 if __name__ == '__main__': | 131 if __name__ == '__main__': |
126 main() | 132 main() |
OLD | NEW |