summaryrefslogtreecommitdiff
path: root/test cases
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2016-12-11 14:21:30 +0200
committerGitHub <noreply@github.com>2016-12-11 14:21:30 +0200
commite128d26b350e4b8ba02e4de8858aa3deafa07ce1 (patch)
tree4d6e7f3b068e2854df0b1c888e42f087c448dae6 /test cases
parentf2b3ab826b9a8b75851853dcf972555fb7e5e2a0 (diff)
parent70f39ee21ee632d1e23b8c3cdcd11817818b9495 (diff)
downloadmeson-e128d26b350e4b8ba02e4de8858aa3deafa07ce1.tar.gz
Merge pull request #1095 from centricular/llvm-ir-assembly
Implement support for LLVM IR compilation
Diffstat (limited to 'test cases')
-rw-r--r--test cases/common/126 llvm ir and assembly/main.c9
-rw-r--r--test cases/common/126 llvm ir and assembly/main.cpp12
-rw-r--r--test cases/common/126 llvm ir and assembly/meson.build17
-rw-r--r--test cases/common/126 llvm ir and assembly/square-arm.S9
-rw-r--r--test cases/common/126 llvm ir and assembly/square-x86.S9
-rw-r--r--test cases/common/126 llvm ir and assembly/square-x86_64.S9
-rw-r--r--test cases/common/126 llvm ir and assembly/square.ll4
-rw-r--r--test cases/common/126 llvm ir and assembly/symbol-underscore.h5
-rw-r--r--test cases/common/127 cpp and asm/meson.build16
-rw-r--r--test cases/common/127 cpp and asm/retval-arm.S8
-rw-r--r--test cases/common/127 cpp and asm/retval-x86.S8
-rw-r--r--test cases/common/127 cpp and asm/retval-x86_64.S8
-rw-r--r--test cases/common/127 cpp and asm/symbol-underscore.h5
-rw-r--r--test cases/common/127 cpp and asm/trivial.cc16
14 files changed, 135 insertions, 0 deletions
diff --git a/test cases/common/126 llvm ir and assembly/main.c b/test cases/common/126 llvm ir and assembly/main.c
new file mode 100644
index 000000000..edfb29ecf
--- /dev/null
+++ b/test cases/common/126 llvm ir and assembly/main.c
@@ -0,0 +1,9 @@
+unsigned square_unsigned (unsigned a);
+
+int
+main (int argc, char * argv[])
+{
+ if (square_unsigned (2) != 4)
+ return -1;
+ return 0;
+}
diff --git a/test cases/common/126 llvm ir and assembly/main.cpp b/test cases/common/126 llvm ir and assembly/main.cpp
new file mode 100644
index 000000000..4f576e7ed
--- /dev/null
+++ b/test cases/common/126 llvm ir and assembly/main.cpp
@@ -0,0 +1,12 @@
+
+extern "C" {
+ unsigned square_unsigned (unsigned a);
+}
+
+int
+main (int argc, char * argv[])
+{
+ if (square_unsigned (2) != 4)
+ return -1;
+ return 0;
+}
diff --git a/test cases/common/126 llvm ir and assembly/meson.build b/test cases/common/126 llvm ir and assembly/meson.build
new file mode 100644
index 000000000..8b9be335a
--- /dev/null
+++ b/test cases/common/126 llvm ir and assembly/meson.build
@@ -0,0 +1,17 @@
+project('llvm-ir', 'c', 'cpp')
+
+foreach lang : ['c', 'cpp']
+ cc_id = meson.get_compiler(lang).get_id()
+ if cc_id == 'clang'
+ e = executable('square_ir_' + lang, 'square.ll', 'main.' + lang)
+ test('test IR square' + lang, e)
+ endif
+ # FIXME: msvc does not support passing assembly to cl.exe, but you can pass
+ # it to ml.exe and get a compiled object. Meson should add support for
+ # transparently building assembly with ml.exe with MSVC.
+ if cc_id != 'msvc'
+ cpu = host_machine.cpu_family()
+ e = executable('square_asm_' + lang, 'square-' + cpu + '.S', 'main.' + lang)
+ test('test ASM square' + lang, e, args : [e.full_path()])
+ endif
+endforeach
diff --git a/test cases/common/126 llvm ir and assembly/square-arm.S b/test cases/common/126 llvm ir and assembly/square-arm.S
new file mode 100644
index 000000000..58a5b1b50
--- /dev/null
+++ b/test cases/common/126 llvm ir and assembly/square-arm.S
@@ -0,0 +1,9 @@
+#include "symbol-underscore.h"
+
+.text
+.globl SYMBOL_NAME(square_unsigned)
+
+SYMBOL_NAME(square_unsigned):
+ mul r1, r0, r0
+ mov r0, r1
+ mov pc, lr
diff --git a/test cases/common/126 llvm ir and assembly/square-x86.S b/test cases/common/126 llvm ir and assembly/square-x86.S
new file mode 100644
index 000000000..f3d67e79f
--- /dev/null
+++ b/test cases/common/126 llvm ir and assembly/square-x86.S
@@ -0,0 +1,9 @@
+#include "symbol-underscore.h"
+
+.text
+.globl SYMBOL_NAME(square_unsigned)
+
+SYMBOL_NAME(square_unsigned):
+ movl 4(%esp), %eax
+ imull %eax, %eax
+ retl
diff --git a/test cases/common/126 llvm ir and assembly/square-x86_64.S b/test cases/common/126 llvm ir and assembly/square-x86_64.S
new file mode 100644
index 000000000..ea73a9dd2
--- /dev/null
+++ b/test cases/common/126 llvm ir and assembly/square-x86_64.S
@@ -0,0 +1,9 @@
+#include "symbol-underscore.h"
+
+.text
+.globl SYMBOL_NAME(square_unsigned)
+
+SYMBOL_NAME(square_unsigned):
+ imull %edi, %edi
+ movl %edi, %eax
+ retq
diff --git a/test cases/common/126 llvm ir and assembly/square.ll b/test cases/common/126 llvm ir and assembly/square.ll
new file mode 100644
index 000000000..7c321aa82
--- /dev/null
+++ b/test cases/common/126 llvm ir and assembly/square.ll
@@ -0,0 +1,4 @@
+define i32 @square_unsigned(i32 %a) {
+ %1 = mul i32 %a, %a
+ ret i32 %1
+}
diff --git a/test cases/common/126 llvm ir and assembly/symbol-underscore.h b/test cases/common/126 llvm ir and assembly/symbol-underscore.h
new file mode 100644
index 000000000..508cf50c5
--- /dev/null
+++ b/test cases/common/126 llvm ir and assembly/symbol-underscore.h
@@ -0,0 +1,5 @@
+#if defined(__WIN32__) || defined(__APPLE__)
+# define SYMBOL_NAME(name) _##name
+#else
+# define SYMBOL_NAME(name) name
+#endif
diff --git a/test cases/common/127 cpp and asm/meson.build b/test cases/common/127 cpp and asm/meson.build
new file mode 100644
index 000000000..55c3d3c6f
--- /dev/null
+++ b/test cases/common/127 cpp and asm/meson.build
@@ -0,0 +1,16 @@
+project('c++ and assembly test', 'cpp')
+
+sources = ['trivial.cc']
+# If the compiler cannot compile assembly, don't use it
+if meson.get_compiler('cpp').get_id() != 'msvc'
+ cpu = host_machine.cpu_family()
+ sources += ['retval-' + cpu + '.S']
+ cpp_args = ['-DUSE_ASM']
+ message('Using ASM')
+else
+ cpp_args = ['-DNO_USE_ASM']
+endif
+
+exe = executable('trivialprog', sources,
+ cpp_args : cpp_args)
+test('runtest', exe)
diff --git a/test cases/common/127 cpp and asm/retval-arm.S b/test cases/common/127 cpp and asm/retval-arm.S
new file mode 100644
index 000000000..8b3719765
--- /dev/null
+++ b/test cases/common/127 cpp and asm/retval-arm.S
@@ -0,0 +1,8 @@
+#include "symbol-underscore.h"
+
+.text
+.globl SYMBOL_NAME(get_retval)
+
+SYMBOL_NAME(get_retval):
+ mov r0, #0
+ mov pc, lr
diff --git a/test cases/common/127 cpp and asm/retval-x86.S b/test cases/common/127 cpp and asm/retval-x86.S
new file mode 100644
index 000000000..06bd75c28
--- /dev/null
+++ b/test cases/common/127 cpp and asm/retval-x86.S
@@ -0,0 +1,8 @@
+#include "symbol-underscore.h"
+
+.text
+.globl SYMBOL_NAME(get_retval)
+
+SYMBOL_NAME(get_retval):
+ xorl %eax, %eax
+ retl
diff --git a/test cases/common/127 cpp and asm/retval-x86_64.S b/test cases/common/127 cpp and asm/retval-x86_64.S
new file mode 100644
index 000000000..638921e3e
--- /dev/null
+++ b/test cases/common/127 cpp and asm/retval-x86_64.S
@@ -0,0 +1,8 @@
+#include "symbol-underscore.h"
+
+.text
+.globl SYMBOL_NAME(get_retval)
+
+SYMBOL_NAME(get_retval):
+ xorl %eax, %eax
+ retq
diff --git a/test cases/common/127 cpp and asm/symbol-underscore.h b/test cases/common/127 cpp and asm/symbol-underscore.h
new file mode 100644
index 000000000..508cf50c5
--- /dev/null
+++ b/test cases/common/127 cpp and asm/symbol-underscore.h
@@ -0,0 +1,5 @@
+#if defined(__WIN32__) || defined(__APPLE__)
+# define SYMBOL_NAME(name) _##name
+#else
+# define SYMBOL_NAME(name) name
+#endif
diff --git a/test cases/common/127 cpp and asm/trivial.cc b/test cases/common/127 cpp and asm/trivial.cc
new file mode 100644
index 000000000..d2928c0c9
--- /dev/null
+++ b/test cases/common/127 cpp and asm/trivial.cc
@@ -0,0 +1,16 @@
+#include<iostream>
+
+extern "C" {
+ int get_retval(void);
+}
+
+int main(int argc, char **argv) {
+ std::cout << "C++ seems to be working." << std::endl;
+#if defined(USE_ASM)
+ return get_retval();
+#elif defined(NO_USE_ASM)
+ return 0;
+#else
+ #error "Forgot to pass asm define"
+#endif
+}