Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Linear ASM compiler #13989

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions docs/markdown/Reference-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,23 @@ Meson natively.
These are the parameter names for passing language specific arguments
to your build target.

| Language | compiler name | linker name |
| ------------- | ------------- | ----------------- |
| C | c_args | c_link_args |
| C++ | cpp_args | cpp_link_args |
| C# | cs_args | cs_link_args |
| CUDA | cuda_args | cuda_link_args |
| D | d_args | d_link_args |
| Fortran | fortran_args | fortran_link_args |
| Java | java_args | java_link_args |
| Objective C | objc_args | objc_link_args |
| Objective C++ | objcpp_args | objcpp_link_args |
| Rust | rust_args | rust_link_args |
| Vala | vala_args | vala_link_args |
| Cython | cython_args | cython_link_args |
| NASM | nasm_args | N/A |
| MASM | masm_args | N/A |
| Language | compiler name | linker name |
| ------------- | -------------- | ----------------- |
| C | c_args | c_link_args |
| C++ | cpp_args | cpp_link_args |
| C# | cs_args | cs_link_args |
| CUDA | cuda_args | cuda_link_args |
| D | d_args | d_link_args |
| Fortran | fortran_args | fortran_link_args |
| Java | java_args | java_link_args |
| Objective C | objc_args | objc_link_args |
| Objective C++ | objcpp_args | objcpp_link_args |
| Rust | rust_args | rust_link_args |
| Vala | vala_args | vala_link_args |
| Cython | cython_args | cython_link_args |
| NASM | nasm_args | N/A |
| MASM | masm_args | N/A |
| Linear ASM | linearasm_args | N/A |

All these `<lang>_*` options are specified per machine. See in
[specifying options per
Expand Down
3 changes: 3 additions & 0 deletions docs/markdown/snippets/linearasm_features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Add new language Linear Asm

TI C6000 compiler supports a dialect of TI asm, so we add a new language for it.
29 changes: 29 additions & 0 deletions mesonbuild/compilers/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..options import OptionKey
from .compilers import Compiler
from .mixins.metrowerks import MetrowerksCompiler, mwasmarm_instruction_set_args, mwasmeppc_instruction_set_args
from .mixins.ti import TICompiler

if T.TYPE_CHECKING:
from ..environment import Environment
Expand Down Expand Up @@ -259,6 +260,34 @@ def depfile_for_object(self, objfile: str) -> T.Optional[str]:
return None


# https://downloads.ti.com/docs/esd/SPRUI04/
class TILinearAsmCompiler(TICompiler, Compiler):
language = 'linearasm'

def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
for_machine: 'MachineChoice', info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None,
Comment on lines +268 to +269
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid quoting type annotations in newly introduced code. It is an older style and unnecessary since we now require a minimum python >=3.7 and started using from __future__ import annotations.

full_version: T.Optional[str] = None, is_cross: bool = False):
Compiler.__init__(self, ccache, exelist, version, for_machine, info, linker, full_version, is_cross)
TICompiler.__init__(self)

def needs_static_linker(self) -> bool:
return True

def get_always_args(self) -> T.List[str]:
return []

def get_crt_compile_args(self, crt_val: str, buildtype: str) -> T.List[str]:
return []

def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

if self.info.cpu_family not in {'c6000'}:
raise EnvironmentException(f'TI Linear ASM compiler {self.id!r} does not support {self.info.cpu_family} CPU family')

def get_depfile_suffix(self) -> str:
return 'd'


class MetrowerksAsmCompiler(MetrowerksCompiler, Compiler):
language = 'nasm'

Expand Down
1 change: 1 addition & 0 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
'cython': ('pyx', ),
'nasm': ('asm', 'nasm',),
'masm': ('masm',),
'linearasm': ('sa',),
}
all_languages = lang_suffixes.keys()
c_cpp_suffixes = {'h'}
Expand Down
21 changes: 21 additions & 0 deletions mesonbuild/compilers/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def compiler_from_language(env: 'Environment', lang: str, for_machine: MachineCh
'cython': detect_cython_compiler,
'nasm': detect_nasm_compiler,
'masm': detect_masm_compiler,
'linearasm': detect_linearasm_compiler,
}
return lang_map[lang](env, for_machine) if lang in lang_map else None

Expand Down Expand Up @@ -1353,6 +1354,26 @@ def detect_masm_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
_handle_exceptions(popen_exceptions, [comp])
raise EnvironmentException('Unreachable code (exception to make mypy happy)')

def detect_linearasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

from .asm import TILinearAsmCompiler
comp = ['cl6x']
comp_class: T.Type[Compiler] = TILinearAsmCompiler
arg = '-h'
info = env.machines[for_machine]
cc = detect_c_compiler(env, for_machine)
is_cross = env.is_cross_build(for_machine)

popen_exceptions: T.Dict[str, Exception] = {}
try:
output = Popen_safe(comp + [arg])[2]
Comment on lines +1359 to +1368
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are hardcoding the compiler as cl6x instead of looking it up via the machine info. This seems suboptimal...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, it looks like masm handling already does that too. @dcbaker what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh... We need to fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to fix that?

version = search_version(output)
env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env)
return comp_class([], comp, version, for_machine, info, cc.linker, is_cross=is_cross)
except OSError as e:
popen_exceptions[' '.join(comp + [arg])] = e
_handle_exceptions(popen_exceptions, [comp])
raise EnvironmentException('Unreachable code (exception to make mypy happy)')

# GNU/Clang defines and version
# =============================

Expand Down
Loading