AfterInit: init
This commit is contained in:
@@ -30,25 +30,44 @@ import (
|
||||
|
||||
// abiBasic returns the abi type of the specified basic kind.
|
||||
func (b Builder) abiBasic(t *types.Basic) Expr {
|
||||
name := abi.BasicName(t)
|
||||
g := b.Pkg.NewVarFrom(name, b.Prog.AbiTypePtrPtr())
|
||||
return b.Load(g.Expr)
|
||||
/*
|
||||
TODO(xsw):
|
||||
name := abi.BasicName(t)
|
||||
g := b.Pkg.NewVarFrom(name, b.Prog.AbiTypePtrPtr())
|
||||
return b.Load(g.Expr)
|
||||
*/
|
||||
return b.InlineCall(b.Pkg.rtFunc("Basic"), b.Prog.Val(int(t.Kind())))
|
||||
}
|
||||
|
||||
// abiStruct returns the abi type of the specified struct type.
|
||||
func (b Builder) abiStruct(t *types.Struct) Expr {
|
||||
pkg := b.Pkg
|
||||
name, _ := pkg.abi.StructName(t)
|
||||
name, private := pkg.abi.StructName(t)
|
||||
g := pkg.VarOf(name)
|
||||
if g == nil {
|
||||
prog := b.Prog
|
||||
g = pkg.doNewVar(name, prog.AbiTypePtrPtr())
|
||||
g.Init(prog.Null(g.Type))
|
||||
g.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
|
||||
pkg.ainits = append(pkg.ainits, func(param unsafe.Pointer) {
|
||||
pub := !private
|
||||
if pub {
|
||||
g.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
|
||||
}
|
||||
pkg.abiini = append(pkg.abiini, func(param unsafe.Pointer) {
|
||||
b := Builder(param)
|
||||
expr := g.Expr
|
||||
var blks []BasicBlock
|
||||
if pub {
|
||||
eq := b.BinOp(token.EQL, b.Load(expr), b.Prog.Null(expr.Type))
|
||||
blks = b.Func.MakeBlocks(2)
|
||||
b.If(eq, blks[0], blks[1])
|
||||
b.SetBlock(blks[0])
|
||||
}
|
||||
tabi := b.structOf(t)
|
||||
b.Store(g.Expr, tabi)
|
||||
b.Store(expr, tabi)
|
||||
if pub {
|
||||
b.Jump(blks[1])
|
||||
b.SetBlock(blks[1])
|
||||
}
|
||||
})
|
||||
}
|
||||
return b.Load(g.Expr)
|
||||
|
||||
@@ -491,7 +491,7 @@ func (p Program) Uint64() Type {
|
||||
type aPackage struct {
|
||||
mod llvm.Module
|
||||
abi abi.Builder
|
||||
ainits []func(b unsafe.Pointer) // b Builder
|
||||
abiini []func(b unsafe.Pointer) // b Builder
|
||||
vars map[string]Global
|
||||
fns map[string]Function
|
||||
stubs map[string]Function
|
||||
@@ -556,13 +556,23 @@ func (p Package) String() string {
|
||||
|
||||
// AfterInit is called after the package is initialized (init all packages that depends on).
|
||||
func (p Package) AfterInit(b Builder, ret BasicBlock) {
|
||||
doAfterInit := len(p.ainits) > 0 || p.pyHasModSyms()
|
||||
if doAfterInit {
|
||||
doAbiInit := len(p.abiini) > 0
|
||||
doPyLoadModSyms := p.pyHasModSyms()
|
||||
if doAbiInit || doPyLoadModSyms {
|
||||
b.SetBlockEx(ret, afterInit)
|
||||
for _, fnAfterInit := range p.ainits {
|
||||
fnAfterInit(unsafe.Pointer(b))
|
||||
if doAbiInit {
|
||||
sigAbiInit := types.NewSignatureType(nil, nil, nil, nil, nil, false)
|
||||
fn := p.NewFunc(p.abi.Pkg+".init$abi", sigAbiInit, InC)
|
||||
fnb := fn.MakeBody(1)
|
||||
for _, abiInit := range p.abiini {
|
||||
abiInit(unsafe.Pointer(fnb))
|
||||
}
|
||||
fnb.Return()
|
||||
b.Call(fn.Expr)
|
||||
}
|
||||
if doPyLoadModSyms {
|
||||
p.pyLoadModSyms(b)
|
||||
}
|
||||
p.pyLoadModSyms(b)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user