diff options
author | William Toohey <wtoohey@tritium.com.au> | 2022-01-27 12:45:57 +1000 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2022-02-02 16:45:05 +0200 |
commit | b4d9b2551c32288754a3008d14895c6fe53f48e2 (patch) | |
tree | 0e13c8818bbd8e368ca01069154b8482a047a833 /mesonbuild/compilers | |
parent | 316cf3a717744bd849a04de4a1625c06779f90a9 (diff) | |
download | meson-b4d9b2551c32288754a3008d14895c6fe53f48e2.zip meson-b4d9b2551c32288754a3008d14895c6fe53f48e2.tar.gz meson-b4d9b2551c32288754a3008d14895c6fe53f48e2.tar.bz2 |
Genericise TI compiler and add MSP430 support
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/__init__.py | 4 | ||||
-rw-r--r-- | mesonbuild/compilers/c.py | 25 | ||||
-rw-r--r-- | mesonbuild/compilers/cpp.py | 21 | ||||
-rw-r--r-- | mesonbuild/compilers/detect.py | 48 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/ti.py (renamed from mesonbuild/compilers/mixins/c2000.py) | 47 |
5 files changed, 83 insertions, 62 deletions
diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index 807a009..034063a 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -120,6 +120,8 @@ __all__ = [ 'CompCertCCompiler', 'C2000CCompiler', 'C2000CPPCompiler', + 'TICCompiler', + 'TICPPCompiler', 'SunFortranCompiler', 'SwiftCompiler', 'ValaCompiler', @@ -188,6 +190,7 @@ from .c import ( Xc16CCompiler, CompCertCCompiler, C2000CCompiler, + TICCompiler, VisualStudioCCompiler, ) from .cpp import ( @@ -206,6 +209,7 @@ from .cpp import ( PGICPPCompiler, CcrxCPPCompiler, C2000CPPCompiler, + TICPPCompiler, VisualStudioCPPCompiler, ) from .cs import MonoCompiler, VisualStudioCsCompiler diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 474bf3b..610473d 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -23,7 +23,7 @@ from .mixins.clike import CLikeCompiler from .mixins.ccrx import CcrxCompiler from .mixins.xc16 import Xc16Compiler from .mixins.compcert import CompCertCompiler -from .mixins.c2000 import C2000Compiler +from .mixins.ti import TICompiler from .mixins.arm import ArmCompiler, ArmclangCompiler from .mixins.visualstudio import MSVCCompiler, ClangClCompiler from .mixins.gnu import GnuCompiler @@ -685,7 +685,7 @@ class CompCertCCompiler(CompCertCompiler, CCompiler): path = '.' return ['-I' + path] -class C2000CCompiler(C2000Compiler, CCompiler): +class TICCompiler(TICompiler, CCompiler): def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, @@ -693,7 +693,7 @@ class C2000CCompiler(C2000Compiler, CCompiler): full_version: T.Optional[str] = None): CCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version) - C2000Compiler.__init__(self) + TICompiler.__init__(self) # Override CCompiler.get_always_args def get_always_args(self) -> T.List[str]: @@ -716,19 +716,6 @@ class C2000CCompiler(C2000Compiler, CCompiler): args.append('--' + std.value) return args - def get_compile_only_args(self) -> T.List[str]: - return [] - - def get_no_optimization_args(self) -> T.List[str]: - return ['-Ooff'] - - def get_output_args(self, target: str) -> T.List[str]: - return [f'--output_file={target}'] - - def get_werror_args(self) -> T.List[str]: - return ['-change_message=error'] - - def get_include_args(self, path: str, is_system: bool) -> T.List[str]: - if path == '': - path = '.' - return ['--include_path=' + path] +class C2000CCompiler(TICCompiler): + # Required for backwards compat with projects created before ti-cgt support existed + id = 'c2000' diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 749da2f..a26f731 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -30,7 +30,7 @@ from .compilers import ( from .c_function_attributes import CXX_FUNC_ATTRIBUTES, C_FUNC_ATTRIBUTES from .mixins.clike import CLikeCompiler from .mixins.ccrx import CcrxCompiler -from .mixins.c2000 import C2000Compiler +from .mixins.ti import TICompiler from .mixins.arm import ArmCompiler, ArmclangCompiler from .mixins.visualstudio import MSVCCompiler, ClangClCompiler from .mixins.gnu import GnuCompiler @@ -839,14 +839,14 @@ class CcrxCPPCompiler(CcrxCompiler, CPPCompiler): def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: return [] -class C2000CPPCompiler(C2000Compiler, CPPCompiler): +class TICPPCompiler(TICompiler, CPPCompiler): def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, linker: T.Optional['DynamicLinker'] = None, full_version: T.Optional[str] = None): CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version) - C2000Compiler.__init__(self) + TICompiler.__init__(self) def get_options(self) -> 'KeyedOptionDictType': opts = CPPCompiler.get_options(self) @@ -862,13 +862,12 @@ class C2000CPPCompiler(C2000Compiler, CPPCompiler): args.append('--' + std.value) return args - def get_no_optimization_args(self) -> T.List[str]: - return ['-Ooff'] + def get_always_args(self) -> T.List[str]: + return [] - def get_output_args(self, target: str) -> T.List[str]: - return [f'--output_file={target}'] + def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]: + return [] - def get_include_args(self, path: str, is_system: bool) -> T.List[str]: - if path == '': - path = '.' - return ['--include_path=' + path] +class C2000CPPCompiler(TICPPCompiler): + # Required for backwards compat with projects created before ti-cgt support existed + id = 'c2000' diff --git a/mesonbuild/compilers/detect.py b/mesonbuild/compilers/detect.py index 4a5e72f..9216ecf 100644 --- a/mesonbuild/compilers/detect.py +++ b/mesonbuild/compilers/detect.py @@ -33,6 +33,8 @@ from ..linkers import ( CompCertDynamicLinker, C2000Linker, C2000DynamicLinker, + TILinker, + TIDynamicLinker, DLinker, NAGDynamicLinker, NvidiaHPC_DynamicLinker, @@ -68,6 +70,7 @@ from .c import ( Xc16CCompiler, CompCertCCompiler, C2000CCompiler, + TICCompiler, VisualStudioCCompiler, ) from .cpp import ( @@ -87,6 +90,7 @@ from .cpp import ( PGICPPCompiler, CcrxCPPCompiler, C2000CPPCompiler, + TICPPCompiler, VisualStudioCPPCompiler, ) from .cs import MonoCompiler, VisualStudioCsCompiler @@ -295,9 +299,11 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker linkers = default_linkers popen_exceptions = {} for linker in linkers: - if not {'lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe', 'xilib', 'xilib.exe'}.isdisjoint(linker): + linker_name = os.path.basename(linker[0]) + + if any(os.path.basename(x) in {'lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe', 'xilib', 'xilib.exe'} for x in linker): arg = '/?' - elif not {'ar2000', 'ar2000.exe'}.isdisjoint(linker): + elif linker_name in {'ar2000', 'ar2000.exe', 'ar430', 'ar430.exe', 'armar', 'armar.exe'}: arg = '?' else: arg = '--version' @@ -312,7 +318,7 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker return VisualStudioLinker(linker, getattr(compiler, 'machine', None)) if 'ar-Error-Unknown switch: --version' in err: return PGIStaticLinker(linker) - if p.returncode == 0 and ('armar' in linker or 'armar.exe' in linker): + if p.returncode == 0 and 'armar' in linker_name: return ArmarLinker(linker) if 'DMD32 D Compiler' in out or 'DMD64 D Compiler' in out: assert isinstance(compiler, DCompiler) @@ -323,12 +329,15 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker if 'GDC' in out and ' based on D ' in out: assert isinstance(compiler, DCompiler) return DLinker(linker, compiler.arch) - if err.startswith('Renesas') and ('rlink' in linker or 'rlink.exe' in linker): + if err.startswith('Renesas') and 'rlink' in linker_name: return CcrxLinker(linker) - if out.startswith('GNU ar') and ('xc16-ar' in linker or 'xc16-ar.exe' in linker): + if out.startswith('GNU ar') and 'xc16-ar' in linker_name: return Xc16Linker(linker) - if out.startswith('TMS320C2000') and ('ar2000' in linker or 'ar2000.exe' in linker): - return C2000Linker(linker) + if 'Texas Instruments Incorporated' in out: + if 'ar2000' in linker_name: + return C2000Linker(linker) + else: + return TILinker(linker) if out.startswith('The CompCert'): return CompCertLinker(linker) if p.returncode == 0: @@ -397,7 +406,8 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin arg = '--version' elif 'ccomp' in compiler_name: arg = '-version' - elif 'cl2000' in compiler_name: + elif compiler_name in {'cl2000', 'cl2000.exe', 'cl430', 'cl430.exe', 'armcl', 'armcl.exe'}: + # TI compiler arg = '-version' elif compiler_name in {'icl', 'icl.exe'}: # if you pass anything to icl you get stuck in a pager @@ -602,6 +612,20 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin return cls( ccache + compiler, version, for_machine, is_cross, info, exe_wrap, full_version=full_version, linker=l) + if 'TMS320C2000 C/C++' in out or 'MSP430 C/C++' in out or 'TI ARM C/C++ Compiler' in out: + lnk : T.Union[T.Type[C2000DynamicLinker], T.Type[TIDynamicLinker]] + if 'TMS320C2000 C/C++' in out: + cls = C2000CCompiler if lang == 'c' else C2000CPPCompiler + lnk = C2000DynamicLinker + else: + cls = TICCompiler if lang == 'c' else TICPPCompiler + lnk = TIDynamicLinker + + env.coredata.add_lang_args(cls.language, cls, for_machine, env) + linker = lnk(compiler, for_machine, version=version) + return cls( + ccache + compiler, version, for_machine, is_cross, info, + exe_wrap, full_version=full_version, linker=linker) if 'ARM' in out: cls = ArmCCompiler if lang == 'c' else ArmCPPCompiler env.coredata.add_lang_args(cls.language, cls, for_machine, env) @@ -633,14 +657,6 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin ccache + compiler, version, for_machine, is_cross, info, exe_wrap, full_version=full_version, linker=linker) - if 'TMS320C2000 C/C++' in out: - cls = C2000CCompiler if lang == 'c' else C2000CPPCompiler - env.coredata.add_lang_args(cls.language, cls, for_machine, env) - linker = C2000DynamicLinker(compiler, for_machine, version=version) - return cls( - ccache + compiler, version, for_machine, is_cross, info, - exe_wrap, full_version=full_version, linker=linker) - _handle_exceptions(popen_exceptions, compilers) raise EnvironmentException(f'Unknown compiler {compilers}') diff --git a/mesonbuild/compilers/mixins/c2000.py b/mesonbuild/compilers/mixins/ti.py index f614d16..60804f7 100644 --- a/mesonbuild/compilers/mixins/c2000.py +++ b/mesonbuild/compilers/mixins/ti.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Representations specific to the Texas Instruments C2000 compiler family.""" +"""Representations specific to the Texas Instruments compiler family.""" import os import typing as T @@ -29,7 +29,7 @@ else: # do). This gives up DRYer type checking, with no runtime impact Compiler = object -c2000_buildtype_args = { +ti_buildtype_args = { 'plain': [], 'debug': [], 'debugoptimized': [], @@ -38,7 +38,7 @@ c2000_buildtype_args = { 'custom': [], } # type: T.Dict[str, T.List[str]] -c2000_optimization_args = { +ti_optimization_args = { '0': ['-O0'], 'g': ['-Ooff'], '1': ['-O1'], @@ -47,22 +47,22 @@ c2000_optimization_args = { 's': ['-04'] } # type: T.Dict[str, T.List[str]] -c2000_debug_args = { +ti_debug_args = { False: [], True: ['-g'] } # type: T.Dict[bool, T.List[str]] -class C2000Compiler(Compiler): +class TICompiler(Compiler): - id = 'c2000' + id = 'ti' def __init__(self) -> None: if not self.is_cross: - raise EnvironmentException('c2000 supports only cross-compilation.') + raise EnvironmentException('TI compilers only support cross-compilation.') self.can_compile_suffixes.add('asm') # Assembly - self.can_compile_suffixes.add('cla') # Control Law Accelerator (CLA) + self.can_compile_suffixes.add('cla') # Control Law Accelerator (CLA) used in C2000 default_warn_args = [] # type: T.List[str] self.warn_args = {'0': [], @@ -71,12 +71,12 @@ class C2000Compiler(Compiler): '3': default_warn_args + []} # type: T.Dict[str, T.List[str]] def get_pic_args(self) -> T.List[str]: - # PIC support is not enabled by default for c2000, + # PIC support is not enabled by default for TI compilers, # if users want to use it, they need to add the required arguments explicitly return [] def get_buildtype_args(self, buildtype: str) -> T.List[str]: - return c2000_buildtype_args[buildtype] + return ti_buildtype_args[buildtype] def get_pch_suffix(self) -> str: return 'pch' @@ -97,10 +97,27 @@ class C2000Compiler(Compiler): return [] def get_optimization_args(self, optimization_level: str) -> T.List[str]: - return c2000_optimization_args[optimization_level] + return ti_optimization_args[optimization_level] def get_debug_args(self, is_debug: bool) -> T.List[str]: - return c2000_debug_args[is_debug] + return ti_debug_args[is_debug] + + def get_compile_only_args(self) -> T.List[str]: + return [] + + def get_no_optimization_args(self) -> T.List[str]: + return ['-Ooff'] + + def get_output_args(self, target: str) -> T.List[str]: + return [f'--output_file={target}'] + + def get_werror_args(self) -> T.List[str]: + return ['--emit_warnings_as_errors'] + + def get_include_args(self, path: str, is_system: bool) -> T.List[str]: + if path == '': + path = '.' + return ['-I=' + path] @classmethod def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]: @@ -108,8 +125,6 @@ class C2000Compiler(Compiler): for i in args: if i.startswith('-D'): i = '--define=' + i[2:] - if i.startswith('-I'): - i = '--include_path=' + i[2:] if i.startswith('-Wl,-rpath='): continue elif i == '--print-search-dirs': @@ -121,8 +136,8 @@ class C2000Compiler(Compiler): def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]: for idx, i in enumerate(parameter_list): - if i[:14] == '--include_path': - parameter_list[idx] = i[:14] + os.path.normpath(os.path.join(build_dir, i[14:])) + if i[:15] == '--include_path=': + parameter_list[idx] = i[:15] + os.path.normpath(os.path.join(build_dir, i[15:])) if i[:2] == '-I': parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:])) |