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
4 # found in the LICENSE file.
8 from driver_env import env
16 # Binary output may go to stdout (when -o was not specified)
18 # We disable the LLVM simplify-libcalls pass by default, since we
19 # statically link in libc, and pnacl-opt is typically used for post-link
20 # optimizations. Changing one library call to another can lead
21 # to undefined symbol errors since which definitions from libc are linked
22 # in is already decided.
23 'DISABLE_SIMPLIFY_LIBCALLS' : '1',
27 ( '--enable-simplify-libcalls', "env.set('DISABLE_SIMPLIFY_LIBCALLS', '0')"),
28 (('-o','(.*)'), "env.set('OUTPUT', pathtools.normalize($0))\n" +
29 "env.set('HAVE_OUTPUT', '1')"),
30 ( '(-.*)', "env.append('ARGS', $0)"),
31 ( '(.*)', "env.set('INPUT', $0)"),
36 driver_tools.ParseArgs(argv, PATTERNS)
38 driver_tools.CheckPathLength(env.getone('INPUT'))
39 driver_tools.CheckPathLength(env.getone('OUTPUT'))
42 '"${LLVM_OPT}" ${ARGS} ' +
43 '${DISABLE_SIMPLIFY_LIBCALLS ? -disable-simplify-libcalls} ' +
44 '${HAVE_OUTPUT ? -o ${OUTPUT}} ' +
47 # Opt is the only tool that will modify a file in-place. If this happens we
48 # need to clear the filetype cache so future invocations of the type checking
49 # routines will re-check the file.
50 if env.getone('INPUT') == env.getone('OUTPUT'):
51 filetype.ClearFileTypeCaches()
53 # only reached in case of no errors
56 def get_help(unused_argv):
57 # Set errexit=False -- Do not exit early to allow testing.
58 # For some reason most the llvm tools return non-zero with --help,
59 # while all of the gnu tools return 0 with --help.
60 # On windows, the exit code is also inconsistent =(
61 code, stdout, stderr = driver_tools.Run('${LLVM_OPT} -help',
62 redirect_stdout=subprocess.PIPE,
63 redirect_stderr=subprocess.STDOUT,