From 04c1909a4dcc4f92c845eabab5515419f0881dc5 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 23 Nov 2016 21:35:52 +0530 Subject: compilers: Implement support for LLVM IR compilation Also C++ compilers can build .S assembly files. This wasn't noticed earlier because most people were also using C compilers in their C++ projects and we would fall back to using the C compiler for building the assembly files. Now we have a test for this. This was trivial to add; except that we needed a new LLVM IR rule because the compiler emits warnings if you pass any special arguments to it such as include arguments or dependency arguments. Closes #1089 --- mesonbuild/compilers.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'mesonbuild/compilers.py') diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 2ee4aac..08ebbfb 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -59,6 +59,11 @@ def is_source(fname): suffix = fname.split('.')[-1] return suffix in clike_suffixes +def is_llvm_ir(fname): + if hasattr(fname, 'fname'): + fname = fname.fname + return fname.split('.')[-1] == 'll' + def is_object(fname): if hasattr(fname, 'fname'): fname = fname.fname @@ -2018,6 +2023,8 @@ class GnuCompiler: if self.gcc_type != GCC_OSX: self.base_options.append('b_lundef') self.base_options.append('b_asneeded') + # All GCC backends can do assembly + self.can_compile_suffixes.add('s') def get_colorout_args(self, colortype): if mesonlib.version_compare(self.version, '>=4.9.0'): @@ -2071,8 +2078,6 @@ class GnuCCompiler(GnuCompiler, CCompiler): def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None): CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) GnuCompiler.__init__(self, gcc_type, defines) - # Gcc can do asm, too. - self.can_compile_suffixes.add('s') self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} @@ -2185,6 +2190,8 @@ class ClangCompiler(): if self.clang_type != CLANG_OSX: self.base_options.append('b_lundef') self.base_options.append('b_asneeded') + # All Clang backends can do assembly and LLVM IR + self.can_compile_suffixes.update(['ll', 's']) def get_pic_args(self): if self.clang_type in (CLANG_WIN, CLANG_OSX): @@ -2240,8 +2247,6 @@ class ClangCCompiler(ClangCompiler, CCompiler): def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None): CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper) ClangCompiler.__init__(self, clang_type) - # Clang can do asm, too. - self.can_compile_suffixes.add('s') self.warn_args = {'1': ['-Wall', '-Winvalid-pch'], '2': ['-Wall', '-Wextra', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} -- cgit v1.1 From 70f39ee21ee632d1e23b8c3cdcd11817818b9495 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 23 Nov 2016 23:16:46 +0530 Subject: unity builds: Assembly and LLVM IR are incompatible Can't just #include them and use them directly in unity builds. Inline assembly is a thing, but it's not trivial and is deprecated with some compilers. Just build them separately and link them in. Ideally the user would then use LTO to ensure the same result. --- mesonbuild/compilers.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mesonbuild/compilers.py') diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 08ebbfb..e474d2e 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -59,6 +59,11 @@ def is_source(fname): suffix = fname.split('.')[-1] return suffix in clike_suffixes +def is_assembly(fname): + if hasattr(fname, 'fname'): + fname = fname.fname + return fname.split('.')[-1].lower() == 's' + def is_llvm_ir(fname): if hasattr(fname, 'fname'): fname = fname.fname -- cgit v1.1