fspl/generator/literal_test.go

195 lines
5.8 KiB
Go

package generator
import "testing"
func TestLiteral (test *testing.T) {
testString (test,
`%Byte = type i8
%Rune = type i32
%Index = type i64
%String = type { ptr, %Index }
define void @main() {
0:
%1 = alloca i64
store i64 382, ptr %1
%2 = alloca i64
store i64 -4392, ptr %2
%3 = alloca %Byte
store i8 128, ptr %3
%4 = alloca i8
store i8 -127, ptr %4
%5 = alloca i8
store i8 104, ptr %5
%6 = load %Byte, ptr %5
%7 = alloca %Byte
store %Byte %6, ptr %7
%8 = alloca i32
store i32 48, ptr %8
%9 = load %Rune, ptr %8
%10 = alloca %Rune
store %Rune %9, ptr %10
%11 = alloca [5 x i8]
%12 = getelementptr [5 x i8], ptr %11, i32 0, i32 0
store i8 104, ptr %12
%13 = getelementptr [5 x i8], ptr %11, i32 0, i32 1
store i8 101, ptr %13
%14 = getelementptr [5 x i8], ptr %11, i32 0, i32 2
store i8 108, ptr %14
%15 = getelementptr [5 x i8], ptr %11, i32 0, i32 3
store i8 108, ptr %15
%16 = getelementptr [5 x i8], ptr %11, i32 0, i32 4
store i8 111, ptr %16
%17 = load [5 x %Byte], ptr %11
%18 = alloca [5 x %Byte]
store [5 x %Byte] %17, ptr %18
%19 = alloca [5 x i32]
%20 = getelementptr [5 x i32], ptr %19, i32 0, i32 0
store i32 104, ptr %20
%21 = getelementptr [5 x i32], ptr %19, i32 0, i32 1
store i32 101, ptr %21
%22 = getelementptr [5 x i32], ptr %19, i32 0, i32 2
store i32 108, ptr %22
%23 = getelementptr [5 x i32], ptr %19, i32 0, i32 3
store i32 108, ptr %23
%24 = getelementptr [5 x i32], ptr %19, i32 0, i32 4
store i32 111, ptr %24
%25 = load [5 x %Rune], ptr %19
%26 = alloca [5 x %Rune]
store [5 x %Rune] %25, ptr %26
%27 = alloca [11 x i8]
%28 = getelementptr [11 x i8], ptr %27, i32 0, i32 0
store i8 104, ptr %28
%29 = getelementptr [11 x i8], ptr %27, i32 0, i32 1
store i8 101, ptr %29
%30 = getelementptr [11 x i8], ptr %27, i32 0, i32 2
store i8 108, ptr %30
%31 = getelementptr [11 x i8], ptr %27, i32 0, i32 3
store i8 108, ptr %31
%32 = getelementptr [11 x i8], ptr %27, i32 0, i32 4
store i8 111, ptr %32
%33 = getelementptr [11 x i8], ptr %27, i32 0, i32 5
store i8 32, ptr %33
%34 = getelementptr [11 x i8], ptr %27, i32 0, i32 6
store i8 119, ptr %34
%35 = getelementptr [11 x i8], ptr %27, i32 0, i32 7
store i8 111, ptr %35
%36 = getelementptr [11 x i8], ptr %27, i32 0, i32 8
store i8 114, ptr %36
%37 = getelementptr [11 x i8], ptr %27, i32 0, i32 9
store i8 108, ptr %37
%38 = getelementptr [11 x i8], ptr %27, i32 0, i32 10
store i8 100, ptr %38
%39 = alloca { ptr, %Index }
%40 = getelementptr { ptr, %Index }, ptr %39, i32 0, i32 0
store ptr %27, ptr %40
%41 = getelementptr { ptr, %Index }, ptr %39, i32 0, i32 1
store %Index 11, ptr %41
%42 = load %String, ptr %39
%43 = alloca %String
store %String %42, ptr %43
%44 = alloca [12 x i8]
%45 = getelementptr [12 x i8], ptr %44, i32 0, i32 0
store i8 104, ptr %45
%46 = getelementptr [12 x i8], ptr %44, i32 0, i32 1
store i8 101, ptr %46
%47 = getelementptr [12 x i8], ptr %44, i32 0, i32 2
store i8 108, ptr %47
%48 = getelementptr [12 x i8], ptr %44, i32 0, i32 3
store i8 108, ptr %48
%49 = getelementptr [12 x i8], ptr %44, i32 0, i32 4
store i8 111, ptr %49
%50 = getelementptr [12 x i8], ptr %44, i32 0, i32 5
store i8 32, ptr %50
%51 = getelementptr [12 x i8], ptr %44, i32 0, i32 6
store i8 119, ptr %51
%52 = getelementptr [12 x i8], ptr %44, i32 0, i32 7
store i8 111, ptr %52
%53 = getelementptr [12 x i8], ptr %44, i32 0, i32 8
store i8 114, ptr %53
%54 = getelementptr [12 x i8], ptr %44, i32 0, i32 9
store i8 108, ptr %54
%55 = getelementptr [12 x i8], ptr %44, i32 0, i32 10
store i8 100, ptr %55
%56 = getelementptr [12 x i8], ptr %44, i32 0, i32 11
store i8 0, ptr %56
%57 = alloca ptr
store ptr %44, ptr %57
%58 = load ptr, ptr %57
%59 = alloca ptr
store ptr %58, ptr %59
%60 = alloca [5 x i64]
%61 = getelementptr [5 x i64], ptr %60, i32 0, i32 0
store i64 1, ptr %61
%62 = getelementptr [5 x i64], ptr %60, i32 0, i32 1
store i64 2, ptr %62
%63 = getelementptr [5 x i64], ptr %60, i32 0, i32 2
store i64 3, ptr %63
%64 = getelementptr [5 x i64], ptr %60, i32 0, i32 3
store i64 4, ptr %64
%65 = getelementptr [5 x i64], ptr %60, i32 0, i32 4
store i64 5, ptr %65
%66 = load [5 x i64], ptr %60
%67 = alloca [5 x i64]
store [5 x i64] %66, ptr %67
%68 = alloca [5 x i64]
%69 = getelementptr [5 x i64], ptr %68, i32 0, i32 0
store i64 1, ptr %69
%70 = getelementptr [5 x i64], ptr %68, i32 0, i32 1
store i64 2, ptr %70
%71 = getelementptr [5 x i64], ptr %68, i32 0, i32 2
store i64 3, ptr %71
%72 = getelementptr [5 x i64], ptr %68, i32 0, i32 3
store i64 4, ptr %72
%73 = getelementptr [5 x i64], ptr %68, i32 0, i32 4
store i64 5, ptr %73
%74 = alloca { ptr, %Index }
%75 = getelementptr { ptr, %Index }, ptr %74, i32 0, i32 0
store ptr %68, ptr %75
%76 = getelementptr { ptr, %Index }, ptr %74, i32 0, i32 1
store %Index 5, ptr %76
%77 = load { ptr, %Index }, ptr %74
%78 = alloca { ptr, %Index }
store { ptr, %Index } %77, ptr %78
%79 = alloca { i64, { i64, i64 } }
%80 = getelementptr { i64, { i64, i64 } }, ptr %79, i32 0, i32 0
store i64 1, ptr %80
%81 = alloca { i64, i64 }
%82 = getelementptr { i64, i64 }, ptr %81, i32 0, i32 0
store i64 2, ptr %82
%83 = getelementptr { i64, i64 }, ptr %81, i32 0, i32 1
store i64 3, ptr %83
%84 = load { i64, i64 }, ptr %81
%85 = getelementptr { i64, { i64, i64 } }, ptr %79, i32 0, i32 1
store { i64, i64 } %84, ptr %85
%86 = load { i64, { i64, i64 } }, ptr %79
%87 = alloca { i64, { i64, i64 } }
store { i64, { i64, i64 } } %86, ptr %87
ret void
}
`,
`
[main] = {
; integers
ia:Int = 382
ib:Int = -4392
ic:Byte = 128
id:I8 = -127
; strings
sa:Byte = 'h'
sb:Rune = '0'
sc:5:Byte = 'hello'
sd:5:Rune = 'hello'
se:String = 'hello world'
sf:*Byte = 'hello world'
; arrays
aa:5:Int = (* 1 2 3 4 5)
ab:*:Int = (* 1 2 3 4 5)
; structs
ta:(x:Int y:(z:Int a:Int)) = (x: 1 y: (z: 2 a: 3))
}
`)
}