| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python | |
| 2 # Copyright (c) 2011 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. | |
| 5 # | |
| 6 # IMPORTANT NOTE: If you make local mods to this file, you must run: | |
| 7 # % tools/llvm/utman.sh driver | |
| 8 # in order for them to take effect in the scons build. This command | |
| 9 # updates the copy in the toolchain/ tree. | |
| 10 # | |
| 11 | |
| 12 from driver_tools import * | |
| 13 | |
| 14 EXTRA_ENV = { | |
| 15 'INPUTS' : '', | |
| 16 'OUTPUT' : '', | |
| 17 | |
| 18 # Options | |
| 19 'DIAGNOSTIC' : '0', | |
| 20 | |
| 21 'AS_FLAGS_ARM' : '-mfpu=vfp -march=armv7-a', | |
| 22 # once we can use llvm's ARM assembler we should use these flags | |
| 23 #'AS_FLAGS_ARM' : '-assemble -filetype=obj -arch=arm -triple=armv7a-nacl', | |
| 24 'AS_FLAGS_X8632' : '-assemble -filetype=obj -arch=x86 -triple=i686-nacl', | |
| 25 'AS_FLAGS_X8664' : '-assemble -filetype=obj -arch=x86-64 -triple=x86_64-nacl', | |
| 26 | |
| 27 'RUN_BITCODE_AS' : '${LLVM_AS} ${input} -o ${output}', | |
| 28 'RUN_NATIVE_AS' : '${AS_%ARCH%} ${AS_FLAGS_%ARCH%} ${input} -o ${output}', | |
| 29 } | |
| 30 env.update(EXTRA_ENV) | |
| 31 | |
| 32 ASPatterns = [ | |
| 33 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), | |
| 34 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), | |
| 35 | |
| 36 ( '(-v|--version)', "env.set('DIAGNOSTIC', '1')"), | |
| 37 | |
| 38 # Ignore these assembler flags | |
| 39 ( '(-Qy)', ""), | |
| 40 ( ('(--traditional-format)', '.*'), ""), | |
| 41 ( '(-gstabs)', ""), | |
| 42 ( '(--gstabs)', ""), | |
| 43 ( '(-gdwarf2)', ""), | |
| 44 ( '(--gdwarf2)', ""), | |
| 45 ( '(--fatal-warnings)', ""), | |
| 46 ( '(-meabi=.*)', ""), | |
| 47 ( '(-mfpu=.*)', ""), | |
| 48 ( '(-march=.*)', ""), | |
| 49 | |
| 50 ( '(-.*)', UnrecognizedOption), | |
| 51 | |
| 52 # Unmatched parameters should be treated as | |
| 53 # assembly inputs by the "as" incarnation. | |
| 54 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), | |
| 55 ] | |
| 56 | |
| 57 def main(argv): | |
| 58 ParseArgs(argv, ASPatterns) | |
| 59 arch = GetArch() | |
| 60 | |
| 61 if env.getbool('DIAGNOSTIC'): | |
| 62 GetArch(required=True) | |
| 63 env.set('ARGV', *argv) | |
| 64 # NOTE: we could probably just print a canned string out instead. | |
| 65 RunWithLog('${AS_%ARCH%} ${ARGV}') | |
| 66 return 0 | |
| 67 | |
| 68 inputs = env.get('INPUTS') | |
| 69 output = env.getone('OUTPUT') | |
| 70 | |
| 71 if len(inputs) != 1: | |
| 72 Log.Fatal('Expecting exactly one input file') | |
| 73 | |
| 74 if arch: | |
| 75 output_type = 'o' | |
| 76 else: | |
| 77 output_type = 'po' | |
| 78 | |
| 79 if output == '': | |
| 80 output = 'a.out' | |
| 81 | |
| 82 env.push() | |
| 83 env.set('input', inputs[0]) | |
| 84 env.set('output', output) | |
| 85 | |
| 86 if output_type == 'po': | |
| 87 # .ll to .po | |
| 88 RunWithLog("${RUN_BITCODE_AS}") | |
| 89 else: | |
| 90 # .s to .o | |
| 91 RunWithLog("${RUN_NATIVE_AS}") | |
| 92 env.pop() | |
| 93 return 0 | |
| 94 | |
| 95 | |
| 96 if __name__ == "__main__": | |
| 97 DriverMain(main) | |
| OLD | NEW |