]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: cleanup funccompile and compile
authorMatthew Dempsky <mdempsky@google.com>
Wed, 7 Mar 2018 00:20:10 +0000 (16:20 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 7 Mar 2018 03:12:38 +0000 (03:12 +0000)
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: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/pgen.go

index 2756707aef16487cc08ccc67e4a070677bae9795..5d1efaadafaf26afd8c4be65a8dd0ad359ea206f 100644 (file)
@@ -1020,29 +1020,6 @@ func addmethod(msym *types.Sym, t *types.Type, local, nointerface bool) *types.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 {
        return s.Name + "·f"
 }
index 2e404e50214496490e862e1618f08b03fec13015..36b46a1c6903d2115112fb6506c74c958df4ff29 100644 (file)
@@ -27,32 +27,32 @@ var (
        compilequeue    []*Node // functions waiting to be compiled
 )
 
-func emitptrargsmap() {
-       if Curfn.funcname() == "_" {
+func emitptrargsmap(fn *Node) {
+       if fn.funcname() == "_" {
                return
        }
-       sym := lookup(fmt.Sprintf("%s.args_stackmap", Curfn.funcname()))
+       sym := lookup(fmt.Sprintf("%s.args_stackmap", fn.funcname()))
        lsym := sym.Linksym()
 
-       nptr := int(Curfn.Type.ArgWidth() / int64(Widthptr))
+       nptr := int(fn.Type.ArgWidth() / int64(Widthptr))
        bv := bvalloc(int32(nptr) * 2)
        nbitmap := 1
-       if Curfn.Type.NumResults() > 0 {
+       if fn.Type.NumResults() > 0 {
                nbitmap = 2
        }
        off := duint32(lsym, 0, uint32(nbitmap))
        off = duint32(lsym, off, uint32(bv.n))
 
-       if Curfn.IsMethod() {
-               onebitwalktype1(Curfn.Type.Recvs(), 0, bv)
+       if fn.IsMethod() {
+               onebitwalktype1(fn.Type.Recvs(), 0, bv)
        }
-       if Curfn.Type.NumParams() > 0 {
-               onebitwalktype1(Curfn.Type.Params(), 0, bv)
+       if fn.Type.NumParams() > 0 {
+               onebitwalktype1(fn.Type.Params(), 0, bv)
        }
        off = dbvec(lsym, off, bv)
 
-       if Curfn.Type.NumResults() > 0 {
-               onebitwalktype1(Curfn.Type.Results(), 0, bv)
+       if fn.Type.NumResults() > 0 {
+               onebitwalktype1(fn.Type.Results(), 0, bv)
                off = dbvec(lsym, off, bv)
        }
 
@@ -183,15 +183,38 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
        s.stkptrsize = Rnd(s.stkptrsize, int64(Widthreg))
 }
 
-func compile(fn *Node) {
-       Curfn = fn
+func funccompile(fn *Node) {
+       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)
 
        if fn.Nbody.Len() == 0 {
-               emitptrargsmap()
+               emitptrargsmap(fn)
                return
        }
 
+       dclcontext = PAUTO
+       funcdepth = fn.Func.Depth + 1
+       Curfn = fn
+
+       compile(fn)
+
+       Curfn = nil
+       funcdepth = 0
+       dclcontext = PEXTERN
+}
+
+func compile(fn *Node) {
        saveerrors()
 
        order(fn)