Skip to content

Commit

Permalink
Added support for Texas Instruments C6000 compiler.
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Machacek committed Sep 14, 2023
1 parent bd3341f commit 678d16e
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 17 deletions.
22 changes: 22 additions & 0 deletions cross/ti-c6000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Cross file tested on Texas Instruments C6000 compiler (bare metal DSP devices)
# This file assumes that path to the Texas Instruments C6000 toolchain is added
# to the environment(PATH) variable.

[host_machine]
system = 'bare metal/tidsp'
cpu_family = 'tidsp'
cpu = 'tidsp'
endian = 'little'

[binaries]
c = 'cl6x'
cpp = 'cl6x'
ar = 'ar6x'
strip = 'strip6x'
nm = 'nm6x'
as = 'asm6x'

[properties]
needs_exe_wrapper = true
has_function_printf = true
bits = 32
3 changes: 3 additions & 0 deletions docs/markdown/Reference-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ These are return values of the `get_id` (Compiler family) and
| sun | Sun Fortran compiler | |
| c2000 | Texas Instruments C/C++ Compiler (C2000) | |
| ti | Texas Instruments C/C++ Compiler | |
| c6x | Texas Instruments C/C++ Compiler (C6000) | |
| valac | Vala compiler | |
| xc16 | Microchip XC16 C compiler | |
| cython | The Cython compiler | |
Expand Down Expand Up @@ -70,6 +71,7 @@ These are return values of the `get_linker_id` method in a compiler object.
| xc16-ar | The Microchip linker, used with XC16 only |
| ar2000 | The Texas Instruments linker, used with C2000 only |
| ti-ar | The Texas Instruments linker |
| ar6x | The Texas Instruments linker, used with C6000 only |
| armlink | The ARM linker (arm and armclang compilers) |
| pgi | Portland/Nvidia PGI |
| nvlink | Nvidia Linker used with cuda |
Expand Down Expand Up @@ -104,6 +106,7 @@ set in the cross file.
| arm | 32 bit ARM processor |
| avr | Atmel AVR processor |
| c2000 | 32 bit C2000 processor |
| tidsp | 32 bit TI DSP processor |
| csky | 32 bit CSky processor |
| dspic | 16 bit Microchip dsPIC |
| e2k | MCST Elbrus processor |
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,8 +1940,8 @@ def post_init(self) -> None:
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() in {'ti', 'c2000'} or
'cpp' in self.compilers and self.compilers['cpp'].get_id() in {'ti', 'c2000'}):
elif ('c' in self.compilers and self.compilers['c'].get_id() in {'ti', 'c2000', 'c6x'} or
'cpp' in self.compilers and self.compilers['cpp'].get_id() in {'ti', 'c2000', 'c6x'}):
self.suffix = 'out'
elif ('c' in self.compilers and self.compilers['c'].get_id() in {'mwccarm', 'mwcceppc'} or
'cpp' in self.compilers and self.compilers['cpp'].get_id() in {'mwccarm', 'mwcceppc'}):
Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,10 @@ class C2000CCompiler(TICCompiler):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'c2000'

class C6xCCompiler(TICCompiler):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'c6x'

class MetrowerksCCompilerARM(MetrowerksCompiler, CCompiler):
id = 'mwccarm'

Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/compilers/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,10 @@ class C2000CPPCompiler(TICPPCompiler):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'c2000'

class C6xCPPCompiler(TICPPCompiler):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'c6x'

class MetrowerksCPPCompilerARM(MetrowerksCompiler, CPPCompiler):
id = 'mwccarm'

Expand Down
37 changes: 22 additions & 15 deletions mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker

