OLD | NEW |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python2 |
2 | 2 |
3 import argparse | 3 import argparse |
4 import os | 4 import os |
5 import sys | |
6 import tempfile | 5 import tempfile |
7 from utils import shellcmd | 6 from utils import shellcmd |
8 | 7 |
9 if __name__ == '__main__': | 8 if __name__ == '__main__': |
10 argparser = argparse.ArgumentParser() | 9 argparser = argparse.ArgumentParser() |
11 argparser.add_argument('cfile', nargs='+', type=str, | 10 argparser.add_argument('cfile', nargs='+', type=str, |
12 help='C file(s) to convert') | 11 help='C file(s) to convert') |
13 argparser.add_argument('--nacl_sdk_root', nargs='?', type=str, | |
14 help='Path to NACL_SDK_ROOT') | |
15 argparser.add_argument('--dir', nargs='?', type=str, default='.', | 12 argparser.add_argument('--dir', nargs='?', type=str, default='.', |
16 help='Output directory') | 13 help='Output directory') |
17 argparser.add_argument('--disable-verify', action='store_true') | 14 argparser.add_argument('--disable-verify', action='store_true') |
18 args = argparser.parse_args() | 15 args = argparser.parse_args() |
19 | 16 |
20 nacl_sdk_root = os.environ.get('NACL_SDK_ROOT', None) | 17 # TODO(stichnot): Find a better way of getting to the top-level |
21 if args.nacl_sdk_root: | 18 # native_client directory. |
22 nacl_sdk_root = os.path.expanduser(args.nacl_sdk_root) | 19 nacl_root = '../../../..' |
23 | 20 # Prepend bin and host_x86_32/bin to $PATH. |
24 if not nacl_sdk_root or not os.path.exists(nacl_sdk_root): | 21 os.environ['PATH'] = \ |
25 print '''\ | 22 nacl_root + '/toolchain/linux_x86/pnacl_newlib/bin' + os.pathsep + \ |
26 Please set the NACL_SDK_ROOT environment variable or pass the path through | 23 nacl_root + '/toolchain/linux_x86/pnacl_newlib/host_x86_32/bin' + \ |
27 --nacl_sdk_root to point to a valid Native Client SDK installation.''' | 24 os.pathsep + os.environ['PATH'] |
28 sys.exit(1) | |
29 | |
30 includes_path = os.path.join(nacl_sdk_root, 'include') | |
31 toolchain_path = os.path.join(nacl_sdk_root, 'toolchain', 'linux_pnacl') | |
32 clang_path = os.path.join(toolchain_path, 'bin64', 'pnacl-clang') | |
33 opt_path = os.path.join(toolchain_path, 'host_x86_64', 'bin', 'opt') | |
34 | 25 |
35 tempdir = tempfile.mkdtemp() | 26 tempdir = tempfile.mkdtemp() |
36 | 27 |
37 for cname in args.cfile: | 28 for cname in args.cfile: |
38 basename = os.path.splitext(cname)[0] | 29 basename = os.path.splitext(cname)[0] |
39 llname = os.path.join(tempdir, basename + '.ll') | 30 llname = os.path.join(tempdir, basename + '.ll') |
40 pnaclname = basename + '.pnacl.ll' | 31 pnaclname = basename + '.pnacl.ll' |
41 pnaclname = os.path.join(args.dir, pnaclname) | 32 pnaclname = os.path.join(args.dir, pnaclname) |
42 | 33 |
43 shellcmd(clang_path + ' -O2 -I{0} -c {1} -o {2}'.format( | 34 shellcmd('pnacl-clang -O2 -c {0} -o {1}'.format(cname, llname)) |
44 includes_path, cname, llname)) | 35 shellcmd('opt -pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt' + |
jvoung (off chromium)
2014/09/02 16:59:47
You might be able to just invoke 'pnacl-opt' and
Jim Stichnoth
2014/09/02 18:30:34
Good point, done. FWIW, crosstest.py was already
| |
45 shellcmd(opt_path + | |
46 ' -pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt' + | |
47 ('' if args.disable_verify else | 36 ('' if args.disable_verify else |
48 ' -verify-pnaclabi-module -verify-pnaclabi-functions') + | 37 ' -verify-pnaclabi-module -verify-pnaclabi-functions') + |
49 ' -pnaclabi-allow-debug-metadata -disable-simplify-libcalls' | 38 ' -pnaclabi-allow-debug-metadata -disable-simplify-libcalls' |
50 ' {0} -S -o {1}'.format(llname, pnaclname)) | 39 ' {0} -S -o {1}'.format(llname, pnaclname)) |
OLD | NEW |