Genericise TI compiler and add MSP430 support

pull/9512/merge
William Toohey 3 years ago committed by Jussi Pakkanen
parent 316cf3a717
commit b4d9b2551c
  1. 25
      cross/msp430.txt
  2. 5
      docs/markdown/Reference-tables.md
  3. 8
      docs/markdown/snippets/ti_compilers.md
  4. 4
      mesonbuild/build.py
  5. 4
      mesonbuild/compilers/__init__.py
  6. 25
      mesonbuild/compilers/c.py
  7. 21
      mesonbuild/compilers/cpp.py
  8. 46
      mesonbuild/compilers/detect.py
  9. 47
      mesonbuild/compilers/mixins/ti.py
  10. 1
      mesonbuild/envconfig.py
  11. 4
      mesonbuild/linkers/__init__.py
  12. 24
      mesonbuild/linkers/linkers.py

@ -0,0 +1,25 @@
# This file assumes that path to the Texas Instruments MSP430 toolchain is added
# to the environment(PATH) variable, so that Meson can find
# cl430 and ar430 while building.
[binaries]
c = cl430
ar = ar430
strip = strip430
[host_machine]
system = 'baremetal'
cpu_family = 'msp430'
endian = 'little'
[built-in options]
c_args = [
'-vmsp',
'--printf_support=minimal']
c_link_args = [
'--rom_model',
'-llibc.a',]
cpp_args = []
cpp_link_args = []
[properties]
needs_exe_wrapper = true

@ -9,7 +9,6 @@ These are return values of the `get_id` (Compiler family) and
| ----- | --------------- | --------------- |
| arm | ARM compiler | |
| armclang | ARMCLANG compiler | |
| c2000 | Texas Instruments C2000 compiler | |
| ccomp | The CompCert formally-verified C compiler | |
| ccrx | Renesas RX Family C/C++ compiler | |
| clang | The Clang compiler | gcc |
@ -32,6 +31,8 @@ These are return values of the `get_id` (Compiler family) and
| pgi | Portland PGI C/C++/Fortran compilers | |
| rustc | Rust compiler | |
| sun | Sun Fortran compiler | |
| c2000 | Texas Instruments C/C++ Compiler (C2000) | |
| ti | Texas Instruments C/C++ Compiler | |
| valac | Vala compiler | |
| xc16 | Microchip XC16 C compiler | |
| cython | The Cython compiler | |
@ -55,6 +56,7 @@ These are return values of the `get_linker_id` method in a compiler object.
| rlink | The Renesas linker, used with CCrx only |
| xc16-ar | The Microchip linker, used with XC16 only |
| ar2000 | The Texas Instruments linker, used with C2000 only |
| ti-ar | The Texas Instruments linker |
| armlink | The ARM linker (arm and armclang compilers) |
| pgi | Portland/Nvidia PGI |
| nvlink | Nvidia Linker used with cuda |
@ -97,6 +99,7 @@ set in the cross file.
| microblaze | MicroBlaze processor |
| mips | 32 bit MIPS processor |
| mips64 | 64 bit MIPS processor |
| msp430 | 16 bit MSP430 processor |
| parisc | HP PA-RISC processor |
| pic24 | 16 bit Microchip PIC24 |
| ppc | 32 bit PPC processors |

@ -0,0 +1,8 @@
## Added support for Texas Instruments MSP430 and ARM compilers
Meson now supports the TI [MSP430](https://www.ti.com/tool/MSP-CGT) and
[ARM](https://www.ti.com/tool/ARM-CGT) toolchains. The compiler and linker are
identified as `ti` and `ti-ar`, respectively. To maintain backwards
compatibility with existing build definitions, the [C2000
toolchain](https://www.ti.com/tool/C2000-CGT) is still identified as `c2000` and
`ar2000`.

@ -1776,8 +1776,8 @@ class Executable(BuildTarget):
self.suffix = 'abs'
elif ('c' in self.compilers and self.compilers['c'].get_id().startswith('xc16')):
self.suffix = 'elf'
elif ('c' in self.compilers and self.compilers['c'].get_id().startswith('c2000') or
'cpp' in self.compilers and self.compilers['cpp'].get_id().startswith('c2000')):
elif ('c' in self.compilers and self.compilers['c'].get_id() in ('ti', 'c2000') or
'cpp' in self.compilers and self.compilers['cpp'].get_id() in ('ti', 'c2000')):
self.suffix = 'out'
else:
self.suffix = environment.machines[for_machine].get_exe_suffix()

@ -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

@ -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'

@ -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'

@ -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):
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}')

@ -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:]))

