130 lines
2.8 KiB
Go
130 lines
2.8 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]
|
|
}
|
|
`)
|
|
}
|
|
|
|
// TODO: Perhaps run all generator output in these tests through llc to check the
|
|
// integrity of the IR.
|
|
|
|
// TODO: uncomment and complete once bitcasting is fully supported
|
|
// func TestBitCastPointer (test *testing.T) {
|
|
// testString (test,
|
|
// `
|
|
// `,
|
|
// `
|
|
// Struct: (. x:Int y:Int)
|
|
// Array: 4:Int
|
|
// [main] = {
|
|
// ptr:*Byte
|
|
// stc:Struct
|
|
// arr:Array
|
|
// str:String
|
|
// flt:F64
|
|
// idx:Index
|
|
//
|
|
// ; struct
|
|
// ptr = [~~*Byte [~~Struct ptr]]
|
|
// stc = [~~Struct [~~*Byte stc]]
|
|
// ; array
|
|
// ptr = [~~*Byte [~~Array ptr]]
|
|
// arr = [~~Array [~~*Byte arr]]
|
|
// ; slice
|
|
// ptr = [~~*Byte [~~String ptr]]
|
|
// str = [~~String [~~*Byte str]]
|
|
// ; int
|
|
// ptr = [~~*Byte [~~Index ptr]]
|
|
// idx = [~~Index [~~*Byte idx]]
|
|
// ; float
|
|
// ptr = [~~*Byte [~~F64 ptr]]
|
|
// flt = [~~F64 [~~*Byte flt]]
|
|
//
|
|
// ; arithmetic
|
|
// ptr = [~~*Byte [+ 1 [~~Index ptr]]]
|
|
// }
|
|
// `)
|
|
// }
|