OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python2 |
| 2 |
| 3 import argparse |
| 4 import itertools |
| 5 import os |
| 6 import re |
| 7 import subprocess |
| 8 import sys |
| 9 |
| 10 for p in sys.path: |
| 11 if p.endswith('/toolchain_build/src/pnacl-subzero'): |
| 12 sys.path.insert(0, p + '/pydir') |
| 13 break |
| 14 |
| 15 from utils import shellcmd |
| 16 |
| 17 if __name__ == '__main__': |
| 18 desc = 'Run llvm2ice on llvm file to produce ICE instructions.' |
| 19 argparser = argparse.ArgumentParser( |
| 20 description=desc, |
| 21 formatter_class=argparse.ArgumentDefaultsHelpFormatter, |
| 22 epilog=''' |
| 23 Runs in two modes, depending on whether the flag '--pnacl' is specified. |
| 24 |
| 25 If flag '--pnacl' is omitted, it runs llvm2ice to (directly) generate |
| 26 the corresponding ICE instructions. |
| 27 |
| 28 If flag '--pnacl' is given, it first assembles and freezes the |
| 29 llvm source file generating the corresponding PNaCl bitcode |
| 30 file. The PNaCl bitcode file is then piped into llvm2ice to |
| 31 generate the corresponding ICE instructions. |
| 32 ''') |
| 33 argparser.add_argument( |
| 34 '--llvm2ice', required=False, default='./llvm2ice', metavar='LLVM2ICE', |
| 35 help='Path to llvm2ice driver program') |
| 36 argparser.add_argument('--llvm-bin-path', required=False, |
| 37 default=None, metavar='LLVM_BIN_PATH', |
| 38 help='Path to LLVM executables ' + |
| 39 '(for building PNaCl files)') |
| 40 argparser.add_argument('--pnacl', required=False, |
| 41 action='store_true', |
| 42 help='Convert llvm source to PNaCl bitcode ' + |
| 43 'file first') |
| 44 argparser.add_argument('--echo-cmd', required=False, |
| 45 action='store_true', |
| 46 help='Trace command that generates ICE instructions') |
| 47 argparser.add_argument('llfile', nargs=1, |
| 48 metavar='LLVM_FILE', |
| 49 help='Llvm source file') |
| 50 |
| 51 args = argparser.parse_args() |
| 52 llvm_bin_path = args.llvm_bin_path |
| 53 llfile = args.llfile[0] |
| 54 |
| 55 cmd = [] |
| 56 if args.pnacl: |
| 57 cmd = [os.path.join(llvm_bin_path, 'llvm-as'), llfile, '-o', '-', '|', |
| 58 os.path.join(llvm_bin_path, 'pnacl-freeze'), |
| 59 '--allow-local-symbol-tables', '|'] |
| 60 cmd += [args.llvm2ice, '-verbose', 'inst', '-notranslate'] |
| 61 if args.pnacl: |
| 62 cmd += ['--allow-local-symbol-tables', '--bitcode-format=pnacl'] |
| 63 else: |
| 64 cmd.append(llfile) |
| 65 |
| 66 stdout_result = shellcmd(cmd, echo=args.echo_cmd) |
| 67 if not args.echo_cmd: |
| 68 sys.stdout.write(stdout_result) |
OLD | NEW |