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