diff options
author | alanNz <alangrimmer@gmail.com> | 2020-03-21 09:13:42 +1300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2020-03-21 00:47:24 +0200 |
commit | 74602928100394f6129e064f8e0bfe6c9e08c9d2 (patch) | |
tree | e3ae62b782a91ade9d68210a52cea35f18211d8e /mesonbuild/compilers | |
parent | 24227a95531b21a04bf2514a5b8f61ae29d47043 (diff) | |
download | meson-74602928100394f6129e064f8e0bfe6c9e08c9d2.zip meson-74602928100394f6129e064f8e0bfe6c9e08c9d2.tar.gz meson-74602928100394f6129e064f8e0bfe6c9e08c9d2.tar.bz2 |
-Add xc16 and c2000 C,Cpp toolchain support
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r-- | mesonbuild/compilers/__init__.py | 6 | ||||
-rw-r--r-- | mesonbuild/compilers/c.py | 91 | ||||
-rw-r--r-- | mesonbuild/compilers/cpp.py | 33 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/c2000.py | 120 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/xc16.py | 123 |
5 files changed, 373 insertions, 0 deletions
diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index a4e3943..05c75dd 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -91,6 +91,9 @@ __all__ = [ 'RustCompiler', 'CcrxCCompiler', 'CcrxCPPCompiler', + 'Xc16CCompiler', + 'C2000CCompiler', + 'C2000CPPCompiler', 'SunFortranCompiler', 'SwiftCompiler', 'ValaCompiler', @@ -135,6 +138,8 @@ from .c import ( IntelClCCompiler, PGICCompiler, CcrxCCompiler, + Xc16CCompiler, + C2000CCompiler, VisualStudioCCompiler, ) from .cpp import ( @@ -151,6 +156,7 @@ from .cpp import ( IntelClCPPCompiler, PGICPPCompiler, CcrxCPPCompiler, + C2000CPPCompiler, VisualStudioCPPCompiler, ) from .cs import MonoCompiler, VisualStudioCsCompiler diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index f98316b..82640be 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -20,6 +20,8 @@ from ..mesonlib import MachineChoice, MesonException, mlog, version_compare from .c_function_attributes import C_FUNC_ATTRIBUTES from .mixins.clike import CLikeCompiler from .mixins.ccrx import CcrxCompiler +from .mixins.xc16 import Xc16Compiler +from .mixins.c2000 import C2000Compiler from .mixins.arm import ArmCompiler, ArmclangCompiler from .mixins.visualstudio import MSVCCompiler, ClangClCompiler from .mixins.gnu import GnuCompiler @@ -424,3 +426,92 @@ class CcrxCCompiler(CcrxCompiler, CCompiler): if path == '': path = '.' return ['-include=' + path] + + +class Xc16CCompiler(Xc16Compiler, CCompiler): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + Xc16Compiler.__init__(self) + + def get_options(self): + opts = CCompiler.get_options(self) + opts.update({'c_std': coredata.UserComboOption('C language standard to use', + ['none', 'c89', 'c99', 'gnu89', 'gnu99'], + 'none')}) + return opts + + def get_no_stdinc_args(self): + return [] + + def get_option_compile_args(self, options): + args = [] + std = options['c_std'] + if std.value != 'none': + args.append('-ansi') + args.append('-std=' + std.value) + return args + + def get_compile_only_args(self): + return [] + + def get_no_optimization_args(self): + return ['-O0'] + + def get_output_args(self, target): + return ['-o%s' % target] + + def get_werror_args(self): + return ['-change_message=error'] + + def get_include_args(self, path, is_system): + if path == '': + path = '.' + return ['-I' + path] + + +class C2000CCompiler(C2000Compiler, CCompiler): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + C2000Compiler.__init__(self) + + # Override CCompiler.get_always_args + def get_always_args(self): + return [] + + def get_options(self): + opts = CCompiler.get_options(self) + opts.update({'c_std': coredata.UserComboOption('C language standard to use', + ['none', 'c89', 'c99', 'c11'], + 'none')}) + return opts + + def get_no_stdinc_args(self): + return [] + + def get_option_compile_args(self, options): + args = [] + std = options['c_std'] + if std.value != 'none': + args.append('--' + std.value) + return args + + def get_compile_only_args(self): + return [] + + def get_no_optimization_args(self): + return ['-Ooff'] + + def get_output_args(self, target): + return ['--output_file=%s' % target] + + def get_werror_args(self): + return ['-change_message=error'] + + def get_include_args(self, path, is_system): + if path == '': + path = '.' + return ['--include_path=' + path] diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 2470bd5..ac0500a 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -29,6 +29,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.arm import ArmCompiler, ArmclangCompiler from .mixins.visualstudio import MSVCCompiler, ClangClCompiler from .mixins.gnu import GnuCompiler @@ -633,3 +634,35 @@ class CcrxCPPCompiler(CcrxCompiler, CPPCompiler): def get_compiler_check_args(self): return [] + +class C2000CPPCompiler(C2000Compiler, CPPCompiler): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap=None, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) + C2000Compiler.__init__(self) + + def get_options(self): + opts = CPPCompiler.get_options(self) + opts.update({'cpp_std': coredata.UserComboOption('C++ language standard to use', + ['none', 'c++03'], + 'none')}) + return opts + + def get_always_args(self): + return ['-nologo', '-lang=cpp'] + + def get_option_compile_args(self, options): + return [] + + def get_compile_only_args(self): + return [] + + def get_output_args(self, target): + return ['-output=obj=%s' % target] + + def get_option_link_args(self, options): + return [] + + def get_compiler_check_args(self): + return [] diff --git a/mesonbuild/compilers/mixins/c2000.py b/mesonbuild/compilers/mixins/c2000.py new file mode 100644 index 0000000..65a2cea --- /dev/null +++ b/mesonbuild/compilers/mixins/c2000.py @@ -0,0 +1,120 @@ +# Copyright 2012-2019 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Representations specific to the Texas Instruments C2000 compiler family.""" + +import os +import typing as T + +from ...mesonlib import EnvironmentException + +if T.TYPE_CHECKING: + from ...environment import Environment + +c2000_buildtype_args = { + 'plain': [], + 'debug': [], + 'debugoptimized': [], + 'release': [], + 'minsize': [], + 'custom': [], +} # type: T.Dict[str, T.List[str]] + +c2000_optimization_args = { + '0': ['-O0'], + 'g': ['-Ooff'], + '1': ['-O1'], + '2': ['-O2'], + '3': ['-O3'], + 's': ['-04'] +} # type: T.Dict[str, T.List[str]] + +c2000_debug_args = { + False: [], + True: [] +} # type: T.Dict[bool, T.List[str]] + + +class C2000Compiler: + def __init__(self): + if not self.is_cross: + raise EnvironmentException('c2000 supports only cross-compilation.') + self.id = 'c2000' + # Assembly + self.can_compile_suffixes.add('asm') + default_warn_args = [] # type: T.List[str] + self.warn_args = {'0': [], + '1': default_warn_args, + '2': default_warn_args + [], + '3': default_warn_args + []} + + def get_pic_args(self) -> T.List[str]: + # PIC support is not enabled by default for c2000, + # 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] + + def get_pch_suffix(self) -> str: + return 'pch' + + def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: + return [] + + # Override CCompiler.get_dependency_gen_args + def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: + return [] + + def thread_flags(self, env: 'Environment') -> T.List[str]: + return [] + + def get_coverage_args(self) -> T.List[str]: + return [] + + def get_no_stdinc_args(self) -> T.List[str]: + return [] + + def get_no_stdlib_link_args(self) -> T.List[str]: + return [] + + def get_optimization_args(self, optimization_level: str) -> T.List[str]: + return c2000_optimization_args[optimization_level] + + def get_debug_args(self, is_debug: bool) -> T.List[str]: + return c2000_debug_args[is_debug] + + @classmethod + def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]: + result = [] + for i in args: + if i.startswith('-D'): + i = '-define=' + i[2:] + if i.startswith('-I'): + i = '-include=' + i[2:] + if i.startswith('-Wl,-rpath='): + continue + elif i == '--print-search-dirs': + continue + elif i.startswith('-L'): + continue + result.append(i) + return result + + 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[:9] == '-include=': + parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:])) + + return parameter_list diff --git a/mesonbuild/compilers/mixins/xc16.py b/mesonbuild/compilers/mixins/xc16.py new file mode 100644 index 0000000..f12cccc --- /dev/null +++ b/mesonbuild/compilers/mixins/xc16.py @@ -0,0 +1,123 @@ +# Copyright 2012-2019 The Meson development team + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Representations specific to the Microchip XC16 C compiler family.""" + +import os +import typing as T + +from ...mesonlib import EnvironmentException + +if T.TYPE_CHECKING: + from ...environment import Environment + +xc16_buildtype_args = { + 'plain': [], + 'debug': [], + 'debugoptimized': [], + 'release': [], + 'minsize': [], + 'custom': [], +} # type: T.Dict[str, T.List[str]] + +xc16_optimization_args = { + '0': ['-O0'], + 'g': ['-O0'], + '1': ['-O1'], + '2': ['-O2'], + '3': ['-O3'], + 's': ['-Os'] +} # type: T.Dict[str, T.List[str]] + +xc16_debug_args = { + False: [], + True: [] +} # type: T.Dict[bool, T.List[str]] + + +class Xc16Compiler: + def __init__(self): + if not self.is_cross: + raise EnvironmentException('xc16 supports only cross-compilation.') + self.id = 'xc16' + # Assembly + self.can_compile_suffixes.add('s') + default_warn_args = [] # type: T.List[str] + self.warn_args = {'0': [], + '1': default_warn_args, + '2': default_warn_args + [], + '3': default_warn_args + []} + + def get_always_args(self) -> T.List[str]: + return [] + + def get_pic_args(self) -> T.List[str]: + # PIC support is not enabled by default for xc16, + # 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 xc16_buildtype_args[buildtype] + + def get_pch_suffix(self) -> str: + return 'pch' + + def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]: + return [] + + # Override CCompiler.get_dependency_gen_args + def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: + return [] + + def thread_flags(self, env: 'Environment') -> T.List[str]: + return [] + + def get_coverage_args(self) -> T.List[str]: + return [] + + def get_no_stdinc_args(self) -> T.List[str]: + return ['-nostdinc'] + + def get_no_stdlib_link_args(self) -> T.List[str]: + return ['--nostdlib'] + + def get_optimization_args(self, optimization_level: str) -> T.List[str]: + return xc16_optimization_args[optimization_level] + + def get_debug_args(self, is_debug: bool) -> T.List[str]: + return xc16_debug_args[is_debug] + + @classmethod + def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]: + result = [] + for i in args: + if i.startswith('-D'): + i = '-D' + i[2:] + if i.startswith('-I'): + i = '-I' + i[2:] + if i.startswith('-Wl,-rpath='): + continue + elif i == '--print-search-dirs': + continue + elif i.startswith('-L'): + continue + result.append(i) + return result + + 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[:9] == '-I': + parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:])) + + return parameter_list |