166 lines
4.3 KiB
Go
166 lines
4.3 KiB
Go
package generator
|
|
|
|
import "testing"
|
|
|
|
func TestType (test *testing.T) {
|
|
testString (test,
|
|
`%"AAAAAAAAAAAAAAAAAAAAAA==::Index" = type i64
|
|
%"AAAAAAAAAAAAAAAAAAAAAA==::String" = type { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::Pegasus" = type { ptr, ptr, ptr, ptr, ptr }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::Point" = type { i64, i64 }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::Rectangle" = type { %"0zNZN147MN2wzMAQ6NS2dQ==::Point", %"0zNZN147MN2wzMAQ6NS2dQ==::Point" }
|
|
%"AAAAAAAAAAAAAAAAAAAAAA==::Bool" = type i1
|
|
%"AAAAAAAAAAAAAAAAAAAAAA==::Byte" = type i8
|
|
%"AAAAAAAAAAAAAAAAAAAAAA==::Rune" = type i32
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::AllInts" = type { %"AAAAAAAAAAAAAAAAAAAAAA==::Bool", %"AAAAAAAAAAAAAAAAAAAAAA==::Byte", %"AAAAAAAAAAAAAAAAAAAAAA==::Index", %"AAAAAAAAAAAAAAAAAAAAAA==::Rune", i64, i64, i8, i16, i32, i64, i8, i16, i32, i64 }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::AllFloats" = type { float, double }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::Path" = type { ptr, %"AAAAAAAAAAAAAAAAAAAAAA==::Index" }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::Quadrangle" = type [4 x %"0zNZN147MN2wzMAQ6NS2dQ==::Point"]
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::AllTypes" = type { %"AAAAAAAAAAAAAAAAAAAAAA==::String", %"0zNZN147MN2wzMAQ6NS2dQ==::Pegasus", %"0zNZN147MN2wzMAQ6NS2dQ==::Rectangle", %"0zNZN147MN2wzMAQ6NS2dQ==::AllInts", %"0zNZN147MN2wzMAQ6NS2dQ==::AllFloats", %"0zNZN147MN2wzMAQ6NS2dQ==::Path", %"0zNZN147MN2wzMAQ6NS2dQ==::Quadrangle" }
|
|
declare %"0zNZN147MN2wzMAQ6NS2dQ==::AllTypes" @"0zNZN147MN2wzMAQ6NS2dQ==::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,
|
|
`%"0zNZN147MN2wzMAQ6NS2dQ==::A" = type ptr
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::B" = type ptr
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::C" = type ptr
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::A"
|
|
%2 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::B"
|
|
%3 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::C"
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
A: *Byte
|
|
B: *Byte
|
|
C: *Byte
|
|
[main] = {
|
|
a:A b:B c:C
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestChainedTypedef (test *testing.T) {
|
|
testString (test,
|
|
`%"0zNZN147MN2wzMAQ6NS2dQ==::A" = type ptr
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::B" = type %"0zNZN147MN2wzMAQ6NS2dQ==::A"
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::C" = type %"0zNZN147MN2wzMAQ6NS2dQ==::B"
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::A"
|
|
%2 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::B"
|
|
%3 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::C"
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
A: *Byte
|
|
B: A
|
|
C: B
|
|
[main] = {
|
|
a:A b:B c:C
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestChainedTypedefGetElementPtr (test *testing.T) {
|
|
testString (test,
|
|
`%"0zNZN147MN2wzMAQ6NS2dQ==::A" = type { i64 }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::B" = type %"0zNZN147MN2wzMAQ6NS2dQ==::A"
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::B"
|
|
%2 = getelementptr %"0zNZN147MN2wzMAQ6NS2dQ==::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
|
|
}
|
|
`)
|
|
}
|
|
|
|
func TestTypeUnion (test *testing.T) {
|
|
testString (test,
|
|
`%"0zNZN147MN2wzMAQ6NS2dQ==::U" = type { i64, i64 }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::SmallU" = type { i64, i16 }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::Padded" = type { i8, i16 }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::PaddedU" = type { i64, i32 }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::Point" = type { i64, i64 }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::Error" = type { ptr, ptr }
|
|
%"0zNZN147MN2wzMAQ6NS2dQ==::PointOrError" = type { i64, i128 }
|
|
define void @"0zNZN147MN2wzMAQ6NS2dQ==::main"() {
|
|
0:
|
|
%1 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::U"
|
|
%2 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::SmallU"
|
|
%3 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::PaddedU"
|
|
%4 = alloca %"0zNZN147MN2wzMAQ6NS2dQ==::PointOrError"
|
|
ret void
|
|
}
|
|
`,
|
|
`
|
|
U: (| I8 I16 I32 I64 Int)
|
|
SmallU: (| I8 U8 I16 U16)
|
|
Point: (. x:Int y:Int)
|
|
Padded: (. a:I8 b:I16)
|
|
PaddedU: (| Padded)
|
|
Error: (& [error]:String)
|
|
PointOrError: (| Point Error)
|
|
[main] = {
|
|
u:U
|
|
su:SmallU
|
|
pu:PaddedU
|
|
pe:PointOrError
|
|
}
|
|
`)}
|