-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.go
53 lines (42 loc) · 1.04 KB
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"github.com/llir/llvm/ir"
"github.com/llir/llvm/ir/constant"
"github.com/llir/llvm/ir/types"
)
//int g = 2;
//
//int add(int x, int y) {
//return x + y;
//}
//int main() {
//return add(1, g);
//}
func hello(a int) int {
return a + 1
}
var b = hello(12)
var a = b + 56
func main() {
m := ir.NewModule()
//globalG := m.NewGlobalDef("g", constant.NewInt(types.I32, 2))
funcAdd := m.NewFunc("add", types.I32,
ir.NewParam("x", types.I32),
ir.NewParam("y", types.I32),
)
ab := funcAdd.NewBlock("")
ab.NewRet(ab.NewAdd(funcAdd.Params[0], funcAdd.Params[1]))
funcMain := m.NewFunc(
"main",
types.I32,
) // omit parameters
mb := funcMain.NewBlock("") // llir/llvm would give correct default name for block without name
//var ld = mb.NewLoad(types.I32, globalG)
//fmt.Println(ld)
//ld.SetName("xxxx")
//mb.NewStore(constant.NewInt(types.I32, 100), ld)
var loc = mb.NewAlloca(types.I32)
var loc2 = mb.NewLoad(types.I32, loc)
mb.NewRet(mb.NewCall(funcAdd, constant.NewInt(types.I32, 1), loc2))
println(m.String())
}