Debian Codegraph @

mesonbuild/compilers/mixins/ccrx.py

raw
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 Renesas CC-RX compiler family."""
7
8 import os
9 import typing as T
10
11 from ...mesonlib import EnvironmentException
12
13 if T.TYPE_CHECKING:
14 from ...envconfig import MachineInfo
15 from ...compilers.compilers import Compiler
16 else:
17 # This is a bit clever, for mypy we pretend that these mixins descend from
18 # Compiler, so we get all of the methods and attributes defined for us, but
19 # for runtime we make them descend from object (which all classes normally
20 # do). This gives up DRYer type checking, with no runtime impact
21 Compiler = object
22
23 ccrx_optimization_args: T.Dict[str, T.List[str]] = {
24 '0': ['-optimize=0'],
25 'g': ['-optimize=0'],
26 '1': ['-optimize=1'],
27 '2': ['-optimize=2'],
28 '3': ['-optimize=max'],
29 's': ['-optimize=2', '-size']
30 }
31
32 ccrx_debug_args: T.Dict[bool, T.List[str]] = {
33 False: [],
34 True: ['-debug']
35 }
36
37
38 class CcrxCompiler(Compiler):
39
40 if T.TYPE_CHECKING:
41 is_cross = True
42
43 id = 'ccrx'
44
45 def __init__(self) -> None:
46 if not self.is_cross:
47 raise EnvironmentException('ccrx supports only cross-compilation.')
48 # Assembly
49 self.can_compile_suffixes.add('src')
50 default_warn_args: T.List[str] = []
51 self.warn_args: T.Dict[str, T.List[str]] = {
52 '0': [],
53 '1': default_warn_args,
54 '2': default_warn_args + [],
55 '3': default_warn_args + [],
56 'everything': default_warn_args + []}
57
58 def get_pic_args(self) -> T.List[str]:
59 # PIC support is not enabled by default for CCRX,
60 # if users want to use it, they need to add the required arguments explicitly
61 return []
62
63 def get_pch_suffix(self) -> str:
64 return 'pch'
65
66 def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
67 return []
68
69 def thread_flags(self) -> T.List[str]:
70 return []
71
72 def get_coverage_args(self) -> T.List[str]:
73 return []
74
75 def get_no_stdinc_args(self) -> T.List[str]:
76 return []
77
78 def get_no_stdlib_link_args(self) -> T.List[str]:
79 return []
80
81 def get_optimization_args(self, optimization_level: str) -> T.List[str]:
82 return ccrx_optimization_args[optimization_level]
83
84 def get_debug_args(self, is_debug: bool) -> T.List[str]:
85 return ccrx_debug_args[is_debug]
86
87 @classmethod
88 def _unix_args_to_native(cls, args: T.List[str], info: MachineInfo) -> T.List[str]:
89 result: T.List[str] = []
90 for i in args:
91 if i.startswith('-D'):
92 i = '-define=' + i[2:]
93 if i.startswith('-I'):
94 i = '-include=' + i[2:]
95 if i.startswith('-Wl,-rpath='):
96 continue
97 elif i == '--print-search-dirs':
98 continue
99 elif i.startswith('-L'):
100 continue
101 elif not i.startswith('-lib=') and i.endswith(('.a', '.lib')):
102 i = '-lib=' + i
103 result.append(i)
104 return result
105
106 def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]:
107 for idx, i in enumerate(parameter_list):
108 if i[:9] == '-include=':
109 parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:]))
110
111 return parameter_list