2023-11-17 03:04:56 +00:00
|
|
|
package generator
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestType (test *testing.T) {
|
|
|
|
testString (test,
|
2023-11-26 09:02:22 +00:00
|
|
|
`%Index = type i64
|
2023-12-05 08:07:54 +00:00
|
|
|
%String = type { ptr, %Index }
|
2023-11-26 09:02:22 +00:00
|
|
|
%Pegasus = type { ptr, ptr, ptr, ptr, ptr }
|
|
|
|
%Point = type { i64, i64 }
|
|
|
|
%Rectangle = type { %Point, %Point }
|
2023-11-17 03:04:56 +00:00
|
|
|
%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 }
|
2023-11-26 09:02:22 +00:00
|
|
|
%AllFloats = type { float, double }
|
2023-12-05 08:07:54 +00:00
|
|
|
%Path = type { ptr, %Index }
|
2023-11-17 03:04:56 +00:00
|
|
|
%Quadrangle = type [4 x %Point]
|
2023-11-26 09:02:22 +00:00
|
|
|
%AllTypes = type { %String, %Pegasus, %Rectangle, %AllInts, %AllFloats, %Path, %Quadrangle }
|
|
|
|
declare %AllTypes @x()
|
2023-11-17 03:04:56 +00:00
|
|
|
`,
|
|
|
|
`
|
|
|
|
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
|
2023-11-21 20:04:22 +00:00
|
|
|
u64:U64)
|
2023-11-17 03:04:56 +00:00
|
|
|
AllFloats: (
|
|
|
|
f32:F32
|
|
|
|
f64:F64)
|
|
|
|
Path: *:Point
|
|
|
|
Quadrangle: 4:Point
|
2023-11-26 09:02:22 +00:00
|
|
|
AllTypes: (
|
|
|
|
string:String
|
|
|
|
pegasus:Pegasus
|
|
|
|
rectangle:Rectangle
|
|
|
|
ints:AllInts
|
|
|
|
floats:AllFloats
|
|
|
|
path:Path
|
|
|
|
quadrangle:Quadrangle
|
|
|
|
)
|
|
|
|
[x]:AllTypes
|
2023-11-17 03:04:56 +00:00
|
|
|
`)
|
|
|
|
}
|
2023-12-25 03:49:10 +00:00
|
|
|
|
|
|
|
func TestSameTypeDifferentName (test *testing.T) {
|
|
|
|
testString (test,
|
|
|
|
`%A = type ptr
|
|
|
|
%B = type ptr
|
|
|
|
%C = type ptr
|
|
|
|
define void @main() {
|
|
|
|
0:
|
|
|
|
%1 = alloca %A
|
2024-01-27 17:35:33 +00:00
|
|
|
%2 = alloca %B
|
|
|
|
%3 = alloca %C
|
2023-12-25 03:49:10 +00:00
|
|
|
ret void
|
2024-01-25 07:36:51 +00:00
|
|
|
}
|
2023-12-25 03:49:10 +00:00
|
|
|
`,
|
|
|
|
`
|
|
|
|
A: *Byte
|
|
|
|
B: *Byte
|
|
|
|
C: *Byte
|
|
|
|
[main] = {
|
|
|
|
a:A b:B c:C
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
2024-01-25 17:56:20 +00:00
|
|
|
|
|
|
|
func TestChainedTypedef (test *testing.T) {
|
|
|
|
testString (test,
|
|
|
|
`%A = type ptr
|
|
|
|
%B = type %A
|
|
|
|
%C = type %B
|
|
|
|
define void @main() {
|
|
|
|
0:
|
|
|
|
%1 = alloca %A
|
2024-01-27 17:35:33 +00:00
|
|
|
%2 = alloca %B
|
|
|
|
%3 = alloca %C
|
2024-01-25 17:56:20 +00:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
`
|
|
|
|
A: *Byte
|
|
|
|
B: A
|
|
|
|
C: B
|
|
|
|
[main] = {
|
|
|
|
a:A b:B c:C
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|
2024-01-25 18:19:34 +00:00
|
|
|
|
|
|
|
func TestChainedTypedefGetElementPtr (test *testing.T) {
|
|
|
|
testString (test,
|
|
|
|
`%A = type { i64 }
|
|
|
|
%B = type %A
|
|
|
|
define void @main() {
|
|
|
|
0:
|
|
|
|
%1 = alloca %B
|
2024-01-27 17:35:33 +00:00
|
|
|
%2 = getelementptr { i64 }, ptr %1, i32 0, i32 0
|
|
|
|
store i64 5, ptr %2
|
2024-01-25 18:19:34 +00:00
|
|
|
ret void
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
`
|
|
|
|
A: (x:Int)
|
|
|
|
B: A
|
|
|
|
[main] = {
|
|
|
|
b:B
|
|
|
|
b.x = 5
|
|
|
|
}
|
|
|
|
`)
|
|
|
|
}
|