159 lines
1.9 KiB
Go
159 lines
1.9 KiB
Go
package generator
|
|
|
|
import "testing"
|
|
|
|
func TestBranchAssign (test *testing.T) {
|
|
testString (test,
|
|
`define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca i64
|
|
br i1 true, label %2, label %4
|
|
2:
|
|
store i64 5, ptr %1
|
|
br label %3
|
|
3:
|
|
ret void
|
|
4:
|
|
store i64 6, ptr %1
|
|
br label %3
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
x:Int
|
|
if true then {
|
|
x = 5
|
|
} else {
|
|
x = 6
|
|
}
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestBranchAssignNoFalse (test *testing.T) {
|
|
testString (test,
|
|
`define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca i64
|
|
br i1 true, label %2, label %3
|
|
2:
|
|
store i64 5, ptr %1
|
|
br label %3
|
|
3:
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
x:Int
|
|
if true then {
|
|
x = 5
|
|
}
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestBranchResult (test *testing.T) {
|
|
testString (test,
|
|
`define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca i64
|
|
br i1 true, label %2, label %5
|
|
2:
|
|
br label %3
|
|
3:
|
|
%4 = phi i64 [ 5, %2 ], [ 6, %5 ]
|
|
store i64 %4, ptr %1
|
|
ret void
|
|
5:
|
|
br label %3
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
x:Int = if true then 5 else 6
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestLoop (test *testing.T) {
|
|
testString (test,
|
|
`define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
br label %1
|
|
1:
|
|
br label %1
|
|
2:
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
loop {
|
|
|
|
}
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestLoopResult (test *testing.T) {
|
|
testString (test,
|
|
`define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca i64
|
|
br label %2
|
|
2:
|
|
br label %3
|
|
3:
|
|
store i64 5, ptr %1
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
x:Int = loop {
|
|
[break 5]
|
|
}
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestLoopBranchResult (test *testing.T) {
|
|
testString (test,
|
|
`define i64 @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca i64
|
|
store i64 6, ptr %1
|
|
br label %2
|
|
2:
|
|
%3 = load i64, ptr %1
|
|
%4 = icmp slt i64 %3, 3
|
|
br i1 %4, label %5, label %8
|
|
5:
|
|
%6 = load i64, ptr %1
|
|
br label %11
|
|
7:
|
|
br label %2
|
|
8:
|
|
%9 = load i64, ptr %1
|
|
%10 = sub i64 %9, 1
|
|
store i64 %10, ptr %1
|
|
br label %7
|
|
11:
|
|
ret i64 %6
|
|
}
|
|
`,
|
|
`
|
|
[main]:Int = {
|
|
y:Int = 6
|
|
loop {
|
|
if [< y 3]
|
|
then [break y]
|
|
else {
|
|
y = [-- y]
|
|
}
|
|
}
|
|
}
|
|
`)
|
|
}
|