Skip to content

Commit

Permalink
Add Linear ASM compiler
Browse files Browse the repository at this point in the history
Fix #13670
  • Loading branch information
Freed-Wu committed Dec 9, 2024
1 parent 83253cd commit 5ec86ca
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 16 deletions.
34 changes: 18 additions & 16 deletions docs/markdown/Reference-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ These are return values of the `get_id` (Compiler family) and
| armasm | Microsoft Macro Assembler for ARM and AARCH64 (Since 0.64.0) | |
| mwasmarm | Metrowerks Assembler for Embedded ARM | |
| mwasmeppc | Metrowerks Assembler for Embedded PowerPC | |
| cl6x | Texas Instruments linear assembler | |

## Linker ids

Expand Down Expand Up @@ -213,22 +214,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
46 changes: 46 additions & 0 deletions mesonbuild/compilers/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,52 @@ def depfile_for_object(self, objfile: str) -> T.Optional[str]:
return None


class LinearAsmCompiler(Compiler):
language = 'linearasm'
id = 'cl6x'

def needs_static_linker(self) -> bool:
return True

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

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

def get_output_args(self, outputname: str) -> T.List[str]:
return ['--output_file=', outputname]

def get_optimization_args(self, optimization_level: str) -> T.List[str]:
return []

def get_debug_args(self, is_debug: bool) -> T.List[str]:
if is_debug:
return ['-g']
return []

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

def get_include_args(self, path: str, is_system: bool) -> T.List[str]:
if not path:
path = '.'
return ['-I=' + path]

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[:2] == '-I':
parameter_list[idx] = i[:2] + os.path.normpath(os.path.join(build_dir, i[2:]))
return parameter_list

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

def depfile_for_object(self, objfile: str) -> T.Optional[str]:
return None


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
18 changes: 18 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,23 @@ 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:
from .asm import LinearAsmCompiler
comp = ['cl6x']
comp_class: T.Type[Compiler] = LinearAsmCompiler
arg = '-h'

popen_exceptions: T.Dict[str, Exception] = {}
try:
output = Popen_safe(comp + [arg])[2]
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

0 comments on commit 5ec86ca

Please sign in to comment.