[dev.unified] cmd/compile: refactor reflectdata.{TypePtr,ITabAddr}

Minor refactoring to decouple from base.Pos and deduplicate some
common code paths.

Passes toolstash -cmp.

Change-Id: I8c0724cf821d28b0ede3b0e8e4b2d02302d9af3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/413355
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Matthew Dempsky 2022-06-14 16:11:17 -07:00
parent fc5dad6646
commit f70775ff22
2 changed files with 25 additions and 6 deletions

View File

@ -842,9 +842,15 @@ func TypeLinksym(t *types.Type) *obj.LSym {
return TypeSym(t).Linksym()
}
// Deprecated: Use TypePtrAt instead.
func TypePtr(t *types.Type) *ir.AddrExpr {
n := ir.NewLinksymExpr(base.Pos, TypeLinksym(t), types.Types[types.TUINT8])
return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr)
return TypePtrAt(base.Pos, t)
}
// TypePtrAt returns an expression that evaluates to the
// *runtime._type value for t.
func TypePtrAt(pos src.XPos, t *types.Type) *ir.AddrExpr {
return typecheck.LinksymAddr(pos, TypeLinksym(t), types.Types[types.TUINT8])
}
// ITabLsym returns the LSym representing the itab for concrete type typ implementing
@ -864,9 +870,15 @@ func ITabLsym(typ, iface *types.Type) *obj.LSym {
return lsym
}
// ITabAddr returns an expression representing a pointer to the itab
// for concrete type typ implementing interface iface.
// Deprecated: Use ITabAddrAt instead.
func ITabAddr(typ, iface *types.Type) *ir.AddrExpr {
return ITabAddrAt(base.Pos, typ, iface)
}
// ITabAddrAt returns an expression that evaluates to the
// *runtime.itab value for concrete type typ implementing interface
// iface.
func ITabAddrAt(pos src.XPos, typ, iface *types.Type) *ir.AddrExpr {
s, existed := ir.Pkgs.Itab.LookupOK(typ.LinkString() + "," + iface.LinkString())
lsym := s.Linksym()
@ -874,8 +886,7 @@ func ITabAddr(typ, iface *types.Type) *ir.AddrExpr {
writeITab(lsym, typ, iface, false)
}
n := ir.NewLinksymExpr(base.Pos, lsym, types.Types[types.TUINT8])
return typecheck.Expr(typecheck.NodAddr(n)).(*ir.AddrExpr)
return typecheck.LinksymAddr(pos, lsym, types.Types[types.TUINT8])
}
// needkeyupdate reports whether map updates with t as a key

View File

@ -13,6 +13,7 @@ import (
"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/types"
"cmd/internal/obj"
"cmd/internal/objabi"
"cmd/internal/src"
)
@ -119,6 +120,13 @@ func ComputeAddrtaken(top []ir.Node) {
}
}
// LinksymAddr returns a new expression that evaluates to the address
// of lsym. typ specifies the type of the addressed memory.
func LinksymAddr(pos src.XPos, lsym *obj.LSym, typ *types.Type) *ir.AddrExpr {
n := ir.NewLinksymExpr(pos, lsym, typ)
return Expr(NodAddrAt(pos, n)).(*ir.AddrExpr)
}
func NodNil() ir.Node {
n := ir.NewNilExpr(base.Pos)
n.SetType(types.Types[types.TNIL])