@ -53,6 +53,7 @@ known_cpu_families = (
'microblaze',
'mips',
'mips64',
'msp430',
'parisc',
'pic24',
'ppc',

@ -31,6 +31,7 @@ from .linkers import (
Xc16Linker,
CompCertLinker,
C2000Linker,
TILinker,
AIXArLinker,
PGIStaticLinker,
NvidiaHPC_StaticLinker,
@ -48,6 +49,7 @@ from .linkers import (
Xc16DynamicLinker,
CompCertDynamicLinker,
C2000DynamicLinker,
TIDynamicLinker,
ArmDynamicLinker,
ArmClangDynamicLinker,
QualcommLLVMDynamicLinker,
@ -89,6 +91,7 @@ __all__ = [
'Xc16Linker',
'CompCertLinker',
'C2000Linker',
'TILinker',
'AIXArLinker',
'PGIStaticLinker',
'NvidiaHPC_StaticLinker',
@ -106,6 +109,7 @@ __all__ = [
'Xc16DynamicLinker',
'CompCertDynamicLinker',
'C2000DynamicLinker',
'TIDynamicLinker',
'ArmDynamicLinker',
'ArmClangDynamicLinker',
'QualcommLLVMDynamicLinker',

@ -288,11 +288,11 @@ class CompCertLinker(StaticLinker):
return [f'-o{target}']
class C2000Linker(StaticLinker):
class TILinker(StaticLinker):
def __init__(self, exelist: T.List[str]):
super().__init__(exelist)
self.id = 'ar2000'
self.id = 'ti-ar'
def can_linker_accept_rsp(self) -> bool:
return False
@ -304,6 +304,11 @@ class C2000Linker(StaticLinker):
return ['-r']
class C2000Linker(TILinker):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'ar2000'
class AIXArLinker(ArLikeLinker):
id = 'aixar'
std_args = ['-csr', '-Xany']
@ -971,15 +976,15 @@ class CompCertDynamicLinker(DynamicLinker):
install_rpath: str) -> T.Tuple[T.List[str], T.Set[bytes]]:
return ([], set())
class C2000DynamicLinker(DynamicLinker):
class TIDynamicLinker(DynamicLinker):
"""Linker for Texas Instruments C2000 compiler."""
"""Linker for Texas Instruments compiler family."""
id = 'cl2000'
id = 'ti'
def __init__(self, exelist: T.List[str], for_machine: mesonlib.MachineChoice,
*, version: str = 'unknown version'):
super().__init__(exelist or ['cl2000.exe'], for_machine, '', [],
super().__init__(exelist, for_machine, '', [],
version=version)
def get_link_whole_for(self, args: T.List[str]) -> T.List[str]:
@ -1000,7 +1005,7 @@ class C2000DynamicLinker(DynamicLinker):
return ['-z', f'--output_file={outputname}']
def get_search_args(self, dirname: str) -> 'T.NoReturn':
raise OSError('cl2000.exe does not have a search dir argument')
raise OSError('TI compilers do not have a search dir argument')
def get_allow_undefined_args(self) -> T.List[str]:
return []
@ -1009,6 +1014,11 @@ class C2000DynamicLinker(DynamicLinker):
return []
class C2000DynamicLinker(TIDynamicLinker):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'cl2000'
class ArmDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):
"""Linker for the ARM compiler."""

Loading…
Cancel
Save