Index: pnacl/driver/pnacl-as.py |
=================================================================== |
--- pnacl/driver/pnacl-as.py (revision 7372) |
+++ pnacl/driver/pnacl-as.py (working copy) |
@@ -9,14 +9,17 @@ |
# updates the copy in the toolchain/ tree. |
# |
-from driver_tools import * |
+import driver_tools |
+env = driver_tools.env |
+ |
EXTRA_ENV = { |
'INPUTS' : '', |
'OUTPUT' : '', |
# Options |
'DIAGNOSTIC' : '0', |
+ 'ASPP_FLAGS': '-DNACL_LINUX=1', |
'AS_FLAGS_ARM' : '-mfpu=vfp -march=armv7-a', |
# once we can use llvm's ARM assembler we should use these flags |
@@ -26,6 +29,9 @@ |
'RUN_BITCODE_AS' : '${LLVM_AS} ${input} -o ${output}', |
'RUN_NATIVE_AS' : '${AS_%ARCH%} ${AS_FLAGS_%ARCH%} ${input} -o ${output}', |
+ |
+ # NOTE: should we run the vanilla preprocessor instead? |
+ 'RUN_PP' : '${CLANG} -E ${ASPP_FLAGS} ${input} -o ${output}' |
} |
env.update(EXTRA_ENV) |
@@ -47,22 +53,30 @@ |
( '(-mfpu=.*)', ""), |
( '(-march=.*)', ""), |
- ( '(-.*)', UnrecognizedOption), |
+ ( '-c', ""), |
+ ( ('-I', '(.+)'), "env.append('ASPP_FLAGS', '-I'+pathtools.normalize($0))"), |
+ ( '-I(.+)', "env.append('ASPP_FLAGS', '-I'+pathtools.normalize($0))"), |
+ |
+ ( ('(-D)','(.*)'), "env.append('ASPP_FLAGS', $0, $1)"), |
+ ( '(-D.+)', "env.append('ASPP_FLAGS', $0)"), |
+ |
+ ( '(-.*)', driver_tools.UnrecognizedOption), |
+ |
# Unmatched parameters should be treated as |
# assembly inputs by the "as" incarnation. |
( '(.*)', "env.append('INPUTS', pathtools.normalize($0))"), |
] |
def main(argv): |
- ParseArgs(argv, ASPatterns) |
- arch = GetArch() |
+ driver_tools.ParseArgs(argv, ASPatterns) |
+ arch = driver_tools.GetArch() |
if env.getbool('DIAGNOSTIC'): |
- GetArch(required=True) |
+ driver_tools.GetArch(required=True) |
env.set('ARGV', *argv) |
# NOTE: we could probably just print a canned string out instead. |
- RunWithLog('${AS_%ARCH%} ${ARGV}') |
+ driver_tools.RunWithLog('${AS_%ARCH%} ${ARGV}') |
return 0 |
inputs = env.get('INPUTS') |
@@ -70,7 +84,9 @@ |
if len(inputs) != 1: |
Log.Fatal('Expecting exactly one input file') |
+ the_input = inputs[0] |
+ |
if arch: |
output_type = 'o' |
else: |
@@ -79,19 +95,29 @@ |
if output == '': |
output = 'a.out' |
+ if the_input.endswith('.S'): |
+ tmp_output = output + ".s" |
+ driver_tools.TempFiles.add(tmp_output) |
+ env.push() |
+ env.set('input', the_input) |
+ env.set('output', tmp_output) |
+ driver_tools.RunWithLog("${RUN_PP}") |
+ env.pop() |
+ the_input = tmp_output |
+ |
env.push() |
- env.set('input', inputs[0]) |
+ env.set('input', the_input) |
env.set('output', output) |
if output_type == 'po': |
# .ll to .po |
- RunWithLog("${RUN_BITCODE_AS}") |
+ driver_tools.RunWithLog("${RUN_BITCODE_AS}") |
else: |
# .s to .o |
- RunWithLog("${RUN_NATIVE_AS}") |
+ driver_tools.RunWithLog("${RUN_NATIVE_AS}") |
env.pop() |
return 0 |
if __name__ == "__main__": |
- DriverMain(main) |
+ driver_tools.DriverMain(main) |