Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: pydir/szbuild.py

Issue 559723003: Subzero: Add a convenience script for Spec2K. Add the --stats argument. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Do an initial scan for unknown components Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pydir/szbuild_spec2k.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 returned if neither the include nor the exclude regex matches. 54 returned if neither the include nor the exclude regex matches.
55 """ 55 """
56 if re_exclude.match(sym): 56 if re_exclude.match(sym):
57 # Always honor an explicit exclude before considering 57 # Always honor an explicit exclude before considering
58 # includes. 58 # includes.
59 return False 59 return False
60 if re_include.match(sym): 60 if re_include.match(sym):
61 return True 61 return True
62 return default_match 62 return default_match
63 63
64 def AddOptionalArgs(argparser):
65 argparser.add_argument('--force', dest='force', action='store_true',
66 help='Force all re-translations of the pexe')
67 argparser.add_argument('--include', '-i', default=[], dest='include',
68 action='append',
69 help='Subzero symbols to include ' +
70 '(regex or line range)')
71 argparser.add_argument('--exclude', '-e', default=[], dest='exclude',
72 action='append',
73 help='Subzero symbols to exclude ' +
74 '(regex or line range)')
75 argparser.add_argument('--output', '-o', default='a.out', dest='output',
76 action='store',
77 help='Output executable. Default %(default)s.')
78 argparser.add_argument('-O', default='2', dest='optlevel',
79 choices=['m1', '-1', '0', '1', '2'],
80 help='Optimization level ' +
81 '(m1 and -1 are equivalent).' +
82 ' Default %(default)s.')
83 argparser.add_argument('--verbose', '-v', dest='verbose',
84 action='store_true',
85 help='Display some extra debugging output')
86 argparser.add_argument('--stats', dest='stats', action='store_true',
87 help='Enable Subzero stats output')
88
64 def main(): 89 def main():
65 """Create a hybrid translation from Subzero and llc. 90 """Create a hybrid translation from Subzero and llc.
66 91
67 Takes a finalized pexe and builds a native executable as a 92 Takes a finalized pexe and builds a native executable as a
68 hybrid of Subzero and llc translated bitcode. Linker tricks are 93 hybrid of Subzero and llc translated bitcode. Linker tricks are
69 used to determine whether Subzero or llc generated symbols are 94 used to determine whether Subzero or llc generated symbols are
70 used, on a per-symbol basis. 95 used, on a per-symbol basis.
71 96
72 By default, for every symbol, its llc version is used. Subzero 97 By default, for every symbol, its llc version is used. Subzero
73 symbols can be enabled by regular expressions on the symbol name, 98 symbols can be enabled by regular expressions on the symbol name,
(...skipping 23 matching lines...) Expand all
97 This script augments PATH so that various PNaCl and LLVM tools can 122 This script augments PATH so that various PNaCl and LLVM tools can
98 be run. These extra paths are within the native_client tree. 123 be run. These extra paths are within the native_client tree.
99 When changes are made to these tools, copy them this way: 124 When changes are made to these tools, copy them this way:
100 cd native_client 125 cd native_client
101 toolchain_build/toolchain_build_pnacl.py llvm_i686_linux \\ 126 toolchain_build/toolchain_build_pnacl.py llvm_i686_linux \\
102 --install=toolchain/linux_x86/pnacl_newlib 127 --install=toolchain/linux_x86/pnacl_newlib
103 """ 128 """
104 argparser = argparse.ArgumentParser( 129 argparser = argparse.ArgumentParser(
105 description=' ' + main.__doc__, 130 description=' ' + main.__doc__,
106 formatter_class=argparse.RawTextHelpFormatter) 131 formatter_class=argparse.RawTextHelpFormatter)
132 AddOptionalArgs(argparser)
107 argparser.add_argument('pexe', help='Finalized pexe to translate') 133 argparser.add_argument('pexe', help='Finalized pexe to translate')
108 argparser.add_argument('--force', dest='force', action='store_true',
109 help='Force all re-translations of the pexe')
110 argparser.add_argument('--include', '-i', default=[], dest='include',
111 action='append',
112 help='Subzero symbols to include ' +
113 '(regex or line range)')
114 argparser.add_argument('--exclude', '-e', default=[], dest='exclude',
115 action='append',
116 help='Subzero symbols to exclude ' +
117 '(regex or line range)')
118 argparser.add_argument('--output', '-o', default='a.out', dest='output',
119 action='store',
120 help='Output executable. Default %(default)s.')
121 argparser.add_argument('-O', default='2', dest='optlevel',
122 choices=['m1', '-1', '0', '1', '2'],
123 help='Optimization level ' +
124 '(m1 and -1 are equivalent).' +
125 ' Default %(default)s.')
126 argparser.add_argument('--verbose', '-v', dest='verbose',
127 action='store_true',
128 help='Display some extra debugging output')
129 args = argparser.parse_args() 134 args = argparser.parse_args()
135 pexe = args.pexe
136 exe = args.output
137 ProcessPexe(args, pexe, exe)
130 138
131 pexe = args.pexe 139 def ProcessPexe(args, pexe, exe):
132 [pexe_base, ext] = os.path.splitext(pexe) 140 [pexe_base, ext] = os.path.splitext(pexe)
133 if ext != '.pexe': 141 if ext != '.pexe':
134 pexe_base = pexe 142 pexe_base = pexe
135 pexe_base_unescaped = pexe_base 143 pexe_base_unescaped = pexe_base
136 pexe_base = pipes.quote(pexe_base) 144 pexe_base = pipes.quote(pexe_base)
137 pexe = pipes.quote(pexe) 145 pexe = pipes.quote(pexe)
138 exe = args.output
139 146
140 nacl_root = FindBaseNaCl() 147 nacl_root = FindBaseNaCl()
141 os.environ['PATH'] = ( 148 os.environ['PATH'] = (
142 '{root}/toolchain/linux_x86/pnacl_newlib/bin{sep}' + 149 '{root}/toolchain/linux_x86/pnacl_newlib/bin{sep}' +
143 '{root}/toolchain/linux_x86/pnacl_newlib/host_x86_32/bin{sep}' + 150 '{root}/toolchain/linux_x86/pnacl_newlib/host_x86_32/bin{sep}' +
144 '{path}' 151 '{path}'
145 ).format(root=nacl_root, sep=os.pathsep, path=os.environ['PATH']) 152 ).format(root=nacl_root, sep=os.pathsep, path=os.environ['PATH'])
146 obj_llc = pexe_base + '.llc.o' 153 obj_llc = pexe_base + '.llc.o'
147 obj_sz = pexe_base + '.sz.o' 154 obj_sz = pexe_base + '.sz.o'
148 asm_sz = pexe_base + '.sz.s' 155 asm_sz = pexe_base + '.sz.s'
(...skipping 25 matching lines...) Expand all
174 shellcmd(( 181 shellcmd((
175 'objcopy --redefine-sym _start=_user_start {obj}' 182 'objcopy --redefine-sym _start=_user_start {obj}'
176 ).format(obj=obj_llc), echo=args.verbose) 183 ).format(obj=obj_llc), echo=args.verbose)
177 shellcmd(( 184 shellcmd((
178 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' 185 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}'
179 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose) 186 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose)
180 if args.force or NewerThanOrNotThere(pexe, obj_sz) or \ 187 if args.force or NewerThanOrNotThere(pexe, obj_sz) or \
181 NewerThanOrNotThere(llvm2ice, obj_sz): 188 NewerThanOrNotThere(llvm2ice, obj_sz):
182 shellcmd(( 189 shellcmd((
183 '{l2i} -O{level} -bitcode-format=pnacl -disable-globals ' + 190 '{l2i} -O{level} -bitcode-format=pnacl -disable-globals ' +
184 '-externalize -ffunction-sections {pexe} -o {asm}' 191 '-externalize -ffunction-sections {pexe} -o {asm}' +
192 (' --stats' if args.stats else '')
185 ).format(l2i=llvm2ice, level=opt_level, pexe=pexe, asm=asm_sz), 193 ).format(l2i=llvm2ice, level=opt_level, pexe=pexe, asm=asm_sz),
186 echo=args.verbose) 194 echo=args.verbose)
187 shellcmd(( 195 shellcmd((
188 'llvm-mc -arch=x86 -x86-asm-syntax=intel -filetype=obj -o {obj} ' + 196 'llvm-mc -arch=x86 -x86-asm-syntax=intel -filetype=obj -o {obj} ' +
189 '{asm}' 197 '{asm}'
190 ).format(asm=asm_sz, obj=obj_sz), echo=args.verbose) 198 ).format(asm=asm_sz, obj=obj_sz), echo=args.verbose)
191 shellcmd(( 199 shellcmd((
192 'objcopy --redefine-sym _start=_user_start {obj}' 200 'objcopy --redefine-sym _start=_user_start {obj}'
193 ).format(obj=obj_sz), echo=args.verbose) 201 ).format(obj=obj_sz), echo=args.verbose)
194 shellcmd(( 202 shellcmd((
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 # Put the extra verbose printing at the end. 256 # Put the extra verbose printing at the end.
249 if args.verbose: 257 if args.verbose:
250 print 'PATH={path}'.format(path=os.environ['PATH']) 258 print 'PATH={path}'.format(path=os.environ['PATH'])
251 print 'include={regex}'.format(regex=re_include_str) 259 print 'include={regex}'.format(regex=re_include_str)
252 print 'exclude={regex}'.format(regex=re_exclude_str) 260 print 'exclude={regex}'.format(regex=re_exclude_str)
253 print 'default_match={dm}'.format(dm=default_match) 261 print 'default_match={dm}'.format(dm=default_match)
254 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) 262 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms))
255 263
256 if __name__ == '__main__': 264 if __name__ == '__main__':
257 main() 265 main()
OLDNEW
« no previous file with comments | « no previous file | pydir/szbuild_spec2k.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698