Debian Codegraph @

mesonbuild/compilers/mixins/ti.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 Texas Instruments 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 ti_optimization_args: T.Dict[str, T.List[str]] = {
24 'plain': [],
25 '0': ['-O0'],
26 'g': ['-Ooff'],
27 '1': ['-O1'],
28 '2': ['-O2'],
29 '3': ['-O3'],
30 's': ['-O4']
31 }
32
33 ti_debug_args: T.Dict[bool, T.List[str]] = {
34 False: [],
35 True: ['-g']
36 }
37
38
39 class TICompiler(Compiler):
40
41 id = 'ti'
42
43 if T.TYPE_CHECKING:
44 # Older versions of mypy can't figure this out for some reason.
45 is_cross: bool
46
47 def __init__(self) -> None:
48 if not self.is_cross:
49 raise EnvironmentException('TI compilers only support cross-compilation.')
50
51 self.can_compile_suffixes.add('asm') # Assembly
52 self.can_compile_suffixes.add('cla') # Control Law Accelerator (CLA) used in C2000
53
54 default_warn_args: T.List[str] = []
55 self.warn_args: T.Dict[str, T.List[str]] = {
56 '0': [],
57 '1': default_warn_args,
58 '2': default_warn_args + [],
59 '3': default_warn_args + [],
60 'everything': default_warn_args + []}
61
62 def get_pic_args(self) -> T.List[str]:
63 # PIC support is not enabled by default for TI compilers,
64 # if users want to use it, they need to add the required arguments explicitly
65 return []
66
67 def get_pch_suffix(self) -> str:
68 return 'pch'
69
70 def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
71 return []
72
73 def thread_flags(self) -> T.List[str]:
74 return []
75
76 def get_coverage_args(self) -> T.List[str]:
77 return []
78
79 def get_no_stdinc_args(self) -> T.List[str]:
80 return []
81
82 def get_no_stdlib_link_args(self) -> T.List[str]:
83 return []
84
85 def get_optimization_args(self, optimization_level: str) -> T.List[str]:
86 return ti_optimization_args[optimization_level]
87
88 def get_debug_args(self, is_debug: bool) -> T.List[str]:
89 return ti_debug_args[is_debug]
90
91 def get_compile_only_args(self) -> T.List[str]:
92 return []
93
94 def get_no_optimization_args(self) -> T.List[str]:
95 return ['-Ooff']
96
97 def get_output_args(self, outputname: str) -> T.List[str]:
98 return [f'--output_file={outputname}']
99
100 def get_werror_args(self) -> T.List[str]:
101 return ['--emit_warnings_as_errors']
102
103 def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
104 if path == '':
105 path = '.'
106 return ['-I' + path]
107
108 @classmethod
109 def _unix_args_to_native(cls, args: T.List[str], info: MachineInfo) -> T.List[str]:
110 result: T.List[str] = []
111 for i in args:
112 if i.startswith('-Wl,-rpath='):
113 continue
114 elif i == '--print-search-dirs':
115 continue
116 elif i.startswith('-L'):
117 continue
118 result.append(i)
119 return result
120
121 def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]:
122 for idx, i in enumerate(parameter_list):
123 if i[:15] == '--include_path=':
124 parameter_list[idx] = i[:15] + os.path.normpath(os.path.join(build_dir, i[15:]))
125 if i[:2] == '-I':
126 parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:]))
127
128 return parameter_list
129
130 def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
131 return ['--preproc_with_compile', f'--preproc_dependency={outfile}']