| 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 Microchip XC C/C++ compiler family.""" |
| 7 |
|
| 8 |
import os |
| 9 |
import typing as T |
| 10 |
|
| 11 |
from .gnu import GnuCStds, GnuCPPStds |
| 12 |
from ..compilers import Compiler |
| 13 |
from ...mesonlib import EnvironmentException, version_compare |
| 14 |
|
| 15 |
if T.TYPE_CHECKING: |
| 16 |
from ...build import BuildTarget |
| 17 |
from ...envconfig import MachineInfo |
| 18 |
|
| 19 |
CompilerBase = Compiler |
| 20 |
else: |
| 21 |
# This is a bit clever, for mypy we pretend that these mixins descend from |
| 22 |
# Compiler, so we get all of the methods and attributes defined for us, but |
| 23 |
# for runtime we make them descend from object (which all classes normally |
| 24 |
# do). This gives up DRYer type checking, with no runtime impact |
| 25 |
CompilerBase = object |
| 26 |
|
| 27 |
xc16_optimization_args: T.Dict[str, T.List[str]] = { |
| 28 |
'plain': [], |
| 29 |
'0': ['-O0'], |
| 30 |
'g': ['-O0'], |
| 31 |
'1': ['-O1'], |
| 32 |
'2': ['-O2'], |
| 33 |
'3': ['-O3'], |
| 34 |
's': ['-Os'] |
| 35 |
} |
| 36 |
|
| 37 |
xc16_debug_args: T.Dict[bool, T.List[str]] = { |
| 38 |
False: [], |
| 39 |
True: [] |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
class Xc16Compiler(Compiler): |
| 44 |
|
| 45 |
id = 'xc16' |
| 46 |
|
| 47 |
def __init__(self) -> None: |
| 48 |
if not self.is_cross: |
| 49 |
raise EnvironmentException('xc16 supports only cross-compilation.') |
| 50 |
# Assembly |
| 51 |
self.can_compile_suffixes.add('s') |
| 52 |
self.can_compile_suffixes.add('sx') |
| 53 |
default_warn_args: T.List[str] = [] |
| 54 |
self.warn_args = {'0': [], |
| 55 |
'1': default_warn_args, |
| 56 |
'2': default_warn_args + [], |
| 57 |
'3': default_warn_args + [], |
| 58 |
'everything': default_warn_args + []} |
| 59 |
|
| 60 |
def get_always_args(self) -> T.List[str]: |
| 61 |
return [] |
| 62 |
|
| 63 |
def get_pic_args(self) -> T.List[str]: |
| 64 |
# PIC support is not enabled by default for xc16, |
| 65 |
# if users want to use it, they need to add the required arguments explicitly |
| 66 |
return [] |
| 67 |
|
| 68 |
def get_pch_suffix(self) -> str: |
| 69 |
return 'pch' |
| 70 |
|
| 71 |
def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: |
| 72 |
return [] |
| 73 |
|
| 74 |
def thread_flags(self) -> T.List[str]: |
| 75 |
return [] |
| 76 |
|
| 77 |
def get_coverage_args(self) -> T.List[str]: |
| 78 |
return [] |
| 79 |
|
| 80 |
def get_no_stdinc_args(self) -> T.List[str]: |
| 81 |
return ['-nostdinc'] |
| 82 |
|
| 83 |
def get_no_stdlib_link_args(self) -> T.List[str]: |
| 84 |
return ['--nostdlib'] |
| 85 |
|
| 86 |
def get_optimization_args(self, optimization_level: str) -> T.List[str]: |
| 87 |
return xc16_optimization_args[optimization_level] |
| 88 |
|
| 89 |
def get_debug_args(self, is_debug: bool) -> T.List[str]: |
| 90 |
return xc16_debug_args[is_debug] |
| 91 |
|
| 92 |
@classmethod |
| 93 |
def _unix_args_to_native(cls, args: T.List[str], info: MachineInfo) -> T.List[str]: |
| 94 |
result = [] |
| 95 |
for i in args: |
| 96 |
if i.startswith('-D'): |
| 97 |
i = '-D' + i[2:] |
| 98 |
if i.startswith('-I'): |
| 99 |
i = '-I' + i[2:] |
| 100 |
if i.startswith('-Wl,-rpath='): |
| 101 |
continue |
| 102 |
elif i == '--print-search-dirs': |
| 103 |
continue |
| 104 |
elif i.startswith('-L'): |
| 105 |
continue |
| 106 |
result.append(i) |
| 107 |
return result |
| 108 |
|
| 109 |
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]: |
| 110 |
for idx, i in enumerate(parameter_list): |
| 111 |
if i[:9] == '-I': |
| 112 |
parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:])) |
| 113 |
|
| 114 |
return parameter_list |
| 115 |
|
| 116 |
|
| 117 |
class Xc32Compiler(CompilerBase): |
| 118 |
|
| 119 |
"""Microchip XC32 compiler mixin. GCC based with some options disabled.""" |
| 120 |
|
| 121 |
id = 'xc32-gcc' |
| 122 |
|
| 123 |
gcc_version = '4.5.1' # Defaults to GCC version used by first XC32 release (v1.00). |
| 124 |
|
| 125 |
_COLOR_VERSION = '>=3.0' # XC32 version based on GCC 8.3.1+ |
| 126 |
_WPEDANTIC_VERSION = '>=1.40' # XC32 version based on GCC 4.8.3+ |
| 127 |
_LTO_AUTO_VERSION = '>=5.00' # XC32 version based on GCC 13.2.1+ |
| 128 |
_LTO_CACHE_VERSION = '==-1' |
| 129 |
_USE_MOLD_VERSION = '==-1' |
| 130 |
|
| 131 |
def __init__(self) -> None: |
| 132 |
if not self.is_cross: |
| 133 |
raise EnvironmentException('XC32 supports only cross-compilation.') |
| 134 |
|
| 135 |
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]: |
| 136 |
return None |
| 137 |
|
| 138 |
def thread_flags(self) -> T.List[str]: |
| 139 |
return [] |
| 140 |
|
| 141 |
def openmp_flags(self) -> T.List[str]: |
| 142 |
return Compiler.openmp_flags(self) |
| 143 |
|
| 144 |
def get_pic_args(self) -> T.List[str]: |
| 145 |
return Compiler.get_pic_args(self) |
| 146 |
|
| 147 |
def get_pie_args(self) -> T.List[str]: |
| 148 |
return Compiler.get_pie_args(self) |
| 149 |
|
| 150 |
def get_profile_generate_args(self) -> T.List[str]: |
| 151 |
return Compiler.get_profile_generate_args(self) |
| 152 |
|
| 153 |
def get_profile_use_args(self) -> T.List[str]: |
| 154 |
return Compiler.get_profile_use_args(self) |
| 155 |
|
| 156 |
def sanitizer_compile_args(self, target: T.Optional[BuildTarget], value: T.List[str]) -> T.List[str]: |
| 157 |
return [] |
| 158 |
|
| 159 |
@classmethod |
| 160 |
def use_linker_args(cls, linker: str, version: str) -> T.List[str]: |
| 161 |
return [] |
| 162 |
|
| 163 |
def get_coverage_args(self) -> T.List[str]: |
| 164 |
return [] |
| 165 |
|
| 166 |
def get_largefile_args(self) -> T.List[str]: |
| 167 |
return [] |
| 168 |
|
| 169 |
def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.Tuple[T.List[str], T.List[str]]: |
| 170 |
return Compiler.get_prelink_args(self, prelink_name, obj_list) |
| 171 |
|
| 172 |
def get_prelink_append_compile_args(self) -> bool: |
| 173 |
return False |
| 174 |
|
| 175 |
def supported_warn_args(self, warn_args_by_version: T.Dict[str, T.List[str]]) -> T.List[str]: |
| 176 |
result: T.List[str] = [] |
| 177 |
for version, warn_args in warn_args_by_version.items(): |
| 178 |
if version_compare(self.gcc_version, '>=' + version): |
| 179 |
result += warn_args |
| 180 |
return result |
| 181 |
|
| 182 |
class Xc32CStds(GnuCStds): |
| 183 |
|
| 184 |
"""Mixin for setting C standards based on XC32 version.""" |
| 185 |
|
| 186 |
_C18_VERSION = '>=3.0' |
| 187 |
_C2X_VERSION = '>=5.00' |
| 188 |
_C23_VERSION = '==-1' |
| 189 |
_C2Y_VERSION = '==-1' |
| 190 |
|
| 191 |
class Xc32CPPStds(GnuCPPStds): |
| 192 |
|
| 193 |
"""Mixin for setting C++ standards based on XC32 version.""" |
| 194 |
|
| 195 |
_CPP23_VERSION = '>=5.00' |
| 196 |
_CPP26_VERSION = '==-1' |