Add test for generated assembly

We weren't testing for this and it was broken
pull/1320/head
Nirbheek Chauhan 8 years ago
parent f934598865
commit 86a0c39f4b
  1. 6
      test cases/common/135 generated assembly/copy.py
  2. 14
      test cases/common/135 generated assembly/main.c
  3. 39
      test cases/common/135 generated assembly/meson.build
  4. 12
      test cases/common/135 generated assembly/square-arm.S.in
  5. 33
      test cases/common/135 generated assembly/square-x86.S.in
  6. 39
      test cases/common/135 generated assembly/square-x86_64.S.in
  7. 5
      test cases/common/135 generated assembly/symbol-underscore.h

@ -0,0 +1,6 @@
#!/usr/bin/env python
import sys
import shutil
shutil.copyfile(sys.argv[1], sys.argv[2])

@ -0,0 +1,14 @@
#include <stdio.h>
unsigned square_unsigned (unsigned a);
int
main (int argc, char * argv[])
{
unsigned int ret = square_unsigned (2);
if (ret != 4) {
printf("Got %u instead of 4\n", ret);
return 1;
}
return 0;
}

@ -0,0 +1,39 @@
project('generated assembly', 'c')
cc = meson.get_compiler('c')
if cc.get_id() == 'msvc'
error('MESON_SKIP_TEST: assembly files cannot be compiled directly by MSVC')
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.symbols_have_underscore_prefix()
add_project_arguments('-DMESON_TEST__UNDERSCORE_SYMBOL', language : 'c')
endif
copy = find_program('copy.py')
output = 'square-@0@.S'.format(cpu)
input = output + '.in'
copygen = generator(copy,
arguments : ['@INPUT@', '@OUTPUT@'],
output : '@BASENAME@')
l = shared_library('square-gen', copygen.process(input))
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 = shared_library('square-ct', copyct)
test('square-ct-test', executable('square-ct-test', 'main.c', link_with : l))

@ -0,0 +1,12 @@
#include "symbol-underscore.h"
.text
.globl SYMBOL_NAME(square_unsigned)
#ifndef __APPLE__
.type square_unsigned,%function
#endif
SYMBOL_NAME(square_unsigned):
mul r1, r0, r0
mov r0, r1
mov pc, lr

@ -0,0 +1,33 @@
#include "symbol-underscore.h"
#ifdef _MSC_VER
.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)
# ifndef __APPLE__
.type square_unsigned,@function
# endif
SYMBOL_NAME(square_unsigned):
movl 4(%esp), %eax
imull %eax, %eax
retl
#endif

@ -0,0 +1,39 @@
#include "symbol-underscore.h"
#include "symbol-underscore.h"
#ifdef _MSC_VER /* 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)
# ifndef __APPLE__
.type square_unsigned,@function
# endif
# ifdef _WIN32 /* MinGW */
SYMBOL_NAME(square_unsigned):
imull %ecx, %ecx
movl %ecx, %eax
retq
# else /* Linux and OS X */
SYMBOL_NAME(square_unsigned):
imull %edi, %edi
movl %edi, %eax
retq
# endif
#endif

@ -0,0 +1,5 @@
#if defined(MESON_TEST__UNDERSCORE_SYMBOL)
# define SYMBOL_NAME(name) _##name
#else
# define SYMBOL_NAME(name) name
#endif
Loading…
Cancel
Save