| 1 |
# SPDX-License-Identifier: Apache-2.0 |
| 2 |
# Copyright 2012-2020 Meson development team |
| 3 |
|
| 4 |
from __future__ import annotations |
| 5 |
|
| 6 |
"""Representations specific to the arm family of compilers.""" |
| 7 |
|
| 8 |
import os |
| 9 |
import typing as T |
| 10 |
|
| 11 |
from ... import mesonlib |
| 12 |
from ...linkers.linkers import ArmClangDynamicLinker |
| 13 |
from ...options import OptionKey |
| 14 |
from ..compilers import clike_debug_args |
| 15 |
from .clang import clang_color_args |
| 16 |
|
| 17 |
if T.TYPE_CHECKING: |
| 18 |
from ...compilers.compilers import Compiler |
| 19 |
else: |
| 20 |
# This is a bit clever, for mypy we pretend that these mixins descend from |
| 21 |
# Compiler, so we get all of the methods and attributes defined for us, but |
| 22 |
# for runtime we make them descend from object (which all classes normally |
| 23 |
# do). This gives up DRYer type checking, with no runtime impact |
| 24 |
Compiler = object |
| 25 |
|
| 26 |
arm_optimization_args: T.Dict[str, T.List[str]] = { |
| 27 |
'plain': [], |
| 28 |
'0': ['-O0'], |
| 29 |
'g': ['-g'], |
| 30 |
'1': ['-O1'], |
| 31 |
'2': [], # Compiler defaults to -O2 |
| 32 |
'3': ['-O3', '-Otime'], |
| 33 |
's': ['-O3'], # Compiler defaults to -Ospace |
| 34 |
} |
| 35 |
|
| 36 |
armclang_optimization_args: T.Dict[str, T.List[str]] = { |
| 37 |
'plain': [], |
| 38 |
'0': [], # Compiler defaults to -O0 |
| 39 |
'g': ['-g'], |
| 40 |
'1': ['-O1'], |
| 41 |
'2': ['-O2'], |
| 42 |
'3': ['-O3'], |
| 43 |
's': ['-Oz'] |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
class ArmCompiler(Compiler): |
| 48 |
|
| 49 |
"""Functionality that is common to all ARM family compilers.""" |
| 50 |
|
| 51 |
id = 'arm' |
| 52 |
|
| 53 |
def __init__(self) -> None: |
| 54 |
if not self.is_cross: |
| 55 |
raise mesonlib.EnvironmentException('armcc supports only cross-compilation.') |
| 56 |
default_warn_args: T.List[str] = [] |
| 57 |
self.warn_args = {'0': [], |
| 58 |
'1': default_warn_args, |
| 59 |
'2': default_warn_args + [], |
| 60 |
'3': default_warn_args + [], |
| 61 |
'everything': default_warn_args + []} |
| 62 |
# Assembly |
| 63 |
self.can_compile_suffixes.add('s') |
| 64 |
self.can_compile_suffixes.add('sx') |
| 65 |
|
| 66 |
def get_pic_args(self) -> T.List[str]: |
| 67 |
# FIXME: Add /ropi, /rwpi, /fpic etc. qualifiers to --apcs |
| 68 |
return [] |
| 69 |
|
| 70 |
# Override CCompiler.get_always_args |
| 71 |
def get_always_args(self) -> T.List[str]: |
| 72 |
return [] |
| 73 |
|
| 74 |
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: |
| 75 |
return ['--depend_target', outtarget, '--depend', outfile, '--depend_single_line'] |
| 76 |
|
| 77 |
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: |
| 78 |
# FIXME: Add required arguments |
| 79 |
# NOTE from armcc user guide: |
| 80 |
# "Support for Precompiled Header (PCH) files is deprecated from ARM Compiler 5.05 |
| 81 |
# onwards on all platforms. Note that ARM Compiler on Windows 8 never supported |
| 82 |
# PCH files." |
| 83 |
return [] |
| 84 |
|
| 85 |
def get_pch_suffix(self) -> str: |
| 86 |
# NOTE from armcc user guide: |
| 87 |
# "Support for Precompiled Header (PCH) files is deprecated from ARM Compiler 5.05 |
| 88 |
# onwards on all platforms. Note that ARM Compiler on Windows 8 never supported |
| 89 |
# PCH files." |
| 90 |
return 'pch' |
| 91 |
|
| 92 |
def thread_flags(self,) -> T.List[str]: |
| 93 |
return [] |
| 94 |
|
| 95 |
def get_coverage_args(self) -> T.List[str]: |
| 96 |
return [] |
| 97 |
|
| 98 |
def get_optimization_args(self, optimization_level: str) -> T.List[str]: |
| 99 |
return arm_optimization_args[optimization_level] |
| 100 |
|
| 101 |
def get_debug_args(self, is_debug: bool) -> T.List[str]: |
| 102 |
return clike_debug_args[is_debug] |
| 103 |
|
| 104 |
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]: |
| 105 |
for idx, i in enumerate(parameter_list): |
| 106 |
if i[:2] == '-I' or i[:2] == '-L': |
| 107 |
parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:])) |
| 108 |
|
| 109 |
return parameter_list |
| 110 |
|
| 111 |
|
| 112 |
class ArmclangCompiler(Compiler): |
| 113 |
''' |
| 114 |
This is the Keil armclang. |
| 115 |
''' |
| 116 |
|
| 117 |
id = 'armclang' |
| 118 |
|
| 119 |
def __init__(self) -> None: |
| 120 |
if not self.is_cross: |
| 121 |
raise mesonlib.EnvironmentException('armclang supports only cross-compilation.') |
| 122 |
# Check whether 'armlink' is available in path |
| 123 |
if not isinstance(self.linker, ArmClangDynamicLinker): |
| 124 |
raise mesonlib.EnvironmentException(f'Unsupported Linker {self.linker.exelist}, must be armlink') |
| 125 |
if not mesonlib.version_compare(self.version, '==' + self.linker.version): |
| 126 |
raise mesonlib.EnvironmentException('armlink version does not match with compiler version') |
| 127 |
self.base_options = { |
| 128 |
OptionKey(o) for o in |
| 129 |
['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage', |
| 130 |
'b_ndebug', 'b_staticpic', 'b_colorout']} |
| 131 |
# Assembly |
| 132 |
self.can_compile_suffixes.add('s') |
| 133 |
self.can_compile_suffixes.add('sx') |
| 134 |
|
| 135 |
def get_pic_args(self) -> T.List[str]: |
| 136 |
# PIC support is not enabled by default for ARM, |
| 137 |
# if users want to use it, they need to add the required arguments explicitly |
| 138 |
return [] |
| 139 |
|
| 140 |
def get_colorout_args(self, colortype: str) -> T.List[str]: |
| 141 |
return clang_color_args[colortype][:] |
| 142 |
|
| 143 |
def get_cpp_permissive_args(self) -> T.List[str]: |
| 144 |
return ['-fpermissive'] |
| 145 |
|
| 146 |
def get_pch_suffix(self) -> str: |
| 147 |
return 'gch' |
| 148 |
|
| 149 |
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: |
| 150 |
# Workaround for Clang bug http://llvm.org/bugs/show_bug.cgi?id=15136 |
| 151 |
# This flag is internal to Clang (or at least not documented on the man page) |
| 152 |
# so it might change semantics at any time. |
| 153 |
return ['-include-pch', os.path.join(pch_dir, self.get_pch_name(header))] |
| 154 |
|
| 155 |
def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: |
| 156 |
return ['-MD', '-MT', outtarget, '-MF', outfile] |
| 157 |
|
| 158 |
def get_optimization_args(self, optimization_level: str) -> T.List[str]: |
| 159 |
return armclang_optimization_args[optimization_level] |
| 160 |
|
| 161 |
def get_debug_args(self, is_debug: bool) -> T.List[str]: |
| 162 |
return clike_debug_args[is_debug] |
| 163 |
|
| 164 |
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]: |
| 165 |
for idx, i in enumerate(parameter_list): |
| 166 |
if i[:2] == '-I' or i[:2] == '-L': |
| 167 |
parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:])) |
| 168 |
|
| 169 |
return parameter_list |