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)