summaryrefslogtreecommitdiffstats
path: root/test cases/common/127 generated assembly
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test cases/common/127 generated assembly/copyfile.py6
-rw-r--r--test cases/common/127 generated assembly/empty.c0
-rw-r--r--test cases/common/127 generated assembly/main.c16
-rw-r--r--test cases/common/127 generated assembly/meson.build66
-rw-r--r--test cases/common/127 generated assembly/square-arm.S.in13
-rw-r--r--test cases/common/127 generated assembly/square-x86.S.in34
-rw-r--r--test cases/common/127 generated assembly/square-x86_64.S.in38
-rw-r--r--test cases/common/127 generated assembly/square.def2
-rw-r--r--test cases/common/127 generated assembly/symbol-underscore.h5
9 files changed, 180 insertions, 0 deletions
diff --git a/test cases/common/127 generated assembly/copyfile.py b/test cases/common/127 generated assembly/copyfile.py
new file mode 100644
index 0000000..ff42ac3
--- /dev/null
+++ b/test cases/common/127 generated assembly/copyfile.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python3
+
+import sys
+import shutil
+
+shutil.copyfile(sys.argv[1], sys.argv[2])
diff --git a/test cases/common/127 generated assembly/empty.c b/test cases/common/127 generated assembly/empty.c
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test cases/common/127 generated assembly/empty.c
diff --git a/test cases/common/127 generated assembly/main.c b/test cases/common/127 generated assembly/main.c
new file mode 100644
index 0000000..fb38f9d
--- /dev/null
+++ b/test cases/common/127 generated assembly/main.c
@@ -0,0 +1,16 @@
+#include <stdio.h>
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+ __declspec(dllimport)
+#endif
+unsigned square_unsigned (unsigned a);
+
+int main(void)
+{
+ unsigned int ret = square_unsigned (2);
+ if (ret != 4) {
+ printf("Got %u instead of 4\n", ret);
+ return 1;
+ }
+ return 0;
+}
diff --git a/test cases/common/127 generated assembly/meson.build b/test cases/common/127 generated assembly/meson.build
new file mode 100644
index 0000000..31a5f17
--- /dev/null
+++ b/test cases/common/127 generated assembly/meson.build
@@ -0,0 +1,66 @@
+project('generated assembly', 'c')
+
+cc = meson.get_compiler('c')
+
+if ['msvc', 'intel-cl'].contains(cc.get_id())
+ error('MESON_SKIP_TEST: assembly files cannot be compiled directly by the compiler')
+endif
+
+if meson.backend() == 'xcode'
+ error('MESON_SKIP_TEST: asm not supported with the Xcode backend. Patches welcome.')
+endif
+
+
+crt_workaround = []
+if cc.get_linker_id() == 'lld-link'
+ # It seems that when building without a .c file, lld-link.exe
+ # misses the fact that it needs to include the c runtime to
+ # make a working .dll. So here we add an empty .c file to easily
+ # pull in crt.
+ crt_workaround += 'empty.c'
+ if host_machine.cpu_family() == 'x86'
+ # x86 assembly needs manual annotation to be compatible with
+ # Safe Exception Handlers (?) This assembly doesn't have such
+ # annotation, so just disable the feature.
+ add_project_link_arguments('/SAFESEH:NO', language : 'c')
+ endif
+endif
+
+cpu = host_machine.cpu_family()
+supported_cpus = ['arm', 'x86', 'x86_64']
+
+if not supported_cpus.contains(cpu)
+ error('MESON_SKIP_TEST: unsupported cpu family: ' + cpu)
+endif
+
+if cc.get_id() == 'clang-cl' and cc.version().version_compare('< 12.0.0') and cpu == 'arm'
+ # https://reviews.llvm.org/D89622
+ error('MESON_SKIP_TEST: arm debug symbols not supported in clang-cl < 12.0.0')
+endif
+
+if cc.symbols_have_underscore_prefix()
+ add_project_arguments('-DMESON_TEST__UNDERSCORE_SYMBOL', language : 'c')
+endif
+
+copy = find_program('copyfile.py')
+output = 'square-@0@.S'.format(cpu)
+input = output + '.in'
+
+copygen = generator(copy,
+ arguments : ['@INPUT@', '@OUTPUT@'],
+ output : '@BASENAME@')
+
+l = library('square-gen', crt_workaround + [copygen.process(input)],
+ vs_module_defs: 'square.def')
+
+test('square-gen-test', executable('square-gen-test', 'main.c', link_with : l))
+
+copyct = custom_target('square',
+ input : input,
+ output : output,
+ command : [copy, '@INPUT@', '@OUTPUT@'])
+
+l = library('square-ct', crt_workaround + [copyct],
+ vs_module_defs: 'square.def')
+
+test('square-ct-test', executable('square-ct-test', 'main.c', link_with : l))
diff --git a/test cases/common/127 generated assembly/square-arm.S.in b/test cases/common/127 generated assembly/square-arm.S.in
new file mode 100644
index 0000000..d2fb7ac
--- /dev/null
+++ b/test cases/common/127 generated assembly/square-arm.S.in
@@ -0,0 +1,13 @@
+#include "symbol-underscore.h"
+
+.text
+.globl SYMBOL_NAME(square_unsigned)
+/* Only supported with GAS */
+# if defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
+.type square_unsigned,%function
+#endif
+
+SYMBOL_NAME(square_unsigned):
+ mul r1, r0, r0
+ mov r0, r1
+ mov pc, lr
diff --git a/test cases/common/127 generated assembly/square-x86.S.in b/test cases/common/127 generated assembly/square-x86.S.in
new file mode 100644
index 0000000..1a48fc4
--- /dev/null
+++ b/test cases/common/127 generated assembly/square-x86.S.in
@@ -0,0 +1,34 @@
+#include "symbol-underscore.h"
+
+#if defined(_MSC_VER) && !defined(__clang__)
+
+.386
+.MODEL FLAT, C
+
+PUBLIC square_unsigned
+_TEXT SEGMENT
+
+square_unsigned PROC var1:DWORD
+ mov eax, var1
+ imul eax, eax
+ ret
+square_unsigned ENDP
+
+_TEXT ENDS
+END
+
+#else
+
+.text
+.globl SYMBOL_NAME(square_unsigned)
+/* Only supported with GAS */
+# if defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
+.type square_unsigned,@function
+# endif
+
+SYMBOL_NAME(square_unsigned):
+ movl 4(%esp), %eax
+ imull %eax, %eax
+ retl
+
+#endif
diff --git a/test cases/common/127 generated assembly/square-x86_64.S.in b/test cases/common/127 generated assembly/square-x86_64.S.in
new file mode 100644
index 0000000..d504341
--- /dev/null
+++ b/test cases/common/127 generated assembly/square-x86_64.S.in
@@ -0,0 +1,38 @@
+#include "symbol-underscore.h"
+
+#if defined(_MSC_VER) && !defined(__clang__) /* MSVC on Windows */
+
+PUBLIC SYMBOL_NAME(square_unsigned)
+_TEXT SEGMENT
+
+SYMBOL_NAME(square_unsigned) PROC
+ mov eax, ecx
+ imul eax, eax
+ ret
+SYMBOL_NAME(square_unsigned) ENDP
+
+_TEXT ENDS
+END
+
+#else
+
+.text
+.globl SYMBOL_NAME(square_unsigned)
+/* Only supported with GAS */
+# if defined(__linux__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__sun)
+.type square_unsigned,@function
+# endif
+
+# if defined(_WIN32) || defined(__CYGWIN__) /* msabi */
+SYMBOL_NAME(square_unsigned):
+ imull %ecx, %ecx
+ movl %ecx, %eax
+ retq
+# else /* sysvabi */
+SYMBOL_NAME(square_unsigned):
+ imull %edi, %edi
+ movl %edi, %eax
+ retq
+# endif
+
+#endif
diff --git a/test cases/common/127 generated assembly/square.def b/test cases/common/127 generated assembly/square.def
new file mode 100644
index 0000000..79f3d65
--- /dev/null
+++ b/test cases/common/127 generated assembly/square.def
@@ -0,0 +1,2 @@
+EXPORTS
+ square_unsigned
diff --git a/test cases/common/127 generated assembly/symbol-underscore.h b/test cases/common/127 generated assembly/symbol-underscore.h
new file mode 100644
index 0000000..d0f3ef9
--- /dev/null
+++ b/test cases/common/127 generated assembly/symbol-underscore.h
@@ -0,0 +1,5 @@
+#if defined(MESON_TEST__UNDERSCORE_SYMBOL)
+# define SYMBOL_NAME(name) _##name
+#else
+# define SYMBOL_NAME(name) name
+#endif