Merge pull request #1320 from centricular/fix-llvmir-and-assembly
Fix llvmir and assemblypull/1325/head
commit
469a758c32
14 changed files with 205 additions and 6 deletions
@ -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,24 @@ |
||||
project('generated llvm ir', 'c') |
||||
|
||||
if meson.get_compiler('c').get_id() != 'clang' |
||||
error('MESON_SKIP_TEST: LLVM IR files can only be built with clang') |
||||
endif |
||||
|
||||
copy = find_program('copy.py') |
||||
|
||||
copygen = generator(copy, |
||||
arguments : ['@INPUT@', '@OUTPUT@'], |
||||
output : '@BASENAME@') |
||||
|
||||
l = shared_library('square-gen', copygen.process('square.ll.in')) |
||||
|
||||
test('square-gen-test', executable('square-gen-test', 'main.c', link_with : l)) |
||||
|
||||
copyct = custom_target('square', |
||||
input : 'square.ll.in', |
||||
output : 'square.ll', |
||||
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,4 @@ |
||||
define i32 @square_unsigned(i32 %a) { |
||||
%1 = mul i32 %a, %a |
||||
ret i32 %1 |
||||
} |
@ -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…
Reference in new issue