From 5b160f19c677b9e4508ef91ee86894f3d204eaa3 Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Wed, 11 Aug 2004 14:16:34 +0000 Subject: [PATCH] Simple hand-coded tests to aid in early development of backends, along with a Makefile to run ad-hoc tests easily. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15664 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/Generic/Makefile | 23 ++++++ test/CodeGen/Generic/branch.c | 15 ++++ test/CodeGen/Generic/call-ret0.ll | 8 ++ test/CodeGen/Generic/call-ret42.ll | 8 ++ test/CodeGen/Generic/call-void.ll | 8 ++ test/CodeGen/Generic/call2-ret0.ll | 13 +++ test/CodeGen/Generic/cast-fp.ll | 47 +++++++++++ test/CodeGen/Generic/global-ret0.ll | 6 ++ test/CodeGen/Generic/hello.ll | 9 +++ test/CodeGen/Generic/print-add.ll | 16 ++++ test/CodeGen/Generic/print-arith-fp.ll | 74 ++++++++++++++++++ test/CodeGen/Generic/print-arith-int.ll | 100 ++++++++++++++++++++++++ test/CodeGen/Generic/print-int.ll | 11 +++ test/CodeGen/Generic/print-mul-exp.ll | 55 +++++++++++++ test/CodeGen/Generic/print-mul.ll | 33 ++++++++ test/CodeGen/Generic/print-shift.ll | 33 ++++++++ test/CodeGen/Generic/print-vals.c | 7 ++ test/CodeGen/Generic/ret0.ll | 3 + test/CodeGen/Generic/ret42.ll | 3 + test/CodeGen/Generic/struct.c | 39 +++++++++ 20 files changed, 511 insertions(+) create mode 100644 test/CodeGen/Generic/Makefile create mode 100644 test/CodeGen/Generic/branch.c create mode 100644 test/CodeGen/Generic/call-ret0.ll create mode 100644 test/CodeGen/Generic/call-ret42.ll create mode 100644 test/CodeGen/Generic/call-void.ll create mode 100644 test/CodeGen/Generic/call2-ret0.ll create mode 100644 test/CodeGen/Generic/cast-fp.ll create mode 100644 test/CodeGen/Generic/global-ret0.ll create mode 100644 test/CodeGen/Generic/hello.ll create mode 100644 test/CodeGen/Generic/print-add.ll create mode 100644 test/CodeGen/Generic/print-arith-fp.ll create mode 100644 test/CodeGen/Generic/print-arith-int.ll create mode 100644 test/CodeGen/Generic/print-int.ll create mode 100644 test/CodeGen/Generic/print-mul-exp.ll create mode 100644 test/CodeGen/Generic/print-mul.ll create mode 100644 test/CodeGen/Generic/print-shift.ll create mode 100644 test/CodeGen/Generic/print-vals.c create mode 100644 test/CodeGen/Generic/ret0.ll create mode 100644 test/CodeGen/Generic/ret42.ll create mode 100644 test/CodeGen/Generic/struct.c diff --git a/test/CodeGen/Generic/Makefile b/test/CodeGen/Generic/Makefile new file mode 100644 index 00000000000..d228f69a856 --- /dev/null +++ b/test/CodeGen/Generic/Makefile @@ -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,$@) diff --git a/test/CodeGen/Generic/branch.c b/test/CodeGen/Generic/branch.c new file mode 100644 index 00000000000..d54a771da40 --- /dev/null +++ b/test/CodeGen/Generic/branch.c @@ -0,0 +1,15 @@ +#include +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; +} diff --git a/test/CodeGen/Generic/call-ret0.ll b/test/CodeGen/Generic/call-ret0.ll new file mode 100644 index 00000000000..205b0be0c39 --- /dev/null +++ b/test/CodeGen/Generic/call-ret0.ll @@ -0,0 +1,8 @@ +int %foo(int %x) { + ret int %x +} + +int %main() { + %r = call int %foo(int 0) + ret int %r +} diff --git a/test/CodeGen/Generic/call-ret42.ll b/test/CodeGen/Generic/call-ret42.ll new file mode 100644 index 00000000000..3501288ab4b --- /dev/null +++ b/test/CodeGen/Generic/call-ret42.ll @@ -0,0 +1,8 @@ +int %foo(int %x) { + ret int 42 +} + +int %main() { + %r = call int %foo(int 15) + ret int %r +} diff --git a/test/CodeGen/Generic/call-void.ll b/test/CodeGen/Generic/call-void.ll new file mode 100644 index 00000000000..b23a8d9b287 --- /dev/null +++ b/test/CodeGen/Generic/call-void.ll @@ -0,0 +1,8 @@ +void %foo() { + ret void +} + +int %main() { + call void ()* %foo() + ret int 0 +} diff --git a/test/CodeGen/Generic/call2-ret0.ll b/test/CodeGen/Generic/call2-ret0.ll new file mode 100644 index 00000000000..6159e40c097 --- /dev/null +++ b/test/CodeGen/Generic/call2-ret0.ll @@ -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 +} diff --git a/test/CodeGen/Generic/cast-fp.ll b/test/CodeGen/Generic/cast-fp.ll new file mode 100644 index 00000000000..9205fc9cb4e --- /dev/null +++ b/test/CodeGen/Generic/cast-fp.ll @@ -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 +} diff --git a/test/CodeGen/Generic/global-ret0.ll b/test/CodeGen/Generic/global-ret0.ll new file mode 100644 index 00000000000..f013937a8c1 --- /dev/null +++ b/test/CodeGen/Generic/global-ret0.ll @@ -0,0 +1,6 @@ +%g = global int 0 + +int %main() { + %h = load int* %g + ret int %h +} diff --git a/test/CodeGen/Generic/hello.ll b/test/CodeGen/Generic/hello.ll new file mode 100644 index 00000000000..3acde34f0fe --- /dev/null +++ b/test/CodeGen/Generic/hello.ll @@ -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 +} diff --git a/test/CodeGen/Generic/print-add.ll b/test/CodeGen/Generic/print-add.ll new file mode 100644 index 00000000000..0e998f4d494 --- /dev/null +++ b/test/CodeGen/Generic/print-add.ll @@ -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 +} + diff --git a/test/CodeGen/Generic/print-arith-fp.ll b/test/CodeGen/Generic/print-arith-fp.ll new file mode 100644 index 00000000000..da3c558a69b --- /dev/null +++ b/test/CodeGen/Generic/print-arith-fp.ll @@ -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 +} diff --git a/test/CodeGen/Generic/print-arith-int.ll b/test/CodeGen/Generic/print-arith-int.ll new file mode 100644 index 00000000000..d767190e594 --- /dev/null +++ b/test/CodeGen/Generic/print-arith-int.ll @@ -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 +} diff --git a/test/CodeGen/Generic/print-int.ll b/test/CodeGen/Generic/print-int.ll new file mode 100644 index 00000000000..ee7d3d1d5fe --- /dev/null +++ b/test/CodeGen/Generic/print-int.ll @@ -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 +} + diff --git a/test/CodeGen/Generic/print-mul-exp.ll b/test/CodeGen/Generic/print-mul-exp.ll new file mode 100644 index 00000000000..ea2882f9a3f --- /dev/null +++ b/test/CodeGen/Generic/print-mul-exp.ll @@ -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 +} diff --git a/test/CodeGen/Generic/print-mul.ll b/test/CodeGen/Generic/print-mul.ll new file mode 100644 index 00000000000..e406545f20a --- /dev/null +++ b/test/CodeGen/Generic/print-mul.ll @@ -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 +} diff --git a/test/CodeGen/Generic/print-shift.ll b/test/CodeGen/Generic/print-shift.ll new file mode 100644 index 00000000000..71bbbd1350c --- /dev/null +++ b/test/CodeGen/Generic/print-shift.ll @@ -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 +} diff --git a/test/CodeGen/Generic/print-vals.c b/test/CodeGen/Generic/print-vals.c new file mode 100644 index 00000000000..452bcaf527c --- /dev/null +++ b/test/CodeGen/Generic/print-vals.c @@ -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; +} diff --git a/test/CodeGen/Generic/ret0.ll b/test/CodeGen/Generic/ret0.ll new file mode 100644 index 00000000000..fc7086309f1 --- /dev/null +++ b/test/CodeGen/Generic/ret0.ll @@ -0,0 +1,3 @@ +int %main() { + ret int 0 +} diff --git a/test/CodeGen/Generic/ret42.ll b/test/CodeGen/Generic/ret42.ll new file mode 100644 index 00000000000..62890e4e758 --- /dev/null +++ b/test/CodeGen/Generic/ret42.ll @@ -0,0 +1,3 @@ +int %main() { + ret int 42 +} diff --git a/test/CodeGen/Generic/struct.c b/test/CodeGen/Generic/struct.c new file mode 100644 index 00000000000..c4181bc2505 --- /dev/null +++ b/test/CodeGen/Generic/struct.c @@ -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; +} -- 2.34.1