cl: afterInit skip pkgHasPatch

This commit is contained in:
visualfc
2024-07-28 11:29:22 +08:00
parent 9d9e998d49
commit c63a1978cb

View File

@@ -25,7 +25,6 @@ import (
"log" "log"
"os" "os"
"sort" "sort"
"strings"
"github.com/goplus/llgo/cl/blocks" "github.com/goplus/llgo/cl/blocks"
"github.com/goplus/llgo/internal/typepatch" "github.com/goplus/llgo/internal/typepatch"
@@ -287,16 +286,11 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
if pyModInit = p.pyMod != ""; pyModInit { if pyModInit = p.pyMod != ""; pyModInit {
last = len(instrs) - 1 last = len(instrs) - 1
instrs = instrs[:last] instrs = instrs[:last]
} else { } 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
after := func() { p.inits = append(p.inits, func() {
pkg.AfterInit(b, ret) pkg.AfterInit(b, ret)
} })
if strings.HasSuffix(fn.Name(), "$hasPatch") {
p.inits[len(p.inits)-1] = after
} else {
p.inits = append(p.inits, after)
}
} }
} 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)