116 lines
2.6 KiB
Go
116 lines
2.6 KiB
Go
package generator
|
|
|
|
import "testing"
|
|
|
|
func TestValueCastSlicePointer (test *testing.T) {
|
|
testString (test,
|
|
`%"AAAAAAAAAAAAAAAAAAAAAA==::Index" = type i64
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }
|
|
%2 = alloca ptr
|
|
%3 = getelementptr { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }, ptr %1, i32 0, i32 0
|
|
%4 = load ptr, ptr %3
|
|
store ptr %4, ptr %2
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
slice: *:Byte
|
|
pointer: *Byte = [~*Byte slice]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestValueCastIntegerIneffectual (test *testing.T) {
|
|
testString (test,
|
|
`%"0zNZN147MN2wzMAQ6NS2dQ==::A" = type i64
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca i64
|
|
store i64 5, ptr %1
|
|
%2 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::A"
|
|
%3 = load i64, ptr %1
|
|
store i64 %3, ptr %2
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
A: Int
|
|
[main] = {
|
|
x:Int = 5
|
|
y:A = [~A x]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestValueCastStringIneffectual (test *testing.T) {
|
|
testString (test,
|
|
`%"AAAAAAAAAAAAAAAAAAAAAA==::Index" = type i64
|
|
%"AAAAAAAAAAAAAAAAAAAAAA==::String" = type { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }
|
|
%2 = alloca %"AAAAAAAAAAAAAAAAAAAAAA==::String"
|
|
%3 = load { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }, ptr %1
|
|
store { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" } %3, ptr %2
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
y:*:Byte
|
|
x:String = [~String y]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestBitCastStringIneffectual (test *testing.T) {
|
|
testString (test,
|
|
`%"AAAAAAAAAAAAAAAAAAAAAA==::Index" = type i64
|
|
%"AAAAAAAAAAAAAAAAAAAAAA==::String" = type { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }
|
|
%2 = alloca %"AAAAAAAAAAAAAAAAAAAAAA==::String"
|
|
%3 = load { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }, ptr %1
|
|
store { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" } %3, ptr %2
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
y:*:Byte
|
|
x:String = [~~String y]
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestPtrIntCast (test *testing.T) {
|
|
testString (test,
|
|
`%"AAAAAAAAAAAAAAAAAAAAAA==::Index" = type i64
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca ptr
|
|
store ptr zeroinitializer, ptr %1
|
|
%2 = alloca %"AAAAAAAAAAAAAAAAAAAAAA==::Index"
|
|
%3 = load ptr, ptr %1
|
|
%4 = ptrtoint ptr %3 to %"AAAAAAAAAAAAAAAAAAAAAA==::Index"
|
|
%5 = add i64 1, %4
|
|
store i64 %5, ptr %2
|
|
%6 = load %"AAAAAAAAAAAAAAAAAAAAAA==::Index", ptr %2
|
|
%7 = inttoptr %"AAAAAAAAAAAAAAAAAAAAAA==::Index" %6 to ptr
|
|
store ptr %7, ptr %1
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
[main] = {
|
|
ptr:*Byte = nil
|
|
nptr:Index = [+ 1 [~~Index ptr]]
|
|
ptr = [~~*Byte nptr]
|
|
}
|
|
`)
|
|
}
|