Merge pull request #586 from xushiwei/q

compileFuncDecl todo: change ssa.If to ssa.Jump for func init
This commit is contained in:
xushiwei
2024-07-28 21:58:07 +08:00
committed by GitHub

View File

@@ -195,7 +195,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
isInit := (f.Name() == "init" && sig.Recv() == nil) isInit := (f.Name() == "init" && sig.Recv() == nil)
if isInit && state == pkgHasPatch { if isInit && state == pkgHasPatch {
name = initFnNameOfHasPatch(name) name = initFnNameOfHasPatch(name)
// pkg.init$guard has been set, change ssa.if-cond // TODO(xsw): pkg.init$guard has been set, change ssa.If to ssa.Jump
block := f.Blocks[0].Instrs[1].(*ssa.If).Block() block := f.Blocks[0].Instrs[1].(*ssa.If).Block()
block.Succs[0], block.Succs[1] = block.Succs[1], block.Succs[0] block.Succs[0], block.Succs[1] = block.Succs[1], block.Succs[0]
} }
@@ -306,7 +306,7 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
b.Call(pkg.FuncOf("main.init").Expr) b.Call(pkg.FuncOf("main.init").Expr)
} }
for i, instr := range instrs { for i, instr := range instrs {
if i == 1 && doModInit && p.state == pkgInPatch { if i == 1 && doModInit && p.state == pkgInPatch { // in patch package but no pkgFNoOldInit
initFnNameOld := initFnNameOfHasPatch(p.fn.Name()) initFnNameOld := initFnNameOfHasPatch(p.fn.Name())
fnOld := pkg.NewFunc(initFnNameOld, llssa.NoArgsNoRet, llssa.InC) fnOld := pkg.NewFunc(initFnNameOld, llssa.NoArgsNoRet, llssa.InC)
b.Call(fnOld.Expr) b.Call(fnOld.Expr)