if any(os.path.basename(x) in {'lib', 'lib.exe', 'llvm-lib', 'llvm-lib.exe', 'xilib', 'xilib.exe'} for x in linker):
arg = '/?'
elif linker_name in {'ar2000', 'ar2000.exe', 'ar430', 'ar430.exe', 'armar', 'armar.exe'}:
elif linker_name in {'ar2000', 'ar2000.exe', 'ar430', 'ar430.exe', 'armar', 'armar.exe', 'ar6x', 'ar6x.exe'}:
arg = '?'
else:
arg = '--version'
Expand Down Expand Up @@ -237,6 +237,8 @@ def detect_static_linker(env: 'Environment', compiler: Compiler) -> StaticLinker
if 'Texas Instruments Incorporated' in out:
if 'ar2000' in linker_name:
return linkers.C2000Linker(linker)
elif 'ar6x' in linker_name:
return linkers.C6xLinker(linker)
else:
return linkers.TILinker(linker)
if out.startswith('The CompCert'):
Expand Down Expand Up @@ -316,7 +318,7 @@ def sanitize(p: str) -> str:
arg = '--version'
elif 'ccomp' in compiler_name:
arg = '-version'
elif compiler_name in {'cl2000', 'cl2000.exe', 'cl430', 'cl430.exe', 'armcl', 'armcl.exe'}:
elif compiler_name in {'cl2000', 'cl2000.exe', 'cl430', 'cl430.exe', 'armcl', 'armcl.exe', 'cl6x', 'cl6x.exe'}:
# TI compiler
arg = '-version'
elif compiler_name in {'icl', 'icl.exe'}:
Expand Down Expand Up @@ -436,6 +438,24 @@ def sanitize(p: str) -> str:
return cls(
compiler, version, for_machine, is_cross, info, target,
exe_wrap, linker=linker)

# must be detected here before clang because TI compilers contain 'clang' in their output and so that they can be detected as 'clang'
ti_compilers = {
'TMS320C2000 C/C++': (c.C2000CCompiler, cpp.C2000CPPCompiler, linkers.C2000DynamicLinker),
'TMS320C6x C/C++': (c.C6xCCompiler, cpp.C6xCPPCompiler, linkers.C6xDynamicLinker),
'TI ARM C/C++ Compiler': (c.TICCompiler, cpp.TICPPCompiler, linkers.TIDynamicLinker),
'MSP430 C/C++': (c.TICCompiler, cpp.TICPPCompiler, linkers.TIDynamicLinker)
}
for indentifier, compiler_classes in ti_compilers.items():
if indentifier in out:
cls = compiler_classes[0] if lang == 'c' else compiler_classes[1]
lnk = compiler_classes[2]
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 'clang' in out or 'Clang' in out:
linker = None

Expand Down Expand Up @@ -533,19 +553,6 @@ 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:
if 'TMS320C2000 C/C++' in out:
cls = c.C2000CCompiler if lang == 'c' else cpp.C2000CPPCompiler
lnk = linkers.C2000DynamicLinker
else:
cls = c.TICCompiler if lang == 'c' else cpp.TICPPCompiler
lnk = linkers.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 and not ('Metrowerks' in out or 'Freescale' in out):
cls = c.ArmCCompiler if lang == 'c' else cpp.ArmCPPCompiler
env.coredata.add_lang_args(cls.language, cls, for_machine, env)
Expand Down
4 changes: 4 additions & 0 deletions mesonbuild/compilers/mixins/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,10 @@ def get_library_naming(self, env: 'Environment', libtype: LibType, strict: bool
elif env.machines[self.for_machine].is_cygwin():
shlibext = ['dll', 'dll.a']
prefixes = ['cyg'] + prefixes
elif env.machines[self.for_machine].is_baremetal():
# bare metal like TI C6000 can have both extensions for static or dynamic libs.
stlibext = ['a', 'lib']
shlibext = ['dll', 'so']
else:
# Linux/BSDs
shlibext = ['so']
Expand Down
5 changes: 5 additions & 0 deletions mesonbuild/envconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'arm',
'avr',
'c2000',
'tidsp',
'csky',
'dspic',
'e2k',
Expand Down Expand Up @@ -373,6 +374,10 @@ def is_irix(self) -> bool:
"""Machine is IRIX?"""
return self.system.startswith('irix')

def is_baremetal(self) -> bool:
"""Machine is bare metal?"""
return self.system.startswith('bare metal')

# Various prefixes and suffixes for import libraries, shared libraries,
# static libraries, and executables.
# Versioning is added to these names in the backends as-needed.
Expand Down
8 changes: 8 additions & 0 deletions mesonbuild/linkers/linkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ class C2000Linker(TILinker):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'ar2000'

class C6xLinker(TILinker):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'ar6x'


class AIXArLinker(ArLikeLinker, StaticLinker):
id = 'aixar'
Expand Down Expand Up @@ -1099,6 +1103,10 @@ class C2000DynamicLinker(TIDynamicLinker):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'cl2000'

class C6xDynamicLinker(TIDynamicLinker):
# Required for backwards compat with projects created before ti-cgt support existed
id = 'cl6x'


class ArmDynamicLinker(PosixDynamicLinkerMixin, DynamicLinker):

Expand Down

0 comments on commit 678d16e

Please sign in to comment.