1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
# Copyright 2012-2019 The Meson development team
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
"""Representations specific to the Metrowerks/Freescale Embedded C/C++ compiler family."""
import os
import typing as T
from ...mesonlib import EnvironmentException, OptionKey
if T.TYPE_CHECKING:
from ...envconfig import MachineInfo
from ...compilers.compilers import Compiler, CompileCheckMode
else:
# This is a bit clever, for mypy we pretend that these mixins descend from
# Compiler, so we get all of the methods and attributes defined for us, but
# for runtime we make them descend from object (which all classes normally
# do). This gives up DRYer type checking, with no runtime impact
Compiler = object
mwcc_buildtype_args: T.Dict[str, T.List[str]] = {
'plain': [],
'debug': [],
'debugoptimized': [],
'release': [],
'minsize': [],
'custom': [],
}
mwccarm_instruction_set_args: T.Dict[str, T.List[str]] = {
'generic': ['-proc', 'generic'],
'v4': ['-proc', 'v4'],
'v4t': ['-proc', 'v4t'],
'v5t': ['-proc', 'v5t'],
'v5te': ['-proc', 'v5te'],
'v6': ['-proc', 'v6'],
'arm7tdmi': ['-proc', 'arm7tdmi'],
'arm710t': ['-proc', 'arm710t'],
'arm720t': ['-proc', 'arm720t'],
'arm740t': ['-proc', 'arm740t'],
'arm7ej': ['-proc', 'arm7ej'],
'arm9tdmi': ['-proc', 'arm9tdmi'],
'arm920t': ['-proc', 'arm920t'],
'arm922t': ['-proc', 'arm922t'],
'arm940t': ['-proc', 'arm940t'],
'arm9ej': ['-proc', 'arm9ej'],
'arm926ej': ['-proc', 'arm926ej'],
'arm946e': ['-proc', 'arm946e'],
'arm966e': ['-proc', 'arm966e'],
'arm1020e': ['-proc', 'arm1020e'],
'arm1022e': ['-proc', 'arm1022e'],
'arm1026ej': ['-proc', 'arm1026ej'],
'dbmx1': ['-proc', 'dbmx1'],
'dbmxl': ['-proc', 'dbmxl'],
'XScale': ['-proc', 'XScale'],
'pxa255': ['-proc', 'pxa255'],
'pxa261': ['-proc', 'pxa261'],
'pxa262': ['-proc', 'pxa262'],
'pxa263': ['-proc', 'pxa263']
}
mwcceppc_instruction_set_args: T.Dict[str, T.List[str]] = {
'generic': ['-proc', 'generic'],
'401': ['-proc', '401'],
'403': ['-proc', '403'],
'505': ['-proc', '505'],
'509': ['-proc', '509'],
'555': ['-proc', '555'],
'601': ['-proc', '601'],
'602': ['-proc', '602'],
'603': ['-proc', '603'],
'603e': ['-proc', '603e'],
'604': ['-proc', '604'],
'604e': ['-proc', '604e'],
'740': ['-proc', '740'],
'750': ['-proc', '750'],
'801': ['-proc', '801'],
'821': ['-proc', '821'],
'823': ['-proc', '823'],
'850': ['-proc', '850'],
'860': ['-proc', '860'],
'7400': ['-proc', '7400'],
'7450': ['-proc', '7450'],
'8240': ['-proc', '8240'],
'8260': ['-proc', '8260'],
'e500': ['-proc', 'e500'],
'gekko': ['-proc', 'gekko'],
}
mwasmarm_instruction_set_args: T.Dict[str, T.List[str]] = {
'arm4': ['-proc', 'arm4'],
'arm4t': ['-proc', 'arm4t'],
'arm4xm': ['-proc', 'arm4xm'],
'arm4txm': ['-proc', 'arm4txm'],
'arm5': ['-proc', 'arm5'],
'arm5T': ['-proc', 'arm5T'],
'arm5xM': ['-proc', 'arm5xM'],
'arm5TxM': ['-proc', 'arm5TxM'],
'arm5TE': ['-proc', 'arm5TE'],
'arm5TExP': ['-proc', 'arm5TExP'],
'arm6': ['-proc', 'arm6'],
'xscale': ['-proc', 'xscale']
}
mwasmeppc_instruction_set_args: T.Dict[str, T.List[str]] = {
'401': ['-proc', '401'],
'403': ['-proc', '403'],
'505': ['-proc', '505'],
'509': ['-proc', '509'],
'555': ['-proc', '555'],
'56X': ['-proc', '56X'],
'601': ['-proc', '601'],
'602': ['-proc', '602'],
'603': ['-proc', '603'],
'603e': ['-proc', '603e'],
'604': ['-proc', '604'],
'604e': ['-proc', '604e'],
'740': ['-proc', '740'],
'74X': ['-proc', '74X'],
'750': ['-proc', '750'],
'75X': ['-proc', '75X'],
'801': ['-proc', '801'],
'821': ['-proc', '821'],
'823': ['-proc', '823'],
'850': ['-proc', '850'],
'85X': ['-proc', '85X'],
'860': ['-proc', '860'],
'86X': ['-proc', '86X'],
'87X': ['-proc', '87X'],
'88X': ['-proc', '88X'],
'5100': ['-proc', '5100'],
'5200': ['-proc', '5200'],
'7400': ['-proc', '7400'],
'744X': ['-proc', '744X'],
'7450': ['-proc', '7450'],
'745X': ['-proc', '745X'],
'82XX': ['-proc', '82XX'],
'8240': ['-proc', '8240'],
'824X': ['-proc', '824X'],
'8260': ['-proc', '8260'],
'827X': ['-proc', '827X'],
'8280': ['-proc', '8280'],
'e300': ['-proc', 'e300'],
'e300c2': ['-proc', 'e300c2'],
'e300c3': ['-proc', 'e300c3'],
'e300c4': ['-proc', 'e300c4'],
'e600': ['-proc', 'e600'],
'85xx': ['-proc', '85xx'],
'e500': ['-proc', 'e500'],
'e500v2': ['-proc', 'e500v2'],
'Zen': ['-proc', 'Zen'],
'5565': ['-proc', '5565'],
'5674': ['-proc', '5674'],
'gekko': ['-proc', 'gekko'],
'generic': ['-proc', 'generic'],
}
mwcc_optimization_args: T.Dict[str, T.List[str]] = {
'plain': [],
'0': ['-O0'],
'g': ['-Op'],
'1': ['-O1'],
'2': ['-O2'],
'3': ['-O4,p'],
's': ['-Os']
}
mwcc_debug_args: T.Dict[bool, T.List[str]] = {
False: [],
True: ['-g']
}
class MetrowerksCompiler(Compiler):
id = 'mwcc'
# These compilers can actually invoke the linker, but they choke on
# linker-specific flags. So it's best to invoke the linker directly
INVOKES_LINKER = False
def __init__(self) -> None:
if not self.is_cross:
raise EnvironmentException(f'{id} supports only cross-compilation.')
self.base_options = {
OptionKey(o) for o in ['b_pch', 'b_ndebug']}
default_warn_args: T.List[str] = []
self.warn_args: T.Dict[str, T.List[str]] = {
'0': ['-w', 'off'],
'1': default_warn_args,
'2': default_warn_args + ['-w', 'most'],
'3': default_warn_args + ['-w', 'all'],
'everything': default_warn_args + ['-w', 'full']}
def depfile_for_object(self, objfile: str) -> T.Optional[str]:
# Earlier versions of these compilers do not support specifying
# a custom name for a depfile, and can only generate '<input_file>.d'
return os.path.splitext(objfile)[0] + '.' + self.get_depfile_suffix()
def get_always_args(self) -> T.List[str]:
return ['-gccinc']
def get_buildtype_args(self, buildtype: str) -> T.List[str]:
return mwcc_buildtype_args[buildtype]
def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
return []
def get_compile_only_args(self) -> T.List[str]:
return ['-c']
def get_debug_args(self, is_debug: bool) -> T.List[str]:
return mwcc_debug_args[is_debug]
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
# Check comment in depfile_for_object()
return ['-gccdep', '-MD']
def get_depfile_suffix(self) -> str:
return 'd'
def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
if not path:
path = '.'
return ['-I' + path]
def get_no_optimization_args(self) -> T.List[str]:
return ['-opt', 'off']
def get_no_stdinc_args(self) -> T.List[str]:
return ['-nostdinc']
def get_no_stdlib_link_args(self) -> T.List[str]:
return ['-nostdlib']
def get_optimization_args(self, optimization_level: str) -> T.List[str]:
return mwcc_optimization_args[optimization_level]
def get_output_args(self, outputname: str) -> T.List[str]:
return ['-o', outputname]
def get_pic_args(self) -> T.List[str]:
return ['-pic']
def get_preprocess_only_args(self) -> T.List[str]:
return ['-E']
def get_preprocess_to_file_args(self) -> T.List[str]:
return ['-P']
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
return ['-prefix', self.get_pch_name(header)]
def get_pch_name(self, name: str) -> str:
return os.path.basename(name) + '.' + self.get_pch_suffix()
def get_pch_suffix(self) -> str:
return 'mch'
def get_warn_args(self, level: str) -> T.List[str]:
return self.warn_args[level]
def get_werror_args(self) -> T.List[str]:
return ['-w', 'error']
@classmethod
def _unix_args_to_native(cls, args: T.List[str], info: MachineInfo) -> T.List[str]:
result: T.List[str] = []
for i in args:
if i.startswith('-D'):
i = '-D' + i[2:]
if i.startswith('-I'):
i = '-I' + i[2:]
if i.startswith('-Wl,-rpath='):
continue
elif i == '--print-search-dirs':
continue
elif i.startswith('-L'):
continue
result.append(i)
return result
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]:
for idx, i in enumerate(parameter_list):
if i[:2] == '-I':
parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:]))
return parameter_list
|