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)
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:
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
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
}