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

Side by Side Diff: pnacl/driver/driver_env.py

Issue 454593002: PNaCl driver: Add libgcc to mixed native/bitcode links (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: review, update expr parser to only evaluate ternary operands when needed Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pnacl/driver/nativeld.py » ('j') | pnacl/driver/pnacl-driver.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 # Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 # 5 #
6 # IMPORTANT NOTE: If you make local mods to this file, you must run: 6 # IMPORTANT NOTE: If you make local mods to this file, you must run:
7 # % pnacl/build.sh driver 7 # % pnacl/build.sh driver
8 # in order for them to take effect in the scons build. This command 8 # in order for them to take effect in the scons build. This command
9 # updates the copy in the toolchain/ tree. 9 # updates the copy in the toolchain/ tree.
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 'BASE_LIB' : '${BASE}/lib', 43 'BASE_LIB' : '${BASE}/lib',
44 'BASE_USR_ARCH' : '${BASE_USR_%BCLIB_ARCH%}', 44 'BASE_USR_ARCH' : '${BASE_USR_%BCLIB_ARCH%}',
45 'BASE_USR_X8632' : '${BASE}/usr-bc-x86-32', 45 'BASE_USR_X8632' : '${BASE}/usr-bc-x86-32',
46 'BASE_USR_X8664' : '${BASE}/usr-bc-x86-64', 46 'BASE_USR_X8664' : '${BASE}/usr-bc-x86-64',
47 'BASE_USR_ARM' : '${BASE}/usr-bc-arm', 47 'BASE_USR_ARM' : '${BASE}/usr-bc-arm',
48 'BASE_LIB_ARCH' : '${BASE_LIB_%BCLIB_ARCH%}', 48 'BASE_LIB_ARCH' : '${BASE_LIB_%BCLIB_ARCH%}',
49 'BASE_LIB_X8632' : '${BASE}/lib-bc-x86-32', 49 'BASE_LIB_X8632' : '${BASE}/lib-bc-x86-32',
50 'BASE_LIB_X8664' : '${BASE}/lib-bc-x86-64', 50 'BASE_LIB_X8664' : '${BASE}/lib-bc-x86-64',
51 'BASE_LIB_ARM' : '${BASE}/lib-bc-arm', 51 'BASE_LIB_ARM' : '${BASE}/lib-bc-arm',
52 52
53 'LIBS_NATIVE_ARCH' : '${LIBS_NATIVE_%ARCH%}',
54 'LIBS_NATIVE_ARM' : '${BASE_LIB_NATIVE}arm',
55 'LIBS_NATIVE_ARM_NONSFI' : '${BASE_LIB_NATIVE}arm-nonsfi',
56 'LIBS_NATIVE_X8632' : '${BASE_LIB_NATIVE}x86-32',
57 'LIBS_NATIVE_X8632_NONSFI' : '${BASE_LIB_NATIVE}x86-32-nonsfi',
58 'LIBS_NATIVE_X8664' : '${BASE_LIB_NATIVE}x86-64',
59 'LIBS_NATIVE_MIPS32' : '${BASE_LIB_NATIVE}mips32',
60
53 'BASE_LLVM_BIN' : '${BASE_LLVM}/bin', 61 'BASE_LLVM_BIN' : '${BASE_LLVM}/bin',
54 'TRANSLATOR_BIN' : 62 'TRANSLATOR_BIN' :
55 '${BASE_TOOLCHAIN}/pnacl_translator/${STANDARD_ARCH}/bin', 63 '${BASE_TOOLCHAIN}/pnacl_translator/${STANDARD_ARCH}/bin',
56 64
57 # TODO(pdox): Unify this with ARCH. 65 # TODO(pdox): Unify this with ARCH.
58 'STANDARD_ARCH' : '${STANDARD_ARCH_%ARCH%}', 66 'STANDARD_ARCH' : '${STANDARD_ARCH_%ARCH%}',
59 'STANDARD_ARCH_X8632' : 'i686', 67 'STANDARD_ARCH_X8632' : 'i686',
60 'STANDARD_ARCH_X8664' : 'x86_64', 68 'STANDARD_ARCH_X8664' : 'x86_64',
61 'STANDARD_ARCH_ARM' : 'armv7', 69 'STANDARD_ARCH_ARM' : 'armv7',
62 'STANDARD_ARCH_MIPS32': 'mips32', 70 'STANDARD_ARCH_MIPS32': 'mips32',
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 m = {} 208 m = {}
201 for ss in strset: 209 for ss in strset:
202 m[s.find(ss, pos)] = ss 210 m[s.find(ss, pos)] = ss
203 if -1 in m: 211 if -1 in m:
204 del m[-1] 212 del m[-1]
205 if len(m) == 0: 213 if len(m) == 0:
206 return (None, len(s)) 214 return (None, len(s))
207 pos = min(m) 215 pos = min(m)
208 return (m[pos], pos) 216 return (m[pos], pos)
209 217
218 # Find the first instance of a terminating character, skipping over nested
219 # brace expressions.
220 def FindTerm(s, pos, terminators):
221 depth = 0
222 end = pos
223 for c in s[pos:]:
224 if c == '{':
225 depth += 1
226 elif depth > 0 and c == '}':
227 depth -= 1
228 else:
229 for t in terminators:
230 if s.find(t, end) == end:
231 return end
232 end += 1
233 return end
234
210 class Environment(object): 235 class Environment(object):
211 functions = {} 236 functions = {}
212 237
213 @classmethod 238 @classmethod
214 def register(cls, func): 239 def register(cls, func):
215 """ Register a function for use in the evaluator """ 240 """ Register a function for use in the evaluator """
216 cls.functions[func.__name__] = func 241 cls.functions[func.__name__] = func
217 return func 242 return func
218 243
219 def __init__(self): 244 def __init__(self):
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 if varname not in self.data: 485 if varname not in self.data:
461 ParseError(s, pos, i, "Undefined variable '%s'" % varname) 486 ParseError(s, pos, i, "Undefined variable '%s'" % varname)
462 vardata = self.data[varname] 487 vardata = self.data[varname]
463 contents = self.eval(vardata) 488 contents = self.eval(vardata)
464 return (contents, i) 489 return (contents, i)
465 else: 490 else:
466 # Ternary Mode 491 # Ternary Mode
467 (is_cond_true,i) = self.eval_bool_expr(s, pos, ['?']+terminators) 492 (is_cond_true,i) = self.eval_bool_expr(s, pos, ['?']+terminators)
468 assert(i < len(s) and s[i] == '?') 493 assert(i < len(s) and s[i] == '?')
469 494
470 (if_true_expr, j) = self.eval_expr(s, i+1, [' : ']+terminators) 495 if is_cond_true:
496 (if_true_expr, j) = self.eval_expr(s, i+1, [' : ']+terminators)
497 else:
498 # Don't evaluate the expr (it won't be used), just find its end.
499 assert terminators[0] == '}'
500 j = FindTerm(s, i+1, [' : '] + terminators)
471 if j == len(s): 501 if j == len(s):
472 return ('', j) # Error one level up 502 return ('', j) # Error one level up
473 503
474 if s[j:j+3] == ' : ': 504 if s[j:j+3] == ' : ':
475 (if_false_expr,j) = self.eval_expr(s, j+3, terminators) 505 if not is_cond_true:
506 (if_false_expr,j) = self.eval_expr(s, j+3, terminators)
507 else:
508 # Don't evaluate the expr (it won't be used), just find its end.
509 assert terminators[0] == '}'
510 j = FindTerm(s, j + 3, terminators)
476 if j == len(s): 511 if j == len(s):
477 # This is an error condition one level up. 512 # This is an error condition one level up.
478 return ('', j) 513 return ('', j)
479 else: 514 else:
480 if_false_expr = '' 515 if_false_expr = ''
481 516
482 if is_cond_true: 517 if is_cond_true:
483 contents = if_true_expr.strip() 518 contents = if_true_expr.strip()
484 else: 519 else:
485 contents = if_false_expr.strip() 520 contents = if_false_expr.strip()
(...skipping 17 matching lines...) Expand all
503 538
504 539
505 env = Environment() 540 env = Environment()
506 541
507 def override_env(meth_name, func): 542 def override_env(meth_name, func):
508 """Override a method in the global |env|, given the method name 543 """Override a method in the global |env|, given the method name
509 and the new function. 544 and the new function.
510 """ 545 """
511 global env 546 global env
512 setattr(env, meth_name, types.MethodType(func, env, Environment)) 547 setattr(env, meth_name, types.MethodType(func, env, Environment))
OLDNEW
« no previous file with comments | « no previous file | pnacl/driver/nativeld.py » ('j') | pnacl/driver/pnacl-driver.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698