cl: fn.SetRecover; inPatch/hasPatch
This commit is contained in:
@@ -102,6 +102,7 @@ type context struct {
|
|||||||
|
|
||||||
inCFunc bool
|
inCFunc bool
|
||||||
skipall bool
|
skipall bool
|
||||||
|
hasPatch bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *context) inMain(instr ssa.Instruction) bool {
|
func (p *context) inMain(instr ssa.Instruction) bool {
|
||||||
@@ -184,6 +185,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
|||||||
return fn, nil, goFunc
|
return fn, nil, goFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isInit bool
|
||||||
var sig = f.Signature
|
var sig = f.Signature
|
||||||
var hasCtx = len(f.FreeVars) > 0
|
var hasCtx = len(f.FreeVars) > 0
|
||||||
if hasCtx {
|
if hasCtx {
|
||||||
@@ -196,6 +198,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
|||||||
if debugInstr {
|
if debugInstr {
|
||||||
log.Println("==> NewFunc", name, "type:", sig.Recv(), sig, "ftype:", ftype)
|
log.Println("==> NewFunc", name, "type:", sig.Recv(), sig, "ftype:", ftype)
|
||||||
}
|
}
|
||||||
|
isInit = (f.Name() == "init" && sig.Recv() == nil)
|
||||||
}
|
}
|
||||||
if fn == nil {
|
if fn == nil {
|
||||||
if name == "main" {
|
if name == "main" {
|
||||||
@@ -211,6 +214,9 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
|||||||
|
|
||||||
if nblk := len(f.Blocks); nblk > 0 {
|
if nblk := len(f.Blocks); nblk > 0 {
|
||||||
fn.MakeBlocks(nblk) // to set fn.HasBody() = true
|
fn.MakeBlocks(nblk) // to set fn.HasBody() = true
|
||||||
|
if f.Recover != nil { // set recover block
|
||||||
|
fn.SetRecover(fn.Block(f.Recover.Index))
|
||||||
|
}
|
||||||
p.inits = append(p.inits, func() {
|
p.inits = append(p.inits, func() {
|
||||||
p.fn = fn
|
p.fn = fn
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -234,7 +240,7 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
|
|||||||
for {
|
for {
|
||||||
block := f.Blocks[i]
|
block := f.Blocks[i]
|
||||||
doMainInit := (i == 0 && name == "main")
|
doMainInit := (i == 0 && name == "main")
|
||||||
doModInit := (i == 1 && f.Name() == "init" && sig.Recv() == nil)
|
doModInit := (i == 1 && isInit)
|
||||||
p.compileBlock(b, block, off[i], doMainInit, doModInit)
|
p.compileBlock(b, block, off[i], doMainInit, doModInit)
|
||||||
if i = p.blkInfos[i].Next; i < 0 {
|
if i = p.blkInfos[i].Next; i < 0 {
|
||||||
break
|
break
|
||||||
@@ -377,9 +383,6 @@ func isPhi(i ssa.Instruction) bool {
|
|||||||
func (p *context) compilePhis(b llssa.Builder, block *ssa.BasicBlock) int {
|
func (p *context) compilePhis(b llssa.Builder, block *ssa.BasicBlock) int {
|
||||||
fn := p.fn
|
fn := p.fn
|
||||||
ret := fn.Block(block.Index)
|
ret := fn.Block(block.Index)
|
||||||
if block.Comment == "recover" { // set recover block
|
|
||||||
fn.SetRecover(ret)
|
|
||||||
}
|
|
||||||
b.SetBlockEx(ret, llssa.AtEnd, false)
|
b.SetBlockEx(ret, llssa.AtEnd, false)
|
||||||
if ninstr := len(block.Instrs); ninstr > 0 {
|
if ninstr := len(block.Instrs); ninstr > 0 {
|
||||||
if isPhi(block.Instrs[0]) {
|
if isPhi(block.Instrs[0]) {
|
||||||
@@ -756,6 +759,7 @@ func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files [
|
|||||||
ctx.skips = skips
|
ctx.skips = skips
|
||||||
}
|
}
|
||||||
if !ctx.skipall {
|
if !ctx.skipall {
|
||||||
|
ctx.hasPatch = hasPatch
|
||||||
processPkg(ctx, ret, pkg)
|
processPkg(ctx, ret, pkg)
|
||||||
}
|
}
|
||||||
for len(ctx.inits) > 0 {
|
for len(ctx.inits) > 0 {
|
||||||
@@ -768,6 +772,12 @@ func NewPackageEx(prog llssa.Program, patches Patches, pkg *ssa.Package, files [
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO(xsw):
|
||||||
|
func inPatch(ctx *context) bool {
|
||||||
|
return ctx.skips == nil
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func processPkg(ctx *context, ret llssa.Package, pkg *ssa.Package) {
|
func processPkg(ctx *context, ret llssa.Package, pkg *ssa.Package) {
|
||||||
type namedMember struct {
|
type namedMember struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Reference in New Issue
Block a user