OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. | 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 | 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 # % tools/llvm/utman.sh driver | 7 # % tools/llvm/utman.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 # |
11 | 11 |
12 from driver_tools import * | 12 import driver_tools |
| 13 |
| 14 env = driver_tools.env |
13 | 15 |
14 EXTRA_ENV = { | 16 EXTRA_ENV = { |
15 'INPUTS' : '', | 17 'INPUTS' : '', |
16 'OUTPUT' : '', | 18 'OUTPUT' : '', |
17 | 19 |
18 # Options | 20 # Options |
19 'DIAGNOSTIC' : '0', | 21 'DIAGNOSTIC' : '0', |
| 22 'ASPP_FLAGS': '-DNACL_LINUX=1', |
20 | 23 |
21 'AS_FLAGS_ARM' : '-mfpu=vfp -march=armv7-a', | 24 'AS_FLAGS_ARM' : '-mfpu=vfp -march=armv7-a', |
22 # once we can use llvm's ARM assembler we should use these flags | 25 # 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', | 26 #'AS_FLAGS_ARM' : '-assemble -filetype=obj -arch=arm -triple=armv7a-nacl', |
24 'AS_FLAGS_X8632' : '-assemble -filetype=obj -arch=x86 -triple=i686-nacl', | 27 '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', | 28 'AS_FLAGS_X8664' : '-assemble -filetype=obj -arch=x86-64 -triple=x86_64-nacl', |
26 | 29 |
27 'RUN_BITCODE_AS' : '${LLVM_AS} ${input} -o ${output}', | 30 'RUN_BITCODE_AS' : '${LLVM_AS} ${input} -o ${output}', |
28 'RUN_NATIVE_AS' : '${AS_%ARCH%} ${AS_FLAGS_%ARCH%} ${input} -o ${output}', | 31 'RUN_NATIVE_AS' : '${AS_%ARCH%} ${AS_FLAGS_%ARCH%} ${input} -o ${output}', |
| 32 |
| 33 # NOTE: should we run the vanilla preprocessor instead? |
| 34 'RUN_PP' : '${CLANG} -E ${ASPP_FLAGS} ${input} -o ${output}' |
29 } | 35 } |
30 env.update(EXTRA_ENV) | 36 env.update(EXTRA_ENV) |
31 | 37 |
32 ASPatterns = [ | 38 ASPatterns = [ |
33 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), | 39 ( '-o(.+)', "env.set('OUTPUT', pathtools.normalize($0))"), |
34 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), | 40 ( ('-o', '(.+)'), "env.set('OUTPUT', pathtools.normalize($0))"), |
35 | 41 |
36 ( '(-v|--version)', "env.set('DIAGNOSTIC', '1')"), | 42 ( '(-v|--version)', "env.set('DIAGNOSTIC', '1')"), |
37 | 43 |
38 # Ignore these assembler flags | 44 # Ignore these assembler flags |
39 ( '(-Qy)', ""), | 45 ( '(-Qy)', ""), |
40 ( ('(--traditional-format)', '.*'), ""), | 46 ( ('(--traditional-format)', '.*'), ""), |
41 ( '(-gstabs)', ""), | 47 ( '(-gstabs)', ""), |
42 ( '(--gstabs)', ""), | 48 ( '(--gstabs)', ""), |
43 ( '(-gdwarf2)', ""), | 49 ( '(-gdwarf2)', ""), |
44 ( '(--gdwarf2)', ""), | 50 ( '(--gdwarf2)', ""), |
45 ( '(--fatal-warnings)', ""), | 51 ( '(--fatal-warnings)', ""), |
46 ( '(-meabi=.*)', ""), | 52 ( '(-meabi=.*)', ""), |
47 ( '(-mfpu=.*)', ""), | 53 ( '(-mfpu=.*)', ""), |
48 ( '(-march=.*)', ""), | 54 ( '(-march=.*)', ""), |
49 | 55 |
50 ( '(-.*)', UnrecognizedOption), | 56 ( '-c', ""), |
| 57 |
| 58 ( ('-I', '(.+)'), "env.append('ASPP_FLAGS', '-I'+pathtools.normalize($0))")
, |
| 59 ( '-I(.+)', "env.append('ASPP_FLAGS', '-I'+pathtools.normalize($0))")
, |
| 60 |
| 61 ( ('(-D)','(.*)'), "env.append('ASPP_FLAGS', $0, $1)"), |
| 62 ( '(-D.+)', "env.append('ASPP_FLAGS', $0)"), |
| 63 |
| 64 ( '(-.*)', driver_tools.UnrecognizedOption), |
51 | 65 |
52 # Unmatched parameters should be treated as | 66 # Unmatched parameters should be treated as |
53 # assembly inputs by the "as" incarnation. | 67 # assembly inputs by the "as" incarnation. |
54 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), | 68 ( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), |
55 ] | 69 ] |
56 | 70 |
57 def main(argv): | 71 def main(argv): |
58 ParseArgs(argv, ASPatterns) | 72 driver_tools.ParseArgs(argv, ASPatterns) |
59 arch = GetArch() | 73 arch = driver_tools.GetArch() |
60 | 74 |
61 if env.getbool('DIAGNOSTIC'): | 75 if env.getbool('DIAGNOSTIC'): |
62 GetArch(required=True) | 76 driver_tools.GetArch(required=True) |
63 env.set('ARGV', *argv) | 77 env.set('ARGV', *argv) |
64 # NOTE: we could probably just print a canned string out instead. | 78 # NOTE: we could probably just print a canned string out instead. |
65 RunWithLog('${AS_%ARCH%} ${ARGV}') | 79 driver_tools.RunWithLog('${AS_%ARCH%} ${ARGV}') |
66 return 0 | 80 return 0 |
67 | 81 |
68 inputs = env.get('INPUTS') | 82 inputs = env.get('INPUTS') |
69 output = env.getone('OUTPUT') | 83 output = env.getone('OUTPUT') |
70 | 84 |
71 if len(inputs) != 1: | 85 if len(inputs) != 1: |
72 Log.Fatal('Expecting exactly one input file') | 86 Log.Fatal('Expecting exactly one input file') |
| 87 the_input = inputs[0] |
| 88 |
73 | 89 |
74 if arch: | 90 if arch: |
75 output_type = 'o' | 91 output_type = 'o' |
76 else: | 92 else: |
77 output_type = 'po' | 93 output_type = 'po' |
78 | 94 |
79 if output == '': | 95 if output == '': |
80 output = 'a.out' | 96 output = 'a.out' |
81 | 97 |
| 98 if the_input.endswith('.S'): |
| 99 tmp_output = output + ".s" |
| 100 driver_tools.TempFiles.add(tmp_output) |
| 101 env.push() |
| 102 env.set('input', the_input) |
| 103 env.set('output', tmp_output) |
| 104 driver_tools.RunWithLog("${RUN_PP}") |
| 105 env.pop() |
| 106 the_input = tmp_output |
| 107 |
82 env.push() | 108 env.push() |
83 env.set('input', inputs[0]) | 109 env.set('input', the_input) |
84 env.set('output', output) | 110 env.set('output', output) |
85 | 111 |
86 if output_type == 'po': | 112 if output_type == 'po': |
87 # .ll to .po | 113 # .ll to .po |
88 RunWithLog("${RUN_BITCODE_AS}") | 114 driver_tools.RunWithLog("${RUN_BITCODE_AS}") |
89 else: | 115 else: |
90 # .s to .o | 116 # .s to .o |
91 RunWithLog("${RUN_NATIVE_AS}") | 117 driver_tools.RunWithLog("${RUN_NATIVE_AS}") |
92 env.pop() | 118 env.pop() |
93 return 0 | 119 return 0 |
94 | 120 |
95 | 121 |
96 if __name__ == "__main__": | 122 if __name__ == "__main__": |
97 DriverMain(main) | 123 driver_tools.DriverMain(main) |
OLD | NEW |