Add match/union generator tests
This commit is contained in:
parent
c5e5b37e45
commit
9611e5ca72
@ -156,3 +156,113 @@ testString (test,
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
func TestMatch (test *testing.T) {
|
||||
testString (test,
|
||||
`%"0zNZN147MN2wzMAQ6NS2dQ==::U" = type { i64, i64 }
|
||||
define i64 @"0zNZN147MN2wzMAQ6NS2dQ==::matchToInt"(%"0zNZN147MN2wzMAQ6NS2dQ==::U" %u) {
|
||||
0:
|
||||
%1 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::U"
|
||||
store %"0zNZN147MN2wzMAQ6NS2dQ==::U" %u, ptr %1
|
||||
%2 = alloca i64
|
||||
%3 = alloca double
|
||||
%4 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %1, i32 0, i32 0
|
||||
%5 = load i64, ptr %4
|
||||
switch i64 %5, label %6 [
|
||||
i64 7620767046192759206, label %8
|
||||
i64 9186060094042213285, label %12
|
||||
]
|
||||
6:
|
||||
%7 = phi i64 [ %11, %8 ], [ %16, %12 ], [ zeroinitializer, %0 ]
|
||||
ret i64 %7
|
||||
8:
|
||||
%9 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %1, i32 0, i32 1
|
||||
%10 = load i64, ptr %9
|
||||
store i64 %10, ptr %2
|
||||
%11 = load i64, ptr %2
|
||||
br label %6
|
||||
12:
|
||||
%13 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %1, i32 0, i32 1
|
||||
%14 = load double, ptr %13
|
||||
store double %14, ptr %3
|
||||
%15 = load double, ptr %3
|
||||
%16 = fptosi double %15 to i64
|
||||
br label %6
|
||||
}
|
||||
`,
|
||||
`
|
||||
U: (| Int F64)
|
||||
[matchToInt u:U]:Int = match u in
|
||||
| u:Int u
|
||||
| u:F64 [~Int u]
|
||||
`)
|
||||
}
|
||||
|
||||
func TestMatchUnionUnderComplete (test *testing.T) {
|
||||
testString (test,
|
||||
`%"0zNZN147MN2wzMAQ6NS2dQ==::U" = type { i64, i64 }
|
||||
%"AAAAAAAAAAAAAAAAAAAAAA==::Index" = type i64
|
||||
%"AAAAAAAAAAAAAAAAAAAAAA==::String" = type { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }
|
||||
define void @"0zNZN147MN2wzMAQ6NS2dQ==::matchToInt"(%"0zNZN147MN2wzMAQ6NS2dQ==::U" %u) {
|
||||
0:
|
||||
%1 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::U"
|
||||
store %"0zNZN147MN2wzMAQ6NS2dQ==::U" %u, ptr %1
|
||||
%2 = alloca i64
|
||||
%3 = alloca %"AAAAAAAAAAAAAAAAAAAAAA==::String"
|
||||
%4 = alloca [3 x i8]
|
||||
%5 = alloca double
|
||||
%6 = alloca %"AAAAAAAAAAAAAAAAAAAAAA==::String"
|
||||
%7 = alloca [3 x i8]
|
||||
%8 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %1, i32 0, i32 0
|
||||
%9 = load i64, ptr %8
|
||||
switch i64 %9, label %10 [
|
||||
i64 7620767046192759206, label %11
|
||||
i64 9186060094042213285, label %20
|
||||
]
|
||||
10:
|
||||
ret void
|
||||
11:
|
||||
%12 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %1, i32 0, i32 1
|
||||
%13 = load i64, ptr %12
|
||||
store i64 %13, ptr %2
|
||||
%14 = getelementptr [3 x i8], ptr %4, i32 0, i32 0
|
||||
store i8 73, ptr %14
|
||||
%15 = getelementptr [3 x i8], ptr %4, i32 0, i32 1
|
||||
store i8 110, ptr %15
|
||||
%16 = getelementptr [3 x i8], ptr %4, i32 0, i32 2
|
||||
store i8 116, ptr %16
|
||||
%17 = getelementptr %"AAAAAAAAAAAAAAAAAAAAAA==::String", ptr %3, i32 0, i32 0
|
||||
store ptr %4, ptr %17
|
||||
%18 = getelementptr %"AAAAAAAAAAAAAAAAAAAAAA==::String", ptr %3, i32 0, i32 1
|
||||
store %"AAAAAAAAAAAAAAAAAAAAAA==::Index" 3, ptr %18
|
||||
%19 = load %"AAAAAAAAAAAAAAAAAAAAAA==::String", ptr %3
|
||||
call void @"0zNZN147MN2wzMAQ6NS2dQ==::print"(%"AAAAAAAAAAAAAAAAAAAAAA==::String" %19)
|
||||
br label %10
|
||||
20:
|
||||
%21 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %1, i32 0, i32 1
|
||||
%22 = load double, ptr %21
|
||||
store double %22, ptr %5
|
||||
%23 = getelementptr [3 x i8], ptr %7, i32 0, i32 0
|
||||
store i8 70, ptr %23
|
||||
%24 = getelementptr [3 x i8], ptr %7, i32 0, i32 1
|
||||
store i8 54, ptr %24
|
||||
%25 = getelementptr [3 x i8], ptr %7, i32 0, i32 2
|
||||
store i8 52, ptr %25
|
||||
%26 = getelementptr %"AAAAAAAAAAAAAAAAAAAAAA==::String", ptr %6, i32 0, i32 0
|
||||
store ptr %7, ptr %26
|
||||
%27 = getelementptr %"AAAAAAAAAAAAAAAAAAAAAA==::String", ptr %6, i32 0, i32 1
|
||||
store %"AAAAAAAAAAAAAAAAAAAAAA==::Index" 3, ptr %27
|
||||
%28 = load %"AAAAAAAAAAAAAAAAAAAAAA==::String", ptr %6
|
||||
call void @"0zNZN147MN2wzMAQ6NS2dQ==::print"(%"AAAAAAAAAAAAAAAAAAAAAA==::String" %28)
|
||||
br label %10
|
||||
}
|
||||
declare void @"0zNZN147MN2wzMAQ6NS2dQ==::print"(%"AAAAAAAAAAAAAAAAAAAAAA==::String" %str)
|
||||
`,
|
||||
`
|
||||
U: (| Int F64 UInt)
|
||||
[print str:String]
|
||||
[matchToInt u:U] = match u in
|
||||
| u:Int [print 'Int']
|
||||
| u:F64 [print 'F64']
|
||||
`)
|
||||
}
|
||||
|
48
generator/union_test.go
Normal file
48
generator/union_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package generator
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestAssignmentUnion (test *testing.T) {
|
||||
testString (test,
|
||||
`%"0zNZN147MN2wzMAQ6NS2dQ==::U" = type { i64, i64 }
|
||||
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
||||
0:
|
||||
%1 = alloca double
|
||||
store double 0x401ECCCCCCCCCCCD, ptr %1
|
||||
%2 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::U"
|
||||
%3 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %2, i32 0, i32 0
|
||||
%4 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %2, i32 0, i32 1
|
||||
store i64 9186060094042213285, ptr %3
|
||||
%5 = load double, ptr %1
|
||||
store double %5, ptr %4
|
||||
%6 = load %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %2
|
||||
ret void
|
||||
}
|
||||
`,
|
||||
`
|
||||
U: (| Int F64)
|
||||
[main] = {
|
||||
x:F64 = 7.7
|
||||
y:U = x
|
||||
}
|
||||
`)}
|
||||
|
||||
func TestAssignmentUnionToUnion (test *testing.T) {
|
||||
testString (test,
|
||||
`%"0zNZN147MN2wzMAQ6NS2dQ==::U" = type { i64, i64 }
|
||||
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
||||
0:
|
||||
%1 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::U"
|
||||
%2 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::U"
|
||||
%3 = load %"0zNZN147MN2wzMAQ6NS2dQ==::U", ptr %2
|
||||
store %"0zNZN147MN2wzMAQ6NS2dQ==::U" %3, ptr %1
|
||||
ret void
|
||||
}
|
||||
`,
|
||||
`
|
||||
U: (| Int F64)
|
||||
[main] = {
|
||||
x:U y:U
|
||||
x = y
|
||||
}
|
||||
`)}
|
Loading…
Reference in New Issue
Block a user