Commit aa00ca12 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile: cleanup funccompile and compile

Bring these functions next to each other, and clean them up a little
bit. Also, change emitptrargsmap to take Curfn as a parameter instead
of a global.

Passes toolstash-check.

Change-Id: Ib9c94fda3b2cb6f0dcec1585622b33b4f311b5e9
Reviewed-on: https://go-review.googlesource.com/99075
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent b75e8a2a
...@@ -1020,29 +1020,6 @@ func addmethod(msym *types.Sym, t *types.Type, local, nointerface bool) *types.F ...@@ -1020,29 +1020,6 @@ func addmethod(msym *types.Sym, t *types.Type, local, nointerface bool) *types.F
return f return f
} }
func funccompile(n *Node) {
if n.Type == nil {
if nerrors == 0 {
Fatalf("funccompile missing type")
}
return
}
// assign parameter offsets
checkwidth(n.Type)
if Curfn != nil {
Fatalf("funccompile %v inside %v", n.Func.Nname.Sym, Curfn.Func.Nname.Sym)
}
dclcontext = PAUTO
funcdepth = n.Func.Depth + 1
compile(n)
Curfn = nil
funcdepth = 0
dclcontext = PEXTERN
}
func funcsymname(s *types.Sym) string { func funcsymname(s *types.Sym) string {
return s.Name + "·f" return s.Name + "·f"
} }
......
...@@ -27,32 +27,32 @@ var ( ...@@ -27,32 +27,32 @@ var (
compilequeue []*Node // functions waiting to be compiled compilequeue []*Node // functions waiting to be compiled
) )
func emitptrargsmap() { func emitptrargsmap(fn *Node) {
if Curfn.funcname() == "_" { if fn.funcname() == "_" {
return return
} }
sym := lookup(fmt.Sprintf("%s.args_stackmap", Curfn.funcname())) sym := lookup(fmt.Sprintf("%s.args_stackmap", fn.funcname()))
lsym := sym.Linksym() lsym := sym.Linksym()
nptr := int(Curfn.Type.ArgWidth() / int64(Widthptr)) nptr := int(fn.Type.ArgWidth() / int64(Widthptr))
bv := bvalloc(int32(nptr) * 2) bv := bvalloc(int32(nptr) * 2)
nbitmap := 1 nbitmap := 1
if Curfn.Type.NumResults() > 0 { if fn.Type.NumResults() > 0 {
nbitmap = 2 nbitmap = 2
} }
off := duint32(lsym, 0, uint32(nbitmap)) off := duint32(lsym, 0, uint32(nbitmap))
off = duint32(lsym, off, uint32(bv.n)) off = duint32(lsym, off, uint32(bv.n))
if Curfn.IsMethod() { if fn.IsMethod() {
onebitwalktype1(Curfn.Type.Recvs(), 0, bv) onebitwalktype1(fn.Type.Recvs(), 0, bv)
} }
if Curfn.Type.NumParams() > 0 { if fn.Type.NumParams() > 0 {
onebitwalktype1(Curfn.Type.Params(), 0, bv) onebitwalktype1(fn.Type.Params(), 0, bv)
} }
off = dbvec(lsym, off, bv) off = dbvec(lsym, off, bv)
if Curfn.Type.NumResults() > 0 { if fn.Type.NumResults() > 0 {
onebitwalktype1(Curfn.Type.Results(), 0, bv) onebitwalktype1(fn.Type.Results(), 0, bv)
off = dbvec(lsym, off, bv) off = dbvec(lsym, off, bv)
} }
...@@ -183,15 +183,38 @@ func (s *ssafn) AllocFrame(f *ssa.Func) { ...@@ -183,15 +183,38 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
s.stkptrsize = Rnd(s.stkptrsize, int64(Widthreg)) s.stkptrsize = Rnd(s.stkptrsize, int64(Widthreg))
} }
func compile(fn *Node) { func funccompile(fn *Node) {
Curfn = fn if Curfn != nil {
Fatalf("funccompile %v inside %v", fn.Func.Nname.Sym, Curfn.Func.Nname.Sym)
}
if fn.Type == nil {
if nerrors == 0 {
Fatalf("funccompile missing type")
}
return
}
// assign parameter offsets
dowidth(fn.Type) dowidth(fn.Type)
if fn.Nbody.Len() == 0 { if fn.Nbody.Len() == 0 {
emitptrargsmap() emitptrargsmap(fn)
return return
} }
dclcontext = PAUTO
funcdepth = fn.Func.Depth + 1
Curfn = fn
compile(fn)
Curfn = nil
funcdepth = 0
dclcontext = PEXTERN
}
func compile(fn *Node) {
saveerrors() saveerrors()
order(fn) order(fn)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment