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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 help='Subzero symbols to exclude ' + | 73 help='Subzero symbols to exclude ' + |
74 '(regex or line range)') | 74 '(regex or line range)') |
75 argparser.add_argument('--output', '-o', default='a.out', dest='output', | 75 argparser.add_argument('--output', '-o', default='a.out', dest='output', |
76 action='store', | 76 action='store', |
77 help='Output executable. Default %(default)s.') | 77 help='Output executable. Default %(default)s.') |
78 argparser.add_argument('-O', default='2', dest='optlevel', | 78 argparser.add_argument('-O', default='2', dest='optlevel', |
79 choices=['m1', '-1', '0', '1', '2'], | 79 choices=['m1', '-1', '0', '1', '2'], |
80 help='Optimization level ' + | 80 help='Optimization level ' + |
81 '(m1 and -1 are equivalent).' + | 81 '(m1 and -1 are equivalent).' + |
82 ' Default %(default)s.') | 82 ' Default %(default)s.') |
83 argparser.add_argument('--elf', dest='elf', | 83 argparser.add_argument('--filetype', default='iasm', dest='filetype', |
84 action='store_true', | 84 choices=['obj', 'asm', 'iasm'], |
85 help='Directly generate ELF output') | 85 help='Output file type. Default %(default)s.') |
86 argparser.add_argument('--verbose', '-v', dest='verbose', | 86 argparser.add_argument('--verbose', '-v', dest='verbose', |
87 action='store_true', | 87 action='store_true', |
88 help='Display some extra debugging output') | 88 help='Display some extra debugging output') |
89 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], | 89 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], |
90 help='Extra arguments for Subzero') | 90 help='Extra arguments for Subzero') |
91 argparser.add_argument('--llc', dest='llc_args', action='append', | 91 argparser.add_argument('--llc', dest='llc_args', action='append', |
92 default=[], help='Extra arguments for llc') | 92 default=[], help='Extra arguments for llc') |
93 | 93 |
94 def main(): | 94 def main(): |
95 """Create a hybrid translation from Subzero and llc. | 95 """Create a hybrid translation from Subzero and llc. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' | 198 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' |
199 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose) | 199 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose) |
200 | 200 |
201 if (args.force or | 201 if (args.force or |
202 NewerThanOrNotThere(pexe, obj_sz) or | 202 NewerThanOrNotThere(pexe, obj_sz) or |
203 NewerThanOrNotThere(llvm2ice, obj_sz)): | 203 NewerThanOrNotThere(llvm2ice, obj_sz)): |
204 # Run llvm2ice regardless of hybrid mode. | 204 # Run llvm2ice regardless of hybrid mode. |
205 shellcmd([llvm2ice, | 205 shellcmd([llvm2ice, |
206 '-O' + opt_level, | 206 '-O' + opt_level, |
207 '-bitcode-format=pnacl', | 207 '-bitcode-format=pnacl', |
208 '-o', obj_sz if args.elf else asm_sz] + | 208 '-filetype=' + args.filetype, |
| 209 '-o', obj_sz if args.filetype == 'obj' else asm_sz] + |
209 (['-externalize', | 210 (['-externalize', |
210 '-ffunction-sections', | 211 '-ffunction-sections', |
211 '-fdata-sections'] if hybrid else []) + | 212 '-fdata-sections'] if hybrid else []) + |
212 (['-elf-writer'] if args.elf else []) + | |
213 args.sz_args + | 213 args.sz_args + |
214 [pexe], | 214 [pexe], |
215 echo=args.verbose) | 215 echo=args.verbose) |
216 if not args.elf: | 216 if args.filetype != 'obj': |
217 shellcmd(( | 217 shellcmd(( |
218 'llvm-mc -arch=x86 -filetype=obj -o {obj} {asm}' | 218 'llvm-mc -arch=x86 -filetype=obj -o {obj} {asm}' |
219 ).format(asm=asm_sz, obj=obj_sz), echo=args.verbose) | 219 ).format(asm=asm_sz, obj=obj_sz), echo=args.verbose) |
220 shellcmd(( | 220 shellcmd(( |
221 'objcopy --redefine-sym _start=_user_start {obj}' | 221 'objcopy --redefine-sym _start=_user_start {obj}' |
222 ).format(obj=obj_sz), echo=args.verbose) | 222 ).format(obj=obj_sz), echo=args.verbose) |
223 if hybrid: | 223 if hybrid: |
224 shellcmd(( | 224 shellcmd(( |
225 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' | 225 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' |
226 ).format(obj=obj_sz, sym=sym_sz), echo=args.verbose) | 226 ).format(obj=obj_sz, sym=sym_sz), echo=args.verbose) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 if args.verbose: | 290 if args.verbose: |
291 print 'PATH={path}'.format(path=os.environ['PATH']) | 291 print 'PATH={path}'.format(path=os.environ['PATH']) |
292 if hybrid: | 292 if hybrid: |
293 print 'include={regex}'.format(regex=re_include_str) | 293 print 'include={regex}'.format(regex=re_include_str) |
294 print 'exclude={regex}'.format(regex=re_exclude_str) | 294 print 'exclude={regex}'.format(regex=re_exclude_str) |
295 print 'default_match={dm}'.format(dm=default_match) | 295 print 'default_match={dm}'.format(dm=default_match) |
296 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) | 296 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) |
297 | 297 |
298 if __name__ == '__main__': | 298 if __name__ == '__main__': |
299 main() | 299 main() |
OLD | NEW |