Commit 97b89dc0 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile/internal/gc: refactor ODCLFUNC creation

Extract out some common boiler plate logic.

Passes toolstash-check -all.

Change-Id: Iddc8a733af8262558f56d13c91d9c27ee0d61330
Reviewed-on: https://go-review.googlesource.com/40253
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b83a916f
...@@ -194,13 +194,7 @@ func genhash(sym *types.Sym, t *types.Type) { ...@@ -194,13 +194,7 @@ func genhash(sym *types.Sym, t *types.Type) {
types.Markdcl(lineno) types.Markdcl(lineno)
// func sym(p *T, h uintptr) uintptr // func sym(p *T, h uintptr) uintptr
fn := nod(ODCLFUNC, nil, nil)
fn.Func.Nname = newname(sym)
fn.Func.Nname.Class = PFUNC
tfn := nod(OTFUNC, nil, nil) tfn := nod(OTFUNC, nil, nil)
fn.Func.Nname.Name.Param.Ntype = tfn
n := namedfield("p", types.NewPtr(t)) n := namedfield("p", types.NewPtr(t))
tfn.List.Append(n) tfn.List.Append(n)
np := n.Left np := n.Left
...@@ -210,8 +204,7 @@ func genhash(sym *types.Sym, t *types.Type) { ...@@ -210,8 +204,7 @@ func genhash(sym *types.Sym, t *types.Type) {
n = anonfield(types.Types[TUINTPTR]) // return value n = anonfield(types.Types[TUINTPTR]) // return value
tfn.Rlist.Append(n) tfn.Rlist.Append(n)
funchdr(fn) fn := dclfunc(sym, tfn)
fn.Func.Nname.Name.Param.Ntype = typecheck(fn.Func.Nname.Name.Param.Ntype, Etype)
// genhash is only called for types that have equality but // genhash is only called for types that have equality but
// cannot be handled by the standard algorithms, // cannot be handled by the standard algorithms,
...@@ -372,13 +365,7 @@ func geneq(sym *types.Sym, t *types.Type) { ...@@ -372,13 +365,7 @@ func geneq(sym *types.Sym, t *types.Type) {
types.Markdcl(lineno) types.Markdcl(lineno)
// func sym(p, q *T) bool // func sym(p, q *T) bool
fn := nod(ODCLFUNC, nil, nil)
fn.Func.Nname = newname(sym)
fn.Func.Nname.Class = PFUNC
tfn := nod(OTFUNC, nil, nil) tfn := nod(OTFUNC, nil, nil)
fn.Func.Nname.Name.Param.Ntype = tfn
n := namedfield("p", types.NewPtr(t)) n := namedfield("p", types.NewPtr(t))
tfn.List.Append(n) tfn.List.Append(n)
np := n.Left np := n.Left
...@@ -388,8 +375,7 @@ func geneq(sym *types.Sym, t *types.Type) { ...@@ -388,8 +375,7 @@ func geneq(sym *types.Sym, t *types.Type) {
n = anonfield(types.Types[TBOOL]) n = anonfield(types.Types[TBOOL])
tfn.Rlist.Append(n) tfn.Rlist.Append(n)
funchdr(fn) fn := dclfunc(sym, tfn)
fn.Func.Nname.Name.Param.Ntype = typecheck(fn.Func.Nname.Name.Param.Ntype, Etype)
// geneq is only called for types that have equality but // geneq is only called for types that have equality but
// cannot be handled by the standard algorithms, // cannot be handled by the standard algorithms,
......
...@@ -1100,6 +1100,21 @@ func makefuncsym(s *types.Sym) { ...@@ -1100,6 +1100,21 @@ func makefuncsym(s *types.Sym) {
} }
} }
func dclfunc(sym *types.Sym, tfn *Node) *Node {
if tfn.Op != OTFUNC {
Fatalf("expected OTFUNC node, got %v", tfn)
}
fn := nod(ODCLFUNC, nil, nil)
fn.Func.Nname = newname(sym)
fn.Func.Nname.Name.Defn = fn
fn.Func.Nname.Name.Param.Ntype = tfn
declare(fn.Func.Nname, PFUNC)
funchdr(fn)
fn.Func.Nname.Name.Param.Ntype = typecheck(fn.Func.Nname.Name.Param.Ntype, Etype)
return fn
}
type nowritebarrierrecChecker struct { type nowritebarrierrecChecker struct {
curfn *Node curfn *Node
stable bool stable bool
......
...@@ -86,13 +86,8 @@ func fninit(n []*Node) { ...@@ -86,13 +86,8 @@ func fninit(n []*Node) {
addvar(gatevar, types.Types[TUINT8], PEXTERN) addvar(gatevar, types.Types[TUINT8], PEXTERN)
// (2) // (2)
fn := nod(ODCLFUNC, nil, nil)
initsym := lookup("init") initsym := lookup("init")
fn.Func.Nname = newname(initsym) fn := dclfunc(initsym, nod(OTFUNC, nil, nil))
fn.Func.Nname.Name.Defn = fn
fn.Func.Nname.Name.Param.Ntype = nod(OTFUNC, nil, nil)
declare(fn.Func.Nname, PFUNC)
funchdr(fn)
// (3) // (3)
a := nod(OIF, nil, nil) a := nod(OIF, nil, nil)
......
...@@ -1710,14 +1710,9 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym, iface ...@@ -1710,14 +1710,9 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym, iface
t.List.Set(append(l, in...)) t.List.Set(append(l, in...))
t.Rlist.Set(out) t.Rlist.Set(out)
fn := nod(ODCLFUNC, nil, nil) fn := dclfunc(newnam, t)
fn.Func.SetDupok(true) fn.Func.SetDupok(true)
fn.Func.Nname = newname(newnam)
fn.Func.Nname.Name.Defn = fn
fn.Func.Nname.Name.Param.Ntype = t
fn.Func.Nname.Sym.SetExported(true) // prevent export; see closure.go fn.Func.Nname.Sym.SetExported(true) // prevent export; see closure.go
declare(fn.Func.Nname, PFUNC)
funchdr(fn)
// arg list // arg list
var args []*Node var args []*Node
......
...@@ -3652,17 +3652,12 @@ func walkprintfunc(n *Node, init *Nodes) *Node { ...@@ -3652,17 +3652,12 @@ func walkprintfunc(n *Node, init *Nodes) *Node {
printargs = append(printargs, a.Left) printargs = append(printargs, a.Left)
} }
fn := nod(ODCLFUNC, nil, nil)
walkprintfunc_prgen++
buf = fmt.Sprintf("print·%d", walkprintfunc_prgen)
fn.Func.Nname = newname(lookup(buf))
fn.Func.Nname.Name.Defn = fn
fn.Func.Nname.Name.Param.Ntype = t
declare(fn.Func.Nname, PFUNC)
oldfn := Curfn oldfn := Curfn
Curfn = nil Curfn = nil
funchdr(fn)
walkprintfunc_prgen++
sym := lookupN("print·%d", walkprintfunc_prgen)
fn := dclfunc(sym, t)
a = nod(n.Op, nil, nil) a = nod(n.Op, nil, nil)
a.List.Set(printargs) a.List.Set(printargs)
......
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