fspl/generator/type_test.go

132 lines
1.9 KiB
Go

package generator
import "testing"
func TestType (test *testing.T) {
testString (test,
`%Index = type i64
%String = type { ptr, %Index }
%Pegasus = type { ptr, ptr, ptr, ptr, ptr }
%Point = type { i64, i64 }
%Rectangle = type { %Point, %Point }
%Bool = type i8
%Byte = type i8
%Rune = type i32
%AllInts = type { %Bool, %Byte, %Index, %Rune, i64, i64, i8, i16, i32, i64, i8, i16, i32, i64 }
%AllFloats = type { float, double }
%Path = type { ptr, %Index }
%Quadrangle = type [4 x %Point]
%AllTypes = type { %String, %Pegasus, %Rectangle, %AllInts, %AllFloats, %Path, %Quadrangle }
declare %AllTypes @x()
`,
`
Point: (.x:Int y:Int)
Pegasus: (~
[clear clouds:*:Point]
[fly rings:*:Point]
[fall distance:Int]
[complete]:Bool)
Rectangle: (.
min:Point
max:Point)
AllInts: (.
bool:Bool
byte:Byte
index:Index
rune:Rune
word:Int
uword:UInt
i8:I8
i16:I16
i32:I32
i64:I64
u8:U8
u16:U16
u32:U32
u64:U64)
AllFloats: (.
f32:F32
f64:F64)
Path: *:Point
Quadrangle: 4:Point
AllTypes: (.
string:String
pegasus:Pegasus
rectangle:Rectangle
ints:AllInts
floats:AllFloats
path:Path
quadrangle:Quadrangle
)
[x]:AllTypes
`)
}
func TestSameTypeDifferentName (test *testing.T) {
testString (test,
`%A = type ptr
%B = type ptr
%C = type ptr
define void @main() {
0:
%1 = alloca %A
%2 = alloca %B
%3 = alloca %C
ret void
}
`,
`
A: *Byte
B: *Byte
C: *Byte
[main] = {
a:A b:B c:C
}
`)
}
func TestChainedTypedef (test *testing.T) {
testString (test,
`%A = type ptr
%B = type %A
%C = type %B
define void @main() {
0:
%1 = alloca %A
%2 = alloca %B
%3 = alloca %C
ret void
}
`,
`
A: *Byte
B: A
C: B
[main] = {
a:A b:B c:C
}
`)
}
func TestChainedTypedefGetElementPtr (test *testing.T) {
testString (test,
`%A = type { i64 }
%B = type %A
define void @main() {
0:
%1 = alloca %B
%2 = getelementptr %B, ptr %1, i32 0, i32 0
store i64 5, ptr %2
ret void
}
`,
`
A: (.x:Int)
B: A
[main] = {
b:B
b.x = 5
}
`)
}