OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python2 | |
2 | |
3 import argparse | |
4 import os | |
5 import shutil | |
6 import tempfile | |
7 from utils import shellcmd | |
8 from utils import FindBaseNaCl | |
9 | |
jvoung (off chromium)
2015/02/23 17:58:36
Usually nacl/chrome py files have 2 space indent,
Jim Stichnoth
2015/02/23 21:38:19
Yeah, I tried to fit in with the existing files. :
| |
10 def Translate(ll_files, extra_args, obj, verbose): | |
11 """Translate a set of input bitcode files into a single object file. | |
12 | |
13 Use pnacl-llc to translate textual bitcode input ll_files into object file | |
14 obj, using extra_args as the architectural flags. | |
15 """ | |
16 shellcmd(['cat'] + ll_files + ['|', | |
17 'pnacl-llc', | |
18 '-externalize', | |
19 '-filetype=obj', | |
20 '-bitcode-format=llvm', | |
21 '-o', obj | |
22 ] + extra_args, echo=verbose) | |
23 shellcmd(['objcopy', | |
24 '--localize-symbol=nacl_tp_tdb_offset', | |
25 '--localize-symbol=nacl_tp_tls_offset', | |
26 obj | |
27 ], echo=verbose) | |
28 | |
29 def main(): | |
30 """Build the Subzero runtime support library for all architectures. | |
31 """ | |
32 argparser = argparse.ArgumentParser( | |
33 description=' ' + main.__doc__, | |
34 formatter_class=argparse.RawTextHelpFormatter) | |
35 argparser.add_argument('--verbose', '-v', dest='verbose', | |
36 action='store_true', | |
37 help='Display some extra debugging output') | |
38 args = argparser.parse_args() | |
39 nacl_root = FindBaseNaCl() | |
40 os.environ['PATH'] = ( | |
41 '{root}/toolchain/linux_x86/pnacl_newlib/bin{sep}' + | |
42 '{path}' | |
43 ).format(root=nacl_root, sep=os.pathsep, path=os.environ['PATH']) | |
44 srcdir = ( | |
45 '{root}/toolchain_build/src/subzero/runtime' | |
46 ).format(root=nacl_root) | |
47 rtdir = ( | |
48 '{root}/toolchain_build/src/subzero/build/runtime' | |
49 ).format(root=nacl_root) | |
50 try: | |
51 tempdir = tempfile.mkdtemp() | |
52 shellcmd(['mkdir', | |
jvoung (off chromium)
2015/02/23 17:58:36
Could have done os.makedirs() instead of shelling
Jim Stichnoth
2015/02/23 21:38:19
Done. I don't care that much about logging this p
jvoung (off chromium)
2015/02/23 23:58:38
Hmm actually, compared to "mkdir -p", you'll may n
Jim Stichnoth
2015/02/24 00:37:57
Oh, good point. Fixed it to check for the directo
| |
53 '-p', | |
54 rtdir | |
55 ], echo=args.verbose) | |
56 # Compile srcdir/szrt.c to tempdir/szrt.ll | |
57 shellcmd(['pnacl-clang', | |
58 '-O2', | |
59 '-c', | |
60 '{srcdir}/szrt.c'.format(srcdir=srcdir), | |
61 '-o', '{dir}/szrt.tmp.bc'.format(dir=tempdir) | |
62 ], echo=args.verbose) | |
63 shellcmd(['pnacl-opt', | |
64 '-pnacl-abi-simplify-preopt', | |
65 '-pnacl-abi-simplify-postopt', | |
66 '-pnaclabi-allow-debug-metadata', | |
67 '{dir}/szrt.tmp.bc'.format(dir=tempdir), | |
68 '-S', | |
69 '-o', '{dir}/szrt.ll'.format(dir=tempdir) | |
70 ], echo=args.verbose) | |
71 ll_files = ['{dir}/szrt.ll'.format(dir=tempdir), | |
72 '{srcdir}/szrt_ll.ll'.format(srcdir=srcdir)] | |
73 # Translate tempdir/szrt.ll and srcdir/szrt_ll.ll to szrt_native_x8632.o | |
74 Translate(ll_files, | |
75 ['-mtriple=i386-unknown-linux-gnu', '-mcpu=pentium4m'], | |
76 '{rtdir}/szrt_native_x8632.o'.format(rtdir=rtdir), | |
77 args.verbose) | |
78 # Translate tempdir/szrt.ll and srcdir/szrt_ll.ll to szrt_sb_x8632.o | |
79 Translate(ll_files, | |
80 ['-mtriple=i686-none-nacl-gnu', '-mcpu=pentium4m'], | |
81 '{rtdir}/szrt_sb_x8632.o'.format(rtdir=rtdir), | |
82 args.verbose) | |
83 finally: | |
84 try: | |
85 shutil.rmtree(tempdir) | |
86 except OSError as exc: | |
87 if exc.errno != errno.ENOENT: # ENOENT - no such file or directory | |
88 raise # re-raise exception | |
89 | |
90 if __name__ == '__main__': | |
91 main() | |
OLD | NEW |