Chromium Code Reviews| Index: pydir/run-llvm2ice.py |
| diff --git a/pydir/run-llvm2ice.py b/pydir/run-llvm2ice.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..241b41d7a802b6da77ed5a7b6be58e17cb6cf20f |
| --- /dev/null |
| +++ b/pydir/run-llvm2ice.py |
| @@ -0,0 +1,86 @@ |
| +#!/usr/bin/env python2 |
| + |
| +import argparse |
| +import itertools |
| +import os |
| +import re |
| +import subprocess |
| +import sys |
| + |
| +from utils import shellcmd |
| + |
| +if __name__ == '__main__': |
| + desc = 'Run the llvm2ice compiler on a llvm file.' |
|
Jim Stichnoth
2014/09/24 20:37:36
You should probably use a docstring here, like in
Karl
2014/09/24 21:01:22
Done.
|
| + argparser = argparse.ArgumentParser( |
| + description=desc, |
| + formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| + epilog=''' |
| + This driver program assembles the input llvm file, |
| + freezes it into a pexe file, |
| + converts it to a Subzero program, and finally compiles it. |
| + ''') |
| + argparser.add_argument('--input', '-i', required=True, |
| + help='LLVM source file to compile') |
| + argparser.add_argument('--insts', required=False, |
| + action='store_true', |
| + help='Stop afer translating to Subzero instructions') |
|
jvoung (off chromium)
2014/09/24 20:35:19
after
Karl
2014/09/24 21:01:22
Done.
|
| + argparser.add_argument('--no-local-syms', required=False, |
| + action='store_true', |
| + help="Don't keep local symbols in the PEXE file") |
|
Jim Stichnoth
2014/09/24 20:37:36
Maybe lowercase 'pexe' for consistency with pexe a
Karl
2014/09/24 21:01:22
Done.
|
| + argparser.add_argument('--llvm', required=False, |
| + action='store_true', |
| + help='Parse pexe into llvm IR first, then ' + |
| + 'convert to Subzero') |
| + argparser.add_argument('--llvm-source', required=False, |
| + action='store_true', |
| + help='Parse source directly into llvm IR ' + |
| + '(without generating a pexe), then ' + |
| + 'convert to Subzero') |
| + argparser.add_argument( |
| + '--llvm2ice', required=False, default='./llvm2ice', metavar='LLVM2ICE', |
| + help="Subzero translator 'llvm2ice'") |
| + argparser.add_argument('--llvm-bin-path', required=False, |
| + default=None, metavar='LLVM_BIN_PATH', |
| + help='Path to LLVM executables ' + |
| + '(for building PEXE files)') |
| + argparser.add_argument('--echo-cmd', required=False, |
| + action='store_true', |
| + help='Trace command that generates ICE instructions') |
| + argparser.add_argument('--args', '-a', nargs=argparse.REMAINDER, |
| + help='Remaining arguments are passed to llvm2ice') |
| + |
| + args = argparser.parse_args() |
| + llvm_bin_path = args.llvm_bin_path |
| + llfile = args.input |
| + |
| + if args.llvm and args.llvm_source: |
| + raise RuntimeError("Can't specify both '--llvm' and '--llvm-source'") |
| + |
| + if args.llvm_source and args.no_local_syms: |
| + raise RuntimeError("Can't specify both '--llvm-source' and " + |
| + "'--no-local-syms'") |
| + |
| + cmd = [] |
| + if not args.llvm_source: |
| + cmd = [os.path.join(llvm_bin_path, 'llvm-as'), llfile, '-o', '-', '|', |
| + os.path.join(llvm_bin_path, 'pnacl-freeze')] |
| + if not args.no_local_syms: |
| + cmd += ['--allow-local-symbol-tables'] |
| + cmd += ['|'] |
| + cmd += [args.llvm2ice] |
| + if args.insts: |
| + cmd += ['-verbose', 'inst', '-notranslate'] |
| + if not args.llvm_source: |
| + cmd += ['--bitcode-format=pnacl'] |
| + if not args.no_local_syms: |
| + cmd += ['--allow-local-symbol-tables'] |
| + if not (args.llvm or args.llvm_source): |
| + cmd += ['--build-on-read'] |
| + if args.args: |
| + cmd += args.args |
| + if args.llvm_source: |
| + cmd.append(llfile) |
|
Jim Stichnoth
2014/09/24 20:37:36
Maybe use
cmd += [llfile]
for consistency?
|
| + |
| + stdout_result = shellcmd(cmd, echo=args.echo_cmd) |
| + if not args.echo_cmd: |
| + sys.stdout.write(stdout_result) |