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