diff options
Diffstat (limited to 'test')
-rwxr-xr-x | test/Feature/TestAsmDisasm.sh | 21 | ||||
-rwxr-xr-x | test/Feature/TestOptimizer.sh | 13 | ||||
-rw-r--r-- | test/Feature/basictest.ll | 53 | ||||
-rw-r--r-- | test/Feature/calltest.ll | 16 | ||||
-rw-r--r-- | test/Feature/forwardreftest.ll | 30 | ||||
-rw-r--r-- | test/Feature/small.ll | 10 | ||||
-rw-r--r-- | test/Feature/smallest.ll | 3 | ||||
-rw-r--r-- | test/Feature/testmemory.ll | 23 | ||||
-rw-r--r-- | test/Feature/testswitch.ll | 21 | ||||
-rw-r--r-- | test/Makefile | 20 | ||||
-rw-r--r-- | test/Setup | 4 | ||||
-rwxr-xr-x | test/SetupOpt | 4 | ||||
-rw-r--r-- | test/fib.ll | 43 | ||||
-rw-r--r-- | test/inlinetest.ll | 27 | ||||
-rw-r--r-- | test/opttest.ll | 59 | ||||
-rw-r--r-- | test/test2darray.ll | 10 | ||||
-rw-r--r-- | test/testpointer.ll | 12 | ||||
-rw-r--r-- | test/teststruct.ll | 13 |
18 files changed, 382 insertions, 0 deletions
diff --git a/test/Feature/TestAsmDisasm.sh b/test/Feature/TestAsmDisasm.sh new file mode 100755 index 0000000..86753e0 --- /dev/null +++ b/test/Feature/TestAsmDisasm.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# test that every step outputs something that is consumable by +# another step + +rm -f test.bc.temp[12] + +LD_LIBRARY_PATH=../lib/Assembly/Parser/Debug:../lib/Assembly/Writer/Debug:../lib/Analysis/Debug:../lib/VMCore/Debug:../lib/Bytecode/Writer/Debug:../lib/Bytecode/Reader/Debug:../lib/Optimizations/Debug +export LD_LIBRARY_PATH + +# Two full cycles are needed for bitwise stability + +../tools/as/as < $1 > $1.bc.1 || exit 1 +../tools/dis/dis < $1.bc.1 > $1.ll.1 || exit 2 +../tools/as/as < $1.ll.1 > $1.bc.2 || exit 3 +../tools/dis/dis < $1.bc.2 > $1.ll.2 || exit 4 + +diff $1.ll.[12] || exit 7 +diff $1.bc.[12] || exit 8 + +rm $1.[bl][cl].[12] + diff --git a/test/Feature/TestOptimizer.sh b/test/Feature/TestOptimizer.sh new file mode 100755 index 0000000..b34aae2 --- /dev/null +++ b/test/Feature/TestOptimizer.sh @@ -0,0 +1,13 @@ +#!/bin/sh +LD_LIBRARY_PATH=../lib/Assembly/Parser/Debug:../lib/Assembly/Writer/Debug:../lib/Analysis/Debug:../lib/VMCore/Debug:../lib/Bytecode/Writer/Debug:../lib/Bytecode/Reader/Debug:../lib/Optimizations/Debug +export LD_LIBRARY_PATH + + +../tools/as/as < $1 | ../tools/opt/opt -q -inline -constprop -dce | ../tools/dis/dis | ../tools/as/as > $1.bc.1 || exit 1 + +# Should not be able to optimize further! +../tools/opt/opt -q -inline -constprop -dce < $1.bc.1 > $1.bc.2 || exit 2 + +diff $1.bc.[12] || exit 3 +rm $1.bc.[12] + diff --git a/test/Feature/basictest.ll b/test/Feature/basictest.ll new file mode 100644 index 0000000..b50c4f3 --- /dev/null +++ b/test/Feature/basictest.ll @@ -0,0 +1,53 @@ +implementation + +void "test function"(int %i0, int %j0) + %x = int 1 +begin +Startup: ; Basic block #0 + %i1 = add int %i0, 1 + %j1 = add int %j0, 1 + %x = setle int %i1, %j1 + br bool %x, label %Increment, label %Decrement + +Merge: ; Basic block #3 + %i4 = phi int %i2, %i3 ; Forward ref vars... + %j2 = add int %j1, %i4 + ret void + +Increment: ; Basic block #1 + %i2 = add int %i1, 1 + br label %Merge + +Decrement: ; Basic block #2 + %i3 = sub int %i1, %x + br label %Merge +end + + +; Test "stripped" format where nothing is symbolic... this is how the bytecode +; format looks anyways (except for negative vs positive offsets)... +; +void "void"(int, int) ; Def %0, %1 + int 0 ; Def 2 + int -4 ; Def 3 +begin + add int %0, %1 ; Def 4 + sub int %4, %3 ; Def 5 + setle int %5, %2 ; Def 0 - bool plane + br bool %0, label %1, label %0 + + add int %0, %1 ; Def 6 + sub int %4, %3 ; Def 7 + setle int %7, %2 ; Def 1 - bool plane + ret void +end + +; This function always returns zero +int "zarro"() + uint 4000000000 ; Def 0 - uint plane + int 0 ; Def 0 - int plane +begin +Startup: + ret int %0 +end + diff --git a/test/Feature/calltest.ll b/test/Feature/calltest.ll new file mode 100644 index 0000000..f478e50 --- /dev/null +++ b/test/Feature/calltest.ll @@ -0,0 +1,16 @@ +implementation + +; Bytecode gets a constant pool block, that constains: +; type plane: int(int) + +int "main"(int %argc) ; TODO: , sbyte **argv, sbyte **envp) +begin + %retval = call int (int) %test(int %argc) + %two = add int %retval, %retval + ret int %two +end + +int "test"(int %i0) +begin + ret int %i0 +end diff --git a/test/Feature/forwardreftest.ll b/test/Feature/forwardreftest.ll new file mode 100644 index 0000000..1465670 --- /dev/null +++ b/test/Feature/forwardreftest.ll @@ -0,0 +1,30 @@ + %myty = type int + %myfn = type float (int,double,uint,short) + type int(%myfn) + type int(int) + type int(int(int)) +implementation + +; This function always returns zero +int "zarro"(int %Func) + %q = uint 4000000000 + %p = int 0 +begin +Startup: + add int %p, 10 + ret int %p +end + +int "test"(int) + %thisfuncty = type int (int) +begin + add %thisfuncty %zarro, %test + add %thisfuncty %test, %foozball + ret int 0 +end + +int "foozball"(int) +begin + ret int 0 +end + diff --git a/test/Feature/small.ll b/test/Feature/small.ll new file mode 100644 index 0000000..9e98de4 --- /dev/null +++ b/test/Feature/small.ll @@ -0,0 +1,10 @@ +%x = type int + +implementation + +int "foo"(int %in) +begin +label: + ret void +end + diff --git a/test/Feature/smallest.ll b/test/Feature/smallest.ll new file mode 100644 index 0000000..6c5db17 --- /dev/null +++ b/test/Feature/smallest.ll @@ -0,0 +1,3 @@ + +implementation + diff --git a/test/Feature/testmemory.ll b/test/Feature/testmemory.ll new file mode 100644 index 0000000..c9ccd6c --- /dev/null +++ b/test/Feature/testmemory.ll @@ -0,0 +1,23 @@ +%struct = type int * + +implementation + +int "test function"(int %i0, int %j0) +begin + %array0 = malloc [4 x ubyte] ; yields {[4 x ubyte]*}:array0 + %size = add uint 2, 2 ; yields {uint}:size = uint %4 + %array1 = malloc [ubyte], uint 4 ; yields {[ubyte]*}:array1 + %array2 = malloc [ubyte], uint %size ; yields {[ubyte]*}:array2 + free [4x ubyte]* %array0 + free [ubyte]* %array1 + free [ubyte]* %array2 + + + alloca [ubyte], uint 5 + %ptr = alloca int ; yields {int*}:ptr + ;store int* %ptr, int 3 ; yields {void} + ;%val = load int* %ptr ; yields {int}:val = int %3 + + ret int 3 +end + diff --git a/test/Feature/testswitch.ll b/test/Feature/testswitch.ll new file mode 100644 index 0000000..e5190d0 --- /dev/null +++ b/test/Feature/testswitch.ll @@ -0,0 +1,21 @@ + %int = type int + +implementation + +int "squared"(%int %i0) +begin + switch int %i0, label %Default [ + int 1, label %Case1 + int 2, label %Case2 + int 4, label %Case4 ] + +Default: + ret int -1 ; Unrecognized input value + +Case1: + ret int 1 +Case2: + ret int 4 +Case4: + ret int 16 +end diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..de6ac40 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,20 @@ +TESTS := $(wildcard *.ll) + +test all : testasmdis testopt + @echo "All tests successfully completed!" + +testasmdis : $(TESTS:%.ll=%.ll.asmdis) + @echo "All assembler/disassembler test succeeded!" + +testopt : $(TESTS:%.ll=%.ll.opt) + +clean : + rm -f *.[123] *.bc core + +%.asmdis: % + @echo "Running assembler/disassembler test on $<" + @./TestAsmDisasm.sh $< + +%.opt: % + @echo "Running optimizier test on $<" + @./TestOptimizer.sh $< diff --git a/test/Setup b/test/Setup new file mode 100644 index 0000000..6972103 --- /dev/null +++ b/test/Setup @@ -0,0 +1,4 @@ +setenv LD_LIBRARY_PATH ../lib/Assembly/Parser/Debug:../lib/Assembly/Writer/Debug:../lib/Analysis/Debug:../lib/VMCore/Debug:../lib/Bytecode/Writer/Debug:../lib/Bytecode/Reader/Debug:../lib/Optimizations/Debug + +setenv PATH ../tools/dis:../tools/opt:../tools/strip:${PATH} +alias as ../tools/as/as diff --git a/test/SetupOpt b/test/SetupOpt new file mode 100755 index 0000000..12d1c09 --- /dev/null +++ b/test/SetupOpt @@ -0,0 +1,4 @@ +setenv LD_LIBRARY_PATH ../lib/Assembly/Parser/Release:../lib/Assembly/Writer/Release:../lib/Analysis/Release:../lib/VMCore/Release:../lib/Bytecode/Writer/Release:../lib/Bytecode/Reader/Release:../lib/Optimizations/Release + +setenv PATH ../tools/dis:../tools/opt:../tools/strip:${PATH} +alias as ../tools/as/as diff --git a/test/fib.ll b/test/fib.ll new file mode 100644 index 0000000..73d5e53 --- /dev/null +++ b/test/fib.ll @@ -0,0 +1,43 @@ + +;; TODO: +;; [ ] Get rid out outside class & begin stuff +;; [ ] Allow global const pool to be expanded continually +;; [ ] Support global variable declaration & definition +;; [ ] Support function definition: %fib = prototype ulong (ulong) +;; [x] Support Type definition + +implementation + +ulong "fib"(ulong %n) +begin + setlt ulong %n, 2 ; {bool}:0 + br bool %0, label %BaseCase, label %RecurseCase + +BaseCase: + ret ulong 1 + +RecurseCase: + %n2 = sub ulong %n, 2 + %n1 = sub ulong %n, 1 + %f2 = call ulong(ulong) %fib(ulong %n2) + %f1 = call ulong(ulong) %fib(ulong %n1) + %result = add ulong %f2, %f1 + ret ulong %result +end + +ulong "main"(int %argc, sbyte ** %argv) +;; %n2 = int 1 +begin + seteq int %argc, 2 ; {bool}:0 + br bool %0, label %HasArg, label %Continue +HasArg: + ; %n1 = atoi(argv[1]) +;;; %n1 = add int 1, 1 + br label %Continue + +Continue: +;;; %n = phi int %n1, %n2 + %N = add ulong 1, 1 ;; TODO: CAST + %F = call ulong(ulong) %fib(ulong %N) + ret ulong %F +end diff --git a/test/inlinetest.ll b/test/inlinetest.ll new file mode 100644 index 0000000..6db3076 --- /dev/null +++ b/test/inlinetest.ll @@ -0,0 +1,27 @@ +implementation + +int "FuncToInline"() +begin + %x = add int 1, 1 ; Instrs can be const prop'd away + %y = sub int -1, 1 + %z = add int %x, %y + ret int %z ; Should equal %0 +end + +int "FuncToInlineInto"(int %arg) ; Instrs can be const prop'd away +begin + %x = add int %arg, 1 + %y = sub int 1, -1 + %p = call int() %FuncToInline() + %z = add int %x, %y + %q = add int %p, %z + + ret int %q +end + +int "FTIITII"() +begin + %z = call int(int) %FuncToInlineInto(int 1) + ret int %z +end + diff --git a/test/opttest.ll b/test/opttest.ll new file mode 100644 index 0000000..bbfe1f6 --- /dev/null +++ b/test/opttest.ll @@ -0,0 +1,59 @@ + long 12 + +implementation + +ulong "const removal"() + long 12345 + %q = uint 4000000000 ; Def 0 - uint plane + ulong 123 ; Def 0 - ulong plane + ulong 4000000000000 ; Def 1 - ulong plane +begin + ret ulong %1 +end + +void "dce #1"() + int 0 +begin + ret void + + ret void ; Unreachable label +end + +void "basic block merge #1"(int %a, uint %b, bool %c, ulong %d) +begin + add int %0, %0 + br label %TestName ; Can be merged with next block +TestName: + add uint %0, %0 + br label %1 ; Can be merged with next block + add ulong %0, %0 + ret void +end + +void "const prop #1"() + %x = int 0 ; Def %x - int plane + int 0 ; Def 0 - int plane + bool false +begin +Startup: + %x = seteq int %0, %x + br bool %x, label %0, label %Startup ; Can be eliminated by const prop + + ret void +end + +int "const prop #2"() +begin + %x = add int 1, 1 ; Instrs can be const prop'd away + %y = sub int -1, 1 + %z = add int %x, %y + ret int %z ; Should equal %0 +end + +sbyte "const prop #3"() ; Instrs can be const prop'd away +begin + %x = add sbyte 127, 127 ; Must wrap around correctly! + %y = sub sbyte 1, -1 + %z = add sbyte %x, %y + ret sbyte %z ; Should equal %0! +end diff --git a/test/test2darray.ll b/test/test2darray.ll new file mode 100644 index 0000000..123d26c --- /dev/null +++ b/test/test2darray.ll @@ -0,0 +1,10 @@ +implementation + +[[2 x int]] "test function"(int %i0, int %j0) + %array = [[2 x int]] [ + [2 x int] [ int 12, int 52 ] + ] +begin + ret [[2x int]] %array +end + diff --git a/test/testpointer.ll b/test/testpointer.ll new file mode 100644 index 0000000..586a040 --- /dev/null +++ b/test/testpointer.ll @@ -0,0 +1,12 @@ + %ptrty = type int * + +implementation + +[[2 x int]] "test function"(int %i0, int %j0) + %array = [[2 x int]] [ + [2 x int] [ int 12, int 52 ] + ] +begin + ret [[2x int]] %array +end + diff --git a/test/teststruct.ll b/test/teststruct.ll new file mode 100644 index 0000000..b984219 --- /dev/null +++ b/test/teststruct.ll @@ -0,0 +1,13 @@ +%structty = type { int, int } + +{ int, int } { int 4, int 3 } + +implementation + +[[2 x int]] "test function"(int %i0, int %j0) + %array = [[2 x int]] [ + [2 x int] [ int 12, int 52 ] + ] +begin + ret [[2x int]] %array +end |