1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

Simple hand-coded tests to aid in early development of backends, along with a

Makefile to run ad-hoc tests easily.

llvm-svn: 15664
This commit is contained in:
Misha Brukman 2004-08-11 14:16:34 +00:00
parent 1f4fb14301
commit d34a40864a
20 changed files with 511 additions and 0 deletions

View File

@ -0,0 +1,23 @@
# Makefile for running ad-hoc custom LLVM tests
#
%.bc: %.ll
llvm-as -f $<
%.llc.s: %.bc
llc -f $< -o $@
%.gcc.s: %.c
gcc -O0 -S $< -o $@
%.nat: %.s
gcc -O0 -lm $< -o $@
%.cbe.out: %.cbe.nat
./$< > $@
%.out: %.nat
./$< > $@
%.clean:
rm -f $(patsubst %.clean,%.bc,$@) $(patsubst %.clean,%.*.s,$@) \
$(patsubst %.clean,%.*.nat,$@) $(patsubst %.clean,%.*.out,$@)

View File

@ -0,0 +1,15 @@
#include <stdio.h>
int a = 1, b = 2;
int main() {
int i,j;
for (i=15; i>=0; --i) {
if (a < i) printf("%d < %d\n", a, i);
else printf("%d >= %d\n", a, i);
for (j=2; j <= 25; j++) {
printf("%d, ", j);
}
printf("\n");
}
return 0;
}

View File

@ -0,0 +1,8 @@
int %foo(int %x) {
ret int %x
}
int %main() {
%r = call int %foo(int 0)
ret int %r
}

View File

@ -0,0 +1,8 @@
int %foo(int %x) {
ret int 42
}
int %main() {
%r = call int %foo(int 15)
ret int %r
}

View File

@ -0,0 +1,8 @@
void %foo() {
ret void
}
int %main() {
call void ()* %foo()
ret int 0
}

View File

@ -0,0 +1,13 @@
int %bar(int %x) {
ret int 0
}
int %foo(int %x) {
%q = call int %bar(int 1)
ret int %q
}
int %main() {
%r = call int %foo(int 2)
ret int %r
}

View File

@ -0,0 +1,47 @@
%a_fstr = internal constant [8 x sbyte] c"a = %f\0A\00"
%a_lstr = internal constant [10 x sbyte] c"a = %lld\0A\00"
%a_dstr = internal constant [8 x sbyte] c"a = %d\0A\00"
%b_dstr = internal constant [8 x sbyte] c"b = %d\0A\00"
%b_fstr = internal constant [8 x sbyte] c"b = %f\0A\00"
declare int %printf(sbyte*, ...)
%A = global double 2.0
%B = global int 2
int %main() {
;; A
%a = load double* %A
%a_fs = getelementptr [8 x sbyte]* %a_fstr, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %a_fs, double %a)
;; cast double to long
%a_d2l = cast double %a to long
%a_ls = getelementptr [10 x sbyte]* %a_lstr, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %a_ls, long %a_d2l)
;; cast double to int
%a_d2i = cast double %a to int
%a_ds = getelementptr [8 x sbyte]* %a_dstr, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %a_ds, int %a_d2i)
;; cast double to sbyte
%a_d2sb = cast double %a to sbyte
call int (sbyte*, ...)* %printf(sbyte* %a_ds, sbyte %a_d2sb)
;; cast int to sbyte
%a_d2i2sb = cast int %a_d2i to sbyte
call int (sbyte*, ...)* %printf(sbyte* %a_ds, sbyte %a_d2i2sb)
;; B
%b = load int* %B
%b_ds = getelementptr [8 x sbyte]* %b_dstr, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %b_ds, int %b)
;; cast int to double
%b_i2d = cast int %b to double
%b_fs = getelementptr [8 x sbyte]* %b_fstr, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %b_fs, double %b_i2d)
ret int 0
}

View File

@ -0,0 +1,6 @@
%g = global int 0
int %main() {
%h = load int* %g
ret int %h
}

View File

