Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / pnacl / driver / pnacl-as.py
1 #!/usr/bin/python
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.
5 #
6 # IMPORTANT NOTE: If you make local mods to this file, you must run:
7 #   %  pnacl/build.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 import driver_tools
13 from driver_env import env
14 from driver_log import Log
15 import sys
16
17 EXTRA_ENV = {
18   'INPUTS'      : '',
19   'OUTPUT'      : '',
20
21   'MC_FLAGS'       : '-assemble -filetype=obj ${MC_FLAGS_%ARCH%}',
22   'MC_FLAGS_ARM'   : ('-arch=arm -triple=armv7a-nacl -mcpu=cortex-a9 ' +
23                       '-mattr=+neon'),
24   'MC_FLAGS_X8632' : '-arch=x86 -triple=i686-nacl',
25   'MC_FLAGS_X8664' : '-arch=x86-64 -triple=x86_64-nacl',
26   'MC_FLAGS_MIPS32': '-arch=mipsel -triple=mipsel-nacl',
27   'MC_FLAGS_ARM_NONSFI': ('-arch=arm -triple=armv7a -mcpu=cortex-a9 '
28                           '-mattr=+neon'),
29   'MC_FLAGS_X8632_NONSFI': '-arch=x86 -triple=i686',
30
31   'RUN_LLVM_AS'    : '${LLVM_AS} ${input} -o ${output}',
32   'RUN_LLVM_MC'    : '${LLVM_MC} ${MC_FLAGS} ${input} -o ${output}',
33 }
34
35 VERSION_STR = """Portable Native Client assembler
36 Compatibility:
37 GNU assembler version 2.21.51 (pnacl-pc-nacl) using BFD version (GNU Binutils) 2.21.51.20110525
38 Low Level Virtual Machine (http://llvm.org/)
39 """
40
41 def DumpVersionDebug():
42   sys.stderr.write(VERSION_STR)
43
44 def DumpVersionAndExit():
45   sys.stdout.write(VERSION_STR)
46   driver_tools.DriverExit(0)
47
48 ASPatterns = [
49   ( '-o(.+)',          "env.set('OUTPUT', pathtools.normalize($0))"),
50   ( ('-o', '(.+)'),    "env.set('OUTPUT', pathtools.normalize($0))"),
51
52   ( '-v',              DumpVersionDebug),
53   ( '--version',       DumpVersionAndExit),
54
55   # Ignore these assembler flags
56   ( '(-Qy)',                  ""),
57   ( ('(--traditional-format)', '.*'), ""),
58   ( '(-gstabs)',              ""),
59   ( '(--gstabs)',             ""),
60   ( '(-gdwarf2)',             ""),
61   ( '(--gdwarf2)',            ""),
62   ( '(--fatal-warnings)',     ""),
63   ( '(-meabi=.*)',            ""),
64   ( '(-mfpu=.*)',             ""),
65   ( '(-march=.*)',            ""),
66
67   ( '(-.+)',  driver_tools.UnrecognizedOption),
68
69   # Unmatched parameters should be treated as
70   # assembly inputs by the "as" incarnation.
71   ( '(-)',   "env.append('INPUTS', $0)"),
72   ( '(.*)',  "env.append('INPUTS', pathtools.normalize($0))"),
73 ]
74
75 def main(argv):
76   env.update(EXTRA_ENV)
77   driver_tools.ParseArgs(argv, ASPatterns)
78   arch = driver_tools.GetArch()
79
80   inputs = env.get('INPUTS')
81   output = env.getone('OUTPUT')
82
83   num_inputs = len(inputs)
84   if num_inputs > 1:
85     Log.Fatal('Expecting exactly one input file')
86   elif num_inputs == 1:
87     the_input = inputs[0]
88   else:
89     # stdin
90     the_input = '-'
91
92
93   if arch:
94     output_type = 'o'
95   else:
96     output_type = 'po'
97
98   if output == '':
99     output = 'a.out'
100
101   env.push()
102   env.set('input', the_input)
103   env.set('output', output)
104
105   if output_type == 'po':
106     # .ll to .po
107     driver_tools.Run("${RUN_LLVM_AS}")
108   else:
109     # .s to .o
110     driver_tools.Run("${RUN_LLVM_MC}")
111   env.pop()
112   # only reached in case of no errors
113   return 0
114
115 def get_help(argv):
116   return """
117 LLVM Assembler for PNaCl
118 Transform LLVM assembly (.ll) to LLVM bitcode.
119
120 Usage: pnacl-as [options] <input .ll file> -o <output.po>
121
122 OPTIONS:
123   -o <file>        Output to file
124   --version        Display version information
125   -help | -h       Output this help.
126 """