llgo/x/llgen
This commit is contained in:
@@ -30,6 +30,7 @@ _llgo_2: ; preds = %_llgo_0
|
||||
|
||||
define void @main() {
|
||||
_llgo_0:
|
||||
call void @init()
|
||||
%0 = call i64 @max(i64 1, i64 2)
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ declare void @printf(ptr, ...)
|
||||
|
||||
define void @main() {
|
||||
_llgo_0:
|
||||
call void @init()
|
||||
call void (ptr, ...) @printf(ptr @hello)
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ _llgo_2: ; preds = %_llgo_1, %_llgo_0
|
||||
|
||||
define void @main() {
|
||||
_llgo_0:
|
||||
call void @init()
|
||||
%0 = load i64, ptr @a, align 4
|
||||
%1 = add i64 %0, 1
|
||||
store i64 %1, ptr @a, align 4
|
||||
|
||||
@@ -73,6 +73,10 @@ func funcKind(vfn ssa.Value) int {
|
||||
return fnNormal
|
||||
}
|
||||
|
||||
func isMainFunc(fn *ssa.Function) bool {
|
||||
return fn.Name() == "main" && fn.Pkg.Pkg.Path() == "main"
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type instrAndValue interface {
|
||||
@@ -126,16 +130,21 @@ func (p *context) compileFunc(pkg llssa.Package, f *ssa.Function) {
|
||||
}
|
||||
fn.MakeBlocks(nblk)
|
||||
b := fn.NewBuilder()
|
||||
for _, block := range f.Blocks {
|
||||
p.compileBlock(b, block)
|
||||
isMain := isMainFunc(f)
|
||||
for i, block := range f.Blocks {
|
||||
p.compileBlock(b, block, isMain && i == 0)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock) llssa.BasicBlock {
|
||||
func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, doInit bool) llssa.BasicBlock {
|
||||
ret := p.fn.Block(block.Index)
|
||||
b.SetBlock(ret)
|
||||
p.bvals = make(map[ssa.Value]llssa.Expr)
|
||||
if doInit {
|
||||
fn := p.pkg.FuncOf("init")
|
||||
b.Call(fn.Expr)
|
||||
}
|
||||
for _, instr := range block.Instrs {
|
||||
p.compileInstr(b, instr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user