Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
Genericise TI compiler and add MSP430 support
Browse files Browse the repository at this point in the history
  • Loading branch information
William Toohey authored and jpakkane committed Feb 2, 2022
1 parent 316cf3a commit b4d9b25
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 72 deletions.
25 changes: 25 additions & 0 deletions cross/msp430.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion docs/markdown/Reference-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 | |
Expand All @@ -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 |
Expand Down Expand Up @@ -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 |
Expand Down
8 changes: 8 additions & 0 deletions docs/markdown/snippets/ti_compilers.md
Original file line number Diff line number Diff line change
@@ -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`.
4 changes: 2 additions & 2 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1776,8 +1776,8 @@ def __init__(self, name: str, subdir: str, subproject: str, for_machine: Machine
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()
Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/compilers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
'CompCertCCompiler',
'C2000CCompiler',
'C2000CPPCompiler',
'TICCompiler',
'TICPPCompiler',
'SunFortranCompiler',
'SwiftCompiler',
'ValaCompiler',
Expand Down Expand Up @@ -188,6 +190,7 @@
Xc16CCompiler,
CompCertCCompiler,
C2000CCompiler,
TICCompiler,
VisualStudioCCompiler,
)
from .cpp import (
Expand All @@ -206,6 +209,7 @@
PGICPPCompiler,
CcrxCPPCompiler,
C2000CPPCompiler,
TICPPCompiler,
VisualStudioCPPCompiler,
)
from .cs import MonoCompiler, VisualStudioCsCompiler
Expand Down
25 changes: 6 additions & 19 deletions mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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
Expand Down Expand Up @@ -685,15 +685,15 @@ def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
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,
linker: T.Optional['DynamicLinker'] = None,
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]:
Expand All @@ -716,19 +716,6 @@ def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]
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'
21 changes: 10 additions & 11 deletions mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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
Expand Down Expand Up @@ -839,14 +839,14 @@ def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
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)
Expand All @@ -862,13 +862,12 @@ def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]
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'
48 changes: 32 additions & 16 deletions mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
CompCertDynamicLinker,
C2000Linker,
C2000DynamicLinker,
TILinker,
TIDynamicLinker,
DLinker,
NAGDynamicLinker,
NvidiaHPC_DynamicLinker,
Expand Down Expand Up @@ -68,6 +70,7 @@
Xc16CCompiler,
CompCertCCompiler,
C2000CCompiler,
TICCompiler,
VisualStudioCCompiler,
)
from .cpp import (
Expand All @@ -87,6 +90,7 @@
PGICPPCompiler,
CcrxCPPCompiler,
C2000CPPCompiler,
TICPPCompiler,
VisualStudioCPPCompiler,
)
from .cs import MonoCompiler, VisualStudioCsCompiler
Expand Down Expand Up @@ -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'
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -397,7 +406,8 @@ def sanitize(p: str) -> str:
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
Expand Down Expand Up @@ -602,6 +612,20 @@ def sanitize(p: str) -> str:
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)
Expand Down Expand Up @@ -633,14 +657,6 @@ def sanitize(p: str) -> str:
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}')

Expand Down
Loading

0 comments on commit b4d9b25

Please sign in to comment.