101 lines
1.7 KiB
Go
101 lines
1.7 KiB
Go
package generator
|
|
|
|
import "testing"
|
|
|
|
func TestPrintDigit (test *testing.T) {
|
|
testString (test,
|
|
`%Byte = type i8
|
|
%Index = type i64
|
|
define void @printDigit(%Byte %digit) {
|
|
0:
|
|
%1 = alloca %Byte
|
|
store %Byte %digit, ptr %1
|
|
%2 = load %Byte, ptr %1
|
|
%3 = alloca i8
|
|
store i8 48, ptr %3
|
|
%4 = load %Byte, ptr %3
|
|
%5 = add %Byte %2, %4
|
|
store %Byte %5, ptr %1
|
|
%6 = call %Index @write(i32 1, ptr %1, i64 1)
|
|
ret void
|
|
}
|
|
declare %Index @write(i32 %file, ptr %buffer, %Index %count)
|
|
`,
|
|
`
|
|
[write file:I32 buffer:*Byte count:Index]: Index
|
|
|
|
[printDigit digit:Byte] = {
|
|
digit = [+ digit '0']
|
|
[write 1 [@digit] 1]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestSignedUnsignedDivision (test *testing.T) {
|
|
testString (test,
|
|
`define void @main() {
|
|
0:
|
|
%1 = sdiv i64 20, -5
|
|
%2 = alloca i64
|
|
store i64 %1, ptr %2
|
|
%3 = sdiv i64 15, 3
|
|
%4 = alloca i64
|
|
store i64 %3, ptr %4
|
|
%5 = srem i64 7, 3
|
|
%6 = alloca i64
|
|
store i64 %5, ptr %6
|
|
%7 = udiv i64 20, 5
|
|
%8 = alloca i64
|
|
store i64 %7, ptr %8
|
|
%9 = udiv i64 15, 3
|
|
%10 = alloca i64
|
|
store i64 %9, ptr %10
|
|
%11 = urem i64 7, 3
|
|
%12 = alloca i64
|
|
store i64 %11, ptr %12
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
a:Int = [/ 20 -5]
|
|
b:Int = [/ 15 3]
|
|
c:Int = [% 7 3]
|
|
|
|
d:UInt = [/ 20 5]
|
|
e:UInt = [/ 15 3]
|
|
f:UInt = [% 7 3]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestCompare (test *testing.T) {
|
|
testString (test,
|
|
`%Bool = type i8
|
|
define %Bool @main() {
|
|
0:
|
|
%1 = alloca i64
|
|
store i64 32, ptr %1
|
|
%2 = load i64, ptr %1
|
|
%3 = icmp sgt i64 %2, 1
|
|
%4 = alloca %Bool
|
|
store i1 %3, ptr %4
|
|
%5 = load i64, ptr %1
|
|
%6 = icmp slt i64 0, %5
|
|
%7 = icmp slt i1 %6, 50
|
|
store i1 %7, ptr %4
|
|
%8 = load i64, ptr %1
|
|
%9 = icmp eq i64 32, %8
|
|
ret i1 %9
|
|
}
|
|
`,
|
|
`
|
|
[main]:Bool = {
|
|
x:Int = 32
|
|
b:Bool = [> x 1]
|
|
b = [< 0 x 50]
|
|
[= 32 x]
|
|
}
|
|
`)
|
|
}
|