| 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 pipes | 5 import pipes |
| 6 import re | 6 import re |
| 7 import sys | 7 import sys |
| 8 | 8 |
| 9 from utils import shellcmd | 9 from utils import shellcmd |
| 10 from utils import FindBaseNaCl | 10 from utils import FindBaseNaCl |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 argparser.add_argument('--target', default='x8632', dest='target', | 91 argparser.add_argument('--target', default='x8632', dest='target', |
| 92 choices=['arm32', 'x8632'], | 92 choices=['arm32', 'x8632'], |
| 93 help='Generate code for specified target.') | 93 help='Generate code for specified target.') |
| 94 argparser.add_argument('--verbose', '-v', dest='verbose', | 94 argparser.add_argument('--verbose', '-v', dest='verbose', |
| 95 action='store_true', | 95 action='store_true', |
| 96 help='Display some extra debugging output') | 96 help='Display some extra debugging output') |
| 97 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], | 97 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], |
| 98 help='Extra arguments for Subzero') | 98 help='Extra arguments for Subzero') |
| 99 argparser.add_argument('--llc', dest='llc_args', action='append', | 99 argparser.add_argument('--llc', dest='llc_args', action='append', |
| 100 default=[], help='Extra arguments for llc') | 100 default=[], help='Extra arguments for llc') |
| 101 argparser.add_argument('--no-sz', dest='nosz', action='store_true', |
| 102 help='Run only post-Subzero build steps') |
| 101 | 103 |
| 102 def main(): | 104 def main(): |
| 103 """Create a hybrid translation from Subzero and llc. | 105 """Create a hybrid translation from Subzero and llc. |
| 104 | 106 |
| 105 Takes a finalized pexe and builds a native executable as a hybrid of Subzero | 107 Takes a finalized pexe and builds a native executable as a hybrid of Subzero |
| 106 and llc translated bitcode. Linker tricks are used to determine whether | 108 and llc translated bitcode. Linker tricks are used to determine whether |
| 107 Subzero or llc generated symbols are used, on a per-symbol basis. | 109 Subzero or llc generated symbols are used, on a per-symbol basis. |
| 108 | 110 |
| 109 By default, for every symbol, its Subzero version is used. Subzero and llc | 111 By default, for every symbol, its Subzero version is used. Subzero and llc |
| 110 symbols can be selectively enabled/disabled via regular expressions on the | 112 symbols can be selectively enabled/disabled via regular expressions on the |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 '{objcopy} --redefine-sym _start=_user_start {obj}' | 211 '{objcopy} --redefine-sym _start=_user_start {obj}' |
| 210 ).format(objcopy=objcopy, obj=obj_llc), echo=args.verbose) | 212 ).format(objcopy=objcopy, obj=obj_llc), echo=args.verbose) |
| 211 # Generate llc syms file for consistency, even though it's not used. | 213 # Generate llc syms file for consistency, even though it's not used. |
| 212 shellcmd(( | 214 shellcmd(( |
| 213 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' | 215 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' |
| 214 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose) | 216 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose) |
| 215 | 217 |
| 216 if (args.force or | 218 if (args.force or |
| 217 NewerThanOrNotThere(pexe, obj_sz) or | 219 NewerThanOrNotThere(pexe, obj_sz) or |
| 218 NewerThanOrNotThere(pnacl_sz, obj_sz)): | 220 NewerThanOrNotThere(pnacl_sz, obj_sz)): |
| 219 # Run pnacl-sz regardless of hybrid mode. | 221 if not args.nosz: |
| 220 shellcmd([pnacl_sz, | 222 # Run pnacl-sz regardless of hybrid mode. |
| 221 '-O' + opt_level, | 223 shellcmd([pnacl_sz, |
| 222 '-bitcode-format=pnacl', | 224 '-O' + opt_level, |
| 223 '-filetype=' + args.filetype, | 225 '-bitcode-format=pnacl', |
| 224 '-o', obj_sz if args.filetype == 'obj' else asm_sz, | 226 '-filetype=' + args.filetype, |
| 225 '-target=' + args.target] + | 227 '-o', obj_sz if args.filetype == 'obj' else asm_sz, |
| 226 (['-externalize', | 228 '-target=' + args.target] + |
| 227 '-ffunction-sections', | 229 (['-externalize', |
| 228 '-fdata-sections'] if hybrid else []) + | 230 '-ffunction-sections', |
| 229 (['-sandbox'] if args.sandbox else []) + | 231 '-fdata-sections'] if hybrid else []) + |
| 230 (['-enable-block-profile'] if | 232 (['-sandbox'] if args.sandbox else []) + |
| 231 args.enable_block_profile and not args.sandbox else []) + | 233 (['-enable-block-profile'] if |
| 232 args.sz_args + | 234 args.enable_block_profile and not args.sandbox |
| 233 [pexe], | 235 else []) + |
| 234 echo=args.verbose) | 236 args.sz_args + |
| 237 [pexe], |
| 238 echo=args.verbose) |
| 235 if args.filetype != 'obj': | 239 if args.filetype != 'obj': |
| 236 triple = { | 240 triple = { |
| 237 'arm32': 'arm-nacl' if args.sandbox else 'arm', | 241 'arm32': 'arm-nacl' if args.sandbox else 'arm', |
| 238 'x8632': 'i686-nacl' if args.sandbox else 'i686', | 242 'x8632': 'i686-nacl' if args.sandbox else 'i686', |
| 239 }[args.target] | 243 }[args.target] |
| 240 | 244 |
| 241 shellcmd(( | 245 shellcmd(( |
| 242 '{base}/llvm-mc -triple={triple} -filetype=obj -o {obj} {asm}' | 246 '{base}/llvm-mc -triple={triple} -filetype=obj -o {obj} {asm}' |
| 243 ).format(base=path_addition, asm=asm_sz, obj=obj_sz, | 247 ).format(base=path_addition, asm=asm_sz, obj=obj_sz, |
| 244 triple=triple), | 248 triple=triple), |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 370 |
| 367 # Put the extra verbose printing at the end. | 371 # Put the extra verbose printing at the end. |
| 368 if args.verbose and hybrid: | 372 if args.verbose and hybrid: |
| 369 print 'include={regex}'.format(regex=re_include_str) | 373 print 'include={regex}'.format(regex=re_include_str) |
| 370 print 'exclude={regex}'.format(regex=re_exclude_str) | 374 print 'exclude={regex}'.format(regex=re_exclude_str) |
| 371 print 'default_match={dm}'.format(dm=default_match) | 375 print 'default_match={dm}'.format(dm=default_match) |
| 372 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) | 376 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) |
| 373 | 377 |
| 374 if __name__ == '__main__': | 378 if __name__ == '__main__': |
| 375 main() | 379 main() |
| OLD | NEW |