Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | |
| 3 | import argparse |
| 4 | import os |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 5 | import tempfile |
| 6 | from utils import shellcmd |
Jim Stichnoth | 16178a1 | 2014-09-02 14:11:57 -0700 | [diff] [blame] | 7 | from utils import FindBaseNaCl |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 8 | |
| 9 | if __name__ == '__main__': |
| 10 | argparser = argparse.ArgumentParser() |
| 11 | argparser.add_argument('cfile', nargs='+', type=str, |
| 12 | help='C file(s) to convert') |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 13 | argparser.add_argument('--dir', nargs='?', type=str, default='.', |
Jim Stichnoth | 65d8d53 | 2014-09-11 09:47:59 -0700 | [diff] [blame] | 14 | help='Output directory. Default "%(default)s".') |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 15 | argparser.add_argument('--disable-verify', action='store_true') |
| 16 | args = argparser.parse_args() |
| 17 | |
Jim Stichnoth | 16178a1 | 2014-09-02 14:11:57 -0700 | [diff] [blame] | 18 | nacl_root = FindBaseNaCl() |
| 19 | # Prepend bin to $PATH. |
| 20 | os.environ['PATH'] = ( |
| 21 | nacl_root + '/toolchain/linux_x86/pnacl_newlib/bin' + os.pathsep + |
| 22 | os.pathsep + os.environ['PATH']) |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 23 | |
| 24 | tempdir = tempfile.mkdtemp() |
| 25 | |
| 26 | for cname in args.cfile: |
| 27 | basename = os.path.splitext(cname)[0] |
| 28 | llname = os.path.join(tempdir, basename + '.ll') |
| 29 | pnaclname = basename + '.pnacl.ll' |
| 30 | pnaclname = os.path.join(args.dir, pnaclname) |
| 31 | |
Jim Stichnoth | 16178a1 | 2014-09-02 14:11:57 -0700 | [diff] [blame] | 32 | shellcmd('pnacl-clang -O2 -c {0} -o {1}'.format(cname, llname)) |
| 33 | shellcmd('pnacl-opt ' + |
| 34 | '-pnacl-abi-simplify-preopt -pnacl-abi-simplify-postopt' + |
| 35 | ('' if args.disable_verify else |
| 36 | ' -verify-pnaclabi-module -verify-pnaclabi-functions') + |
| 37 | ' -pnaclabi-allow-debug-metadata' |
| 38 | ' {0} -S -o {1}'.format(llname, pnaclname)) |