Index: pydir/run-pnacl-sz.py |
diff --git a/pydir/run-pnacl-sz.py b/pydir/run-pnacl-sz.py |
index b7434adc25de0c02c4143e390e16d50ded727bf1..423d7172679a7b799c8e3d90082e6a3aaef1e829 100755 |
--- a/pydir/run-pnacl-sz.py |
+++ b/pydir/run-pnacl-sz.py |
@@ -40,6 +40,8 @@ def main(): |
formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
argparser.add_argument('--input', '-i', required=True, |
help='LLVM source file to compile') |
+ argparser.add_argument('--output', '-o', required=False, |
+ help='Output file to write') |
argparser.add_argument('--insts', required=False, |
action='store_true', |
help='Stop after translating to ' + |
@@ -77,10 +79,12 @@ def main(): |
help='Add a disassembler flag') |
argparser.add_argument('--filetype', default='iasm', dest='filetype', |
choices=['obj', 'asm', 'iasm'], |
- help='Output file type. Default %(default)s.') |
+ help='Output file type. Default %(default)s') |
+ argparser.add_argument('--forceasm', required=False, action='store_true', |
+ help='Force --filetype=asm') |
argparser.add_argument('--target', default='x8632', dest='target', |
choices=['x8632','arm32','mips32'], |
- help='Target architecture. Default %(default)s.') |
+ help='Target architecture. Default %(default)s') |
argparser.add_argument('--echo-cmd', required=False, |
action='store_true', |
help='Trace command that generates ICE instructions') |
@@ -92,7 +96,7 @@ def main(): |
default=[], |
help='Remaining arguments are passed to pnacl-sz') |
argparser.add_argument('--sandbox', required=False, action='store_true', |
- help='Sandboxes the generated code.') |
+ help='Sandboxes the generated code') |
args = argparser.parse_args() |
pnacl_bin_path = args.pnacl_bin_path |
@@ -111,6 +115,16 @@ def main(): |
if args.llvm and args.tbc: |
raise RuntimeError("Can't specify both '--tbc' and '--llvm'") |
+ if args.forceasm: |
+ if args.filetype == 'asm': |
+ pass |
+ elif args.filetype == 'iasm': |
+ # TODO(sehr) implement forceasm for iasm. |
+ pass |
+ elif args.filetype == 'obj': |
+ args.filetype = 'asm' |
+ args.assemble = True |
+ |
cmd = [] |
if args.tbc: |
cmd = [os.path.join(pnacl_bin_path, 'pnacl-bcfuzz'), llfile, |
@@ -141,34 +155,47 @@ def main(): |
else: |
cmd += ['--build-on-read=1'] |
cmd += ['--filetype=' + args.filetype] |
+ # Redirecting the output file needs to be done through the script because |
+ # forceasm may introduce a new temporary file between pnacl-sz and llvm-mc. |
+ for i, j in enumerate(args.args): |
+ if j == '-o': |
Jim Stichnoth
2016/01/12 14:54:02
This confused me for a bit. I think it would help
sehr
2016/01/12 19:01:19
I ventured a bit into python regexes. At your mer
|
+ print 'Output redirection should be done using --output' |
+ exit(1) |
+ asm_temp = None |
+ output_file_name = None |
+ keep_output_file = False |
+ if args.output: |
+ output_file_name = args.output |
+ keep_output_file = True |
cmd += args.args |
if args.llvm_source: |
cmd += [llfile] |
- asm_temp = None |
if args.assemble or args.disassemble: |
- # On windows we may need to close the file first before it can be |
- # re-opened by the other tools, so don't do delete-on-close, |
- # and instead manually delete. |
- asm_temp = tempfile.NamedTemporaryFile(delete=False) |
- asm_temp.close() |
+ if not output_file_name: |
+ # On windows we may need to close the file first before it can be |
+ # re-opened by the other tools, so don't do delete-on-close, |
+ # and instead manually delete. |
+ asm_temp = tempfile.NamedTemporaryFile(delete=False) |
+ asm_temp.close() |
+ output_file_name = asm_temp.name |
if args.assemble and args.filetype != 'obj': |
cmd += (['|', os.path.join(pnacl_bin_path, 'llvm-mc')] + |
TargetAssemblerFlags(args.target, args.sandbox) + |
- ['-filetype=obj', '-o', asm_temp.name]) |
- elif asm_temp: |
- cmd += ['-o', asm_temp.name] |
+ ['-filetype=obj', '-o', output_file_name]) |
+ elif output_file_name: |
+ cmd += ['-o', output_file_name] |
if args.disassemble: |
# Show wide instruction encodings, diassemble, and show relocs. |
cmd += (['&&', os.path.join(pnacl_bin_path, 'le32-nacl-objdump')] + |
args.dis_flags + |
['-w', '-d', '-r'] + TargetDisassemblerFlags(args.target) + |
- [asm_temp.name]) |
+ [output_file_name]) |
stdout_result = shellcmd(cmd, echo=args.echo_cmd) |
if not args.echo_cmd: |
sys.stdout.write(stdout_result) |
- if asm_temp: |
- os.remove(asm_temp.name) |
+ if asm_temp and not keep_output_file: |
+ os.remove(output_file_name) |
if __name__ == '__main__': |
main() |