1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:44:45 -07:00

cmd/compile: refactor static slice symbol creation

This change mostly moves code around to unify it.
A subsequent change will simplify and improve slicesym.

Passes toolstash-check.

Change-Id: I84a877ea747febb2b571d4089ba6d905b51b27ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/227549
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Josh Bleecher Snyder 2020-04-08 13:41:59 -07:00
parent 376472ddb7
commit 7096b1700d
2 changed files with 13 additions and 20 deletions

View File

@ -417,6 +417,16 @@ func dsymptrWeakOff(s *obj.LSym, off int, x *obj.LSym) int {
return off
}
// slicesym writes a static slice symbol {&arr, lencap, lencap} to n.
func slicesym(n, arr, lencap *Node) {
base := n.Xoffset
gdata(n, nod(OADDR, arr, nil), Widthptr)
n.Xoffset = base + sliceLenOffset
gdata(n, lencap, Widthptr)
n.Xoffset = base + sliceCapOffset
gdata(n, lencap, Widthptr)
}
func gdata(nam *Node, nr *Node, wid int) {
if nam.Op != ONAME {
Fatalf("gdata nam op %v", nam.Op)

View File

@ -130,12 +130,7 @@ func (s *InitSchedule) staticcopy(l *Node, r *Node) bool {
a := s.inittemps[r]
n := l.copy()
n.Xoffset = l.Xoffset + slicePtrOffset
gdata(n, nod(OADDR, a, nil), Widthptr)
n.Xoffset = l.Xoffset + sliceLenOffset
gdata(n, r.Right, Widthptr)
n.Xoffset = l.Xoffset + sliceCapOffset
gdata(n, r.Right, Widthptr)
slicesym(n, a, r.Right)
return true
case OARRAYLIT, OSTRUCTLIT:
@ -227,12 +222,7 @@ func (s *InitSchedule) staticassign(l *Node, r *Node) bool {
a := staticname(ta)
s.inittemps[r] = a
n := l.copy()
n.Xoffset = l.Xoffset + slicePtrOffset
gdata(n, nod(OADDR, a, nil), Widthptr)
n.Xoffset = l.Xoffset + sliceLenOffset
gdata(n, r.Right, Widthptr)
n.Xoffset = l.Xoffset + sliceCapOffset
gdata(n, r.Right, Widthptr)
slicesym(n, a, r.Right)
// Fall through to init underlying array.
l = a
@ -614,14 +604,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
var v Node
v.Type = types.Types[TINT]
setintconst(&v, t.NumElem())
nam.Xoffset += slicePtrOffset
gdata(&nam, nod(OADDR, vstat, nil), Widthptr)
nam.Xoffset += sliceLenOffset - slicePtrOffset
gdata(&nam, &v, Widthptr)
nam.Xoffset += sliceCapOffset - sliceLenOffset
gdata(&nam, &v, Widthptr)
slicesym(&nam, vstat, &v)
return
}