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