Clean up run script to use for testing Subzero.
Adds the python script run-llvm2ice.py (was llvm2iceinsts.py) that
automatically handles conversion of LLVM source to a PEXE file,
and then runs llvm2ice on the corresponding PEXE file.
Also, defines three paths in tests, based on the executable chosen:
%lc2i - Directly reads from LLVM source, and converts to Subzero.
%l2i - Parses a PEXE file into LLVM IR, and converts to Subzero.
%p2i - Parses a PEXE directly into Subzero.
Note that for all three executables, the same arguments can be used,
making it easy to change how the input is handled.
Also moves tests to use %p2i whenever possible.
BUG= https://code.google.com/p/nativeclient/issues/detail?id=3892
R=jvoung@chromium.org
Review URL: https://codereview.chromium.org/600043002
diff --git a/pydir/run-llvm2ice.py b/pydir/run-llvm2ice.py
new file mode 100755
index 0000000..583d7f8
--- /dev/null
+++ b/pydir/run-llvm2ice.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python2
+
+import argparse
+import itertools
+import os
+import re
+import subprocess
+import sys
+
+from utils import shellcmd
+
+def main():
+ """Run the llvm2ice compiler on an llvm file.
+
+ Takes an llvm input file, freezes it into a pexe file, converts
+ it to a Subzero program, and finally compiles it.
+ """
+ argparser = argparse.ArgumentParser(
+ description=' ' + main.__doc__,
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+ argparser.add_argument('--input', '-i', required=True,
+ help='LLVM source file to compile')
+ argparser.add_argument('--insts', required=False,
+ action='store_true',
+ help='Stop after translating to ' +
+ 'Subzero instructions')
+ argparser.add_argument('--no-local-syms', required=False,
+ action='store_true',
+ help="Don't keep local symbols in the pexe file")
+ 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 += [llfile]
+
+ stdout_result = shellcmd(cmd, echo=args.echo_cmd)
+ if not args.echo_cmd:
+ sys.stdout.write(stdout_result)
+
+if __name__ == '__main__':
+ main()