cl: build initAfter

This commit is contained in:
visualfc
2024-08-08 21:36:18 +08:00
parent c5b96f4e9c
commit 108829ad9c

View File

@@ -100,6 +100,7 @@ type context struct {
inits []func() inits []func()
phis []func() phis []func()
initAfter func()
state pkgState state pkgState
inCFunc bool inCFunc bool
@@ -292,9 +293,9 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
instrs = instrs[:last] instrs = instrs[:last]
} else if p.state != pkgHasPatch { } else if p.state != pkgHasPatch {
// TODO(xsw): confirm pyMod don't need to call AfterInit // TODO(xsw): confirm pyMod don't need to call AfterInit
p.inits = append(p.inits, func() { p.initAfter = func() {
pkg.AfterInit(b, ret) pkg.AfterInit(b, ret)
}) }
} }
} else if doMainInit { } else if doMainInit {
argc := pkg.NewVar("__llgo_argc", types.NewPointer(types.Typ[types.Int32]), llssa.InC) argc := pkg.NewVar("__llgo_argc", types.NewPointer(types.Typ[types.Int32]), llssa.InC)
@@ -837,6 +838,10 @@ func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files [
ini() ini()
} }
} }
if fn := ctx.initAfter; fn != nil {
ctx.initAfter = nil
fn()
}
return return
} }