Skip to content

Commit aa00ca1

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent b75e8a2 commit aa00ca1

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

Diff for: src/cmd/compile/internal/gc/dcl.go

-23
Original file line numberDiff line numberDiff line change
@@ -1020,29 +1020,6 @@ func addmethod(msym *types.Sym, t *types.Type, local, nointerface bool) *types.F
10201020
return f
10211021
}
10221022

1023-
func funccompile(n *Node) {
1024-
if n.Type == nil {
1025-
if nerrors == 0 {
1026-
Fatalf("funccompile missing type")
1027-
}
1028-
return
1029-
}
1030-
1031-
// assign parameter offsets
1032-
checkwidth(n.Type)
1033-
1034-
if Curfn != nil {
1035-
Fatalf("funccompile %v inside %v", n.Func.Nname.Sym, Curfn.Func.Nname.Sym)
1036-
}
1037-
1038-
dclcontext = PAUTO
1039-
funcdepth = n.Func.Depth + 1
1040-
compile(n)
1041-
Curfn = nil
1042-
funcdepth = 0
1043-
dclcontext = PEXTERN
1044-
}
1045-
10461023
func funcsymname(s *types.Sym) string {
10471024
return s.Name + "·f"
10481025
}

Diff for: src/cmd/compile/internal/gc/pgen.go

+37-14
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,32 @@ var (
2727
compilequeue []*Node // functions waiting to be compiled
2828
)
2929

30-
func emitptrargsmap() {
31-
if Curfn.funcname() == "_" {
30+
func emitptrargsmap(fn *Node) {
31+
if fn.funcname() == "_" {
3232
return
3333
}
34-
sym := lookup(fmt.Sprintf("%s.args_stackmap", Curfn.funcname()))
34+
sym := lookup(fmt.Sprintf("%s.args_stackmap", fn.funcname()))
3535
lsym := sym.Linksym()
3636

37-
nptr := int(Curfn.Type.ArgWidth() / int64(Widthptr))
37+
nptr := int(fn.Type.ArgWidth() / int64(Widthptr))
3838
bv := bvalloc(int32(nptr) * 2)
3939
nbitmap := 1
40-
if Curfn.Type.NumResults() > 0 {
40+
if fn.Type.NumResults() > 0 {
4141
nbitmap = 2
4242
}
4343
off := duint32(lsym, 0, uint32(nbitmap))
4444
off = duint32(lsym, off, uint32(bv.n))
4545

46-
if Curfn.IsMethod() {
47-
onebitwalktype1(Curfn.Type.Recvs(), 0, bv)
46+
if fn.IsMethod() {
47+
onebitwalktype1(fn.Type.Recvs(), 0, bv)
4848
}
49-
if Curfn.Type.NumParams() > 0 {
50-
onebitwalktype1(Curfn.Type.Params(), 0, bv)
49+
if fn.Type.NumParams() > 0 {
50+
onebitwalktype1(fn.Type.Params(), 0, bv)
5151
}
5252
off = dbvec(lsym, off, bv)
5353

54-
if Curfn.Type.NumResults() > 0 {
55-
onebitwalktype1(Curfn.Type.Results(), 0, bv)
54+
if fn.Type.NumResults() > 0 {
55+
onebitwalktype1(fn.Type.Results(), 0, bv)
5656
off = dbvec(lsym, off, bv)
5757
}
5858

@@ -183,15 +183,38 @@ func (s *ssafn) AllocFrame(f *ssa.Func) {
183183
s.stkptrsize = Rnd(s.stkptrsize, int64(Widthreg))
184184
}
185185

186-
func compile(fn *Node) {
187-
Curfn = fn
186+
func funccompile(fn *Node) {
187+
if Curfn != nil {
188+
Fatalf("funccompile %v inside %v", fn.Func.Nname.Sym, Curfn.Func.Nname.Sym)
189+
}
190+
191+
if fn.Type == nil {
192+
if nerrors == 0 {
193+
Fatalf("funccompile missing type")
194+
}
195+
return
196+
}
197+
198+
// assign parameter offsets
188199
dowidth(fn.Type)
189200

190201
if fn.Nbody.Len() == 0 {
191-
emitptrargsmap()
202+
emitptrargsmap(fn)
192203
return
193204
}
194205

206+
dclcontext = PAUTO
207+
funcdepth = fn.Func.Depth + 1
208+
Curfn = fn
209+
210+
compile(fn)
211+
212+
Curfn = nil
213+
funcdepth = 0
214+
dclcontext = PEXTERN
215+
}
216+
217+
func compile(fn *Node) {
195218
saveerrors()
196219

197220
order(fn)

0 commit comments

Comments
 (0)