@ -0,0 +1,9 @@
%.str_1 = internal constant [7 x sbyte] c"hello\0A\00"
declare int %printf(sbyte*, ...)
int %main() {
%s = getelementptr [7 x sbyte]* %.str_1, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %s)
ret int 0
}

View File

@ -0,0 +1,16 @@
%.str_1 = internal constant [4 x sbyte] c"%d\0A\00"
declare int %printf(sbyte*, ...)
int %main() {
%f = getelementptr [4 x sbyte]* %.str_1, long 0, long 0
%d = add int 1, 0
call int (sbyte*, ...)* %printf(sbyte* %f, int %d)
%e = add int 38, 2
call int (sbyte*, ...)* %printf(sbyte* %f, int %e)
%g = add int %d, %d
%h = add int %e, %g
call int (sbyte*, ...)* %printf(sbyte* %f, int %h)
ret int 0
}

View File

@ -0,0 +1,74 @@
%a_str = internal constant [8 x sbyte] c"a = %f\0A\00"
%b_str = internal constant [8 x sbyte] c"b = %f\0A\00"
;; binary ops: arith
%add_str = internal constant [12 x sbyte] c"a + b = %f\0A\00"
%sub_str = internal constant [12 x sbyte] c"a - b = %f\0A\00"
%mul_str = internal constant [12 x sbyte] c"a * b = %f\0A\00"
%div_str = internal constant [12 x sbyte] c"b / a = %f\0A\00"
%rem_str = internal constant [13 x sbyte] c"b %% a = %f\0A\00"
;; binary ops: setcc
%lt_str = internal constant [12 x sbyte] c"a < b = %d\0A\00"
%le_str = internal constant [13 x sbyte] c"a <= b = %d\0A\00"
%gt_str = internal constant [12 x sbyte] c"a > b = %d\0A\00"
%ge_str = internal constant [13 x sbyte] c"a >= b = %d\0A\00"
%eq_str = internal constant [13 x sbyte] c"a == b = %d\0A\00"
%ne_str = internal constant [13 x sbyte] c"a != b = %d\0A\00"
declare int %printf(sbyte*, ...)
%A = global double 2.0
%B = global double 5.0
int %main() {
;; main vars
%a = load double* %A
%b = load double* %B
%a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
%b_s = getelementptr [8 x sbyte]* %b_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %a_s, double %a)
call int (sbyte*, ...)* %printf(sbyte* %b_s, double %b)
;; arithmetic
%add_r = add double %a, %b
%sub_r = sub double %a, %b
%mul_r = mul double %a, %b
%div_r = div double %b, %a
%rem_r = rem double %b, %a
%add_s = getelementptr [12 x sbyte]* %add_str, long 0, long 0
%sub_s = getelementptr [12 x sbyte]* %sub_str, long 0, long 0
%mul_s = getelementptr [12 x sbyte]* %mul_str, long 0, long 0
%div_s = getelementptr [12 x sbyte]* %div_str, long 0, long 0
%rem_s = getelementptr [13 x sbyte]* %rem_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %add_s, double %add_r)
call int (sbyte*, ...)* %printf(sbyte* %sub_s, double %sub_r)
call int (sbyte*, ...)* %printf(sbyte* %mul_s, double %mul_r)
call int (sbyte*, ...)* %printf(sbyte* %div_s, double %div_r)
call int (sbyte*, ...)* %printf(sbyte* %rem_s, double %rem_r)
;; setcc
%lt_r = setlt double %a, %b
%le_r = setle double %a, %b
%gt_r = setgt double %a, %b
%ge_r = setge double %a, %b
%eq_r = seteq double %a, %b
%ne_r = setne double %a, %b
%lt_s = getelementptr [12 x sbyte]* %lt_str, long 0, long 0
%le_s = getelementptr [13 x sbyte]* %le_str, long 0, long 0
%gt_s = getelementptr [12 x sbyte]* %gt_str, long 0, long 0
%ge_s = getelementptr [13 x sbyte]* %ge_str, long 0, long 0
%eq_s = getelementptr [13 x sbyte]* %eq_str, long 0, long 0
%ne_s = getelementptr [13 x sbyte]* %ne_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %lt_s, bool %lt_r)
call int (sbyte*, ...)* %printf(sbyte* %le_s, bool %le_r)
call int (sbyte*, ...)* %printf(sbyte* %gt_s, bool %gt_r)
call int (sbyte*, ...)* %printf(sbyte* %ge_s, bool %ge_r)
call int (sbyte*, ...)* %printf(sbyte* %eq_s, bool %eq_r)
call int (sbyte*, ...)* %printf(sbyte* %ne_s, bool %ne_r)
ret int 0
}

View File

@ -0,0 +1,100 @@
%a_str = internal constant [8 x sbyte] c"a = %d\0A\00"
%b_str = internal constant [8 x sbyte] c"b = %d\0A\00"
;; binary ops: arith
%add_str = internal constant [12 x sbyte] c"a + b = %d\0A\00"
%sub_str = internal constant [12 x sbyte] c"a - b = %d\0A\00"
%mul_str = internal constant [12 x sbyte] c"a * b = %d\0A\00"
%div_str = internal constant [12 x sbyte] c"b / a = %d\0A\00"
%rem_str = internal constant [13 x sbyte] c"b \% a = %d\0A\00"
;; binary ops: setcc
%lt_str = internal constant [12 x sbyte] c"a < b = %d\0A\00"
%le_str = internal constant [13 x sbyte] c"a <= b = %d\0A\00"
%gt_str = internal constant [12 x sbyte] c"a > b = %d\0A\00"
%ge_str = internal constant [13 x sbyte] c"a >= b = %d\0A\00"
%eq_str = internal constant [13 x sbyte] c"a == b = %d\0A\00"
%ne_str = internal constant [13 x sbyte] c"a != b = %d\0A\00"
;; logical
%and_str = internal constant [12 x sbyte] c"a & b = %d\0A\00"
%or_str = internal constant [12 x sbyte] c"a | b = %d\0A\00"
%xor_str = internal constant [12 x sbyte] c"a ^ b = %d\0A\00"
%shl_str = internal constant [13 x sbyte] c"b << a = %d\0A\00"
%shr_str = internal constant [13 x sbyte] c"b >> a = %d\0A\00"
declare int %printf(sbyte*, ...)
%A = global int 2
%B = global int 5
int %main() {
;; main vars
%a = load int* %A
%b = load int* %B
%a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
%b_s = getelementptr [8 x sbyte]* %b_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %a_s, int %a)
call int (sbyte*, ...)* %printf(sbyte* %b_s, int %b)
;; arithmetic
%add_r = add int %a, %b
%sub_r = sub int %a, %b
%mul_r = mul int %a, %b
%div_r = div int %b, %a
%rem_r = rem int %b, %a
%add_s = getelementptr [12 x sbyte]* %add_str, long 0, long 0
%sub_s = getelementptr [12 x sbyte]* %sub_str, long 0, long 0
%mul_s = getelementptr [12 x sbyte]* %mul_str, long 0, long 0
%div_s = getelementptr [12 x sbyte]* %div_str, long 0, long 0
%rem_s = getelementptr [13 x sbyte]* %rem_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %add_s, int %add_r)
call int (sbyte*, ...)* %printf(sbyte* %sub_s, int %sub_r)
call int (sbyte*, ...)* %printf(sbyte* %mul_s, int %mul_r)
call int (sbyte*, ...)* %printf(sbyte* %div_s, int %div_r)
call int (sbyte*, ...)* %printf(sbyte* %rem_s, int %rem_r)
;; setcc
%lt_r = setlt int %a, %b
%le_r = setle int %a, %b
%gt_r = setgt int %a, %b
%ge_r = setge int %a, %b
%eq_r = seteq int %a, %b
%ne_r = setne int %a, %b
%lt_s = getelementptr [12 x sbyte]* %lt_str, long 0, long 0
%le_s = getelementptr [13 x sbyte]* %le_str, long 0, long 0
%gt_s = getelementptr [12 x sbyte]* %gt_str, long 0, long 0
%ge_s = getelementptr [13 x sbyte]* %ge_str, long 0, long 0
%eq_s = getelementptr [13 x sbyte]* %eq_str, long 0, long 0
%ne_s = getelementptr [13 x sbyte]* %ne_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %lt_s, bool %lt_r)
call int (sbyte*, ...)* %printf(sbyte* %le_s, bool %le_r)
call int (sbyte*, ...)* %printf(sbyte* %gt_s, bool %gt_r)
call int (sbyte*, ...)* %printf(sbyte* %ge_s, bool %ge_r)
call int (sbyte*, ...)* %printf(sbyte* %eq_s, bool %eq_r)
call int (sbyte*, ...)* %printf(sbyte* %ne_s, bool %ne_r)
;; logical
%and_r = and int %a, %b
%or_r = or int %a, %b
%xor_r = xor int %a, %b
%u = cast int %a to ubyte
%shl_r = shl int %b, ubyte %u
%shr_r = shr int %b, ubyte %u
%and_s = getelementptr [12 x sbyte]* %and_str, long 0, long 0
%or_s = getelementptr [12 x sbyte]* %or_str, long 0, long 0
%xor_s = getelementptr [12 x sbyte]* %xor_str, long 0, long 0
%shl_s = getelementptr [13 x sbyte]* %shl_str, long 0, long 0
%shr_s = getelementptr [13 x sbyte]* %shr_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %and_s, int %and_r)
call int (sbyte*, ...)* %printf(sbyte* %or_s, int %or_r)
call int (sbyte*, ...)* %printf(sbyte* %xor_s, int %xor_r)
call int (sbyte*, ...)* %printf(sbyte* %shl_s, int %shl_r)
call int (sbyte*, ...)* %printf(sbyte* %shr_s, int %shr_r)
ret int 0
}

View File

@ -0,0 +1,11 @@
%.str_1 = internal constant [4 x sbyte] c"%d\0A\00"
declare int %printf(sbyte*, ...)
int %main() {
%f = getelementptr [4 x sbyte]* %.str_1, long 0, long 0
%d = add int 0, 0
%tmp.0 = call int (sbyte*, ...)* %printf(sbyte* %f, int %d)
ret int 0
}

View File

@ -0,0 +1,55 @@
%a_str = internal constant [8 x sbyte] c"a = %d\0A\00"
%a_mul_str = internal constant [13 x sbyte] c"a * %d = %d\0A\00"
%A = global int 2
declare int %printf(sbyte*, ...)
int %main() {
%a = load int* %A
%a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
%a_mul_s = getelementptr [13 x sbyte]* %a_mul_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %a_s, int %a)
%r_0 = mul int %a, 0
%r_1 = mul int %a, 1
%r_2 = mul int %a, 2
%r_3 = mul int %a, 3
%r_4 = mul int %a, 4
%r_5 = mul int %a, 5
%r_6 = mul int %a, 6
%r_7 = mul int %a, 7
%r_8 = mul int %a, 8
%r_9 = mul int %a, 9
%r_10 = mul int %a, 10
%r_11 = mul int %a, 11
%r_12 = mul int %a, 12
%r_13 = mul int %a, 13
%r_14 = mul int %a, 14
%r_15 = mul int %a, 15
%r_16 = mul int %a, 16
%r_17 = mul int %a, 17
%r_18 = mul int %a, 18
%r_19 = mul int %a, 19
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 0, int %r_0)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 1, int %r_1)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 2, int %r_2)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 3, int %r_3)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 4, int %r_4)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 5, int %r_5)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 6, int %r_6)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 7, int %r_7)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 8, int %r_8)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 9, int %r_9)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 10, int %r_10)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 11, int %r_11)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 12, int %r_12)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 13, int %r_13)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 14, int %r_14)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 15, int %r_15)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 16, int %r_16)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 17, int %r_17)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 18, int %r_18)
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int 19, int %r_19)
ret int 0
}

View File

@ -0,0 +1,33 @@
%a_str = internal constant [8 x sbyte] c"a = %d\0A\00"
%b_str = internal constant [8 x sbyte] c"b = %d\0A\00"
;; mul
%a_mul_str = internal constant [13 x sbyte] c"a * %d = %d\0A\00"
declare int %printf(sbyte*, ...)
%A = global int 2
%B = global int 5
int %main() {
entry:
%a = load int* %A
%b = load int* %B
%a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
%b_s = getelementptr [8 x sbyte]* %b_str, long 0, long 0
%a_mul_s = getelementptr [13 x sbyte]* %a_mul_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %a_s, int %a)
call int (sbyte*, ...)* %printf(sbyte* %b_s, int %b)
br label %shl_test
shl_test:
;; test mul by 0-255
%s = phi int [ 0, %entry ], [ %s_inc, %shl_test ]
%result = mul int %a, %s
call int (sbyte*, ...)* %printf(sbyte* %a_mul_s, int %s, int %result)
%s_inc = add int %s, 1
%done = seteq int %s, 256
br bool %done, label %fini, label %shl_test
fini:
ret int 0
}

View File

@ -0,0 +1,33 @@
%a_str = internal constant [8 x sbyte] c"a = %d\0A\00"
%b_str = internal constant [8 x sbyte] c"b = %d\0A\00"
;; shl
%a_shl_str = internal constant [14 x sbyte] c"a << %d = %d\0A\00"
declare int %printf(sbyte*, ...)
%A = global int 2
%B = global int 5
int %main() {
entry:
%a = load int* %A
%b = load int* %B
%a_s = getelementptr [8 x sbyte]* %a_str, long 0, long 0
%b_s = getelementptr [8 x sbyte]* %b_str, long 0, long 0
%a_shl_s = getelementptr [14 x sbyte]* %a_shl_str, long 0, long 0
call int (sbyte*, ...)* %printf(sbyte* %a_s, int %a)
call int (sbyte*, ...)* %printf(sbyte* %b_s, int %b)
br label %shl_test
shl_test:
;; test left shifts 0-31
%s = phi ubyte [ 0, %entry ], [ %s_inc, %shl_test ]
%result = shl int %a, ubyte %s
call int (sbyte*, ...)* %printf(sbyte* %a_shl_s, ubyte %s, int %result)
%s_inc = add ubyte %s, 1
%done = seteq ubyte %s, 32
br bool %done, label %fini, label %shl_test
fini:
ret int 0
}

View File

@ -0,0 +1,7 @@
void printf(char*, ...);
int main() {
printf("%f, %d, %f, %d, %f\n", //, %d, %f, %d, %f, %d\n",
1.0, 2, 3.0, 4, 5.0 /*, 6, 7.0, 8, 9.0, 10*/);
return 0;
}

View File

@ -0,0 +1,3 @@
int %main() {
ret int 0
}

View File

@ -0,0 +1,3 @@
int %main() {
ret int 42
}

View File

@ -0,0 +1,39 @@
void printf(char*, ...);
typedef struct params_ {
int i1;
float f1;
double d1;
short s1;
double d2;
char c1;
unsigned short s2;
float f2;
int i2;
} params;
void print_param(params p) {
printf("%d, %f, %f, %d, %f, %c, %d, %f, %d\n",
p.i1, p.f1, p.d1, p.s1, p.d2, p.c1, p.s2, p.f2, p.i2);
}
void print_param_addr(params *p) {
printf("%d, %f, %f, %d, %f, %c, %d, %f, %d\n",
p->i1, p->f1, p->d1, p->s1, p->d2, p->c1, p->s2, p->f2, p->i2);
}
int main() {
params p;
p.i1 = 1;
p.f1 = 2.0;
p.d1 = 3.0;
p.s1 = 4;
p.d2 = 5.0;
p.c1 = '6';
p.s2 = 7;
p.f2 = 8.0;
p.i2 = 9;
print_param(p);
print_param_addr(&p);
return 0;
}