Skip to content

Commit 0ac7cde

Browse files
authored
Merge pull request #684 from visualfc/initafter
cl: build initAfter
2 parents c5b96f4 + 108829a commit 0ac7cde

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

cl/compile.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ type context struct {
9898
patches Patches
9999
blkInfos []blocks.Info
100100

101-
inits []func()
102-
phis []func()
101+
inits []func()
102+
phis []func()
103+
initAfter func()
103104

104105
state pkgState
105106
inCFunc bool
@@ -292,9 +293,9 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
292293
instrs = instrs[:last]
293294
} else if p.state != pkgHasPatch {
294295
// TODO(xsw): confirm pyMod don't need to call AfterInit
295-
p.inits = append(p.inits, func() {
296+
p.initAfter = func() {
296297
pkg.AfterInit(b, ret)
297-
})
298+
}
298299
}
299300
} else if doMainInit {
300301
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 [
837838
ini()
838839
}
839840
}
841+
if fn := ctx.initAfter; fn != nil {
842+
ctx.initAfter = nil
843+
fn()
844+
}
840845
return
841846
}
842847

0 commit comments

Comments
 (0)