Commit db9796da authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: simplify staticname

Add docs.
Give it a more natural signature.

Passes toolstash -cmp.

Change-Id: Iab368dd10e8f16e41b725c2980020bbead2cdefb
Reviewed-on: https://go-review.googlesource.com/26756
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 7b5df0c1
......@@ -400,7 +400,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
switch r.Left.Op {
case OARRAYLIT, OSLICELIT, OMAPLIT, OSTRUCTLIT:
// Init pointer.
a := staticname(r.Left.Type, inNonInitFunction)
a := staticname(r.Left.Type)
inittemps[r] = a
gdata(l, Nod(OADDR, a, nil), int(l.Type.Width))
......@@ -425,7 +425,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool {
// Init slice.
bound := r.Right.Int64()
ta := typArray(r.Type.Elem(), bound)
a := staticname(ta, inNonInitFunction)
a := staticname(ta)
inittemps[r] = a
n := *l
n.Xoffset = l.Xoffset + int64(Array_array)
......@@ -507,12 +507,13 @@ const (
// most of the work is to generate
// data statements for the constant
// part of the composite literal.
func staticname(t *Type, ctxt initContext) *Node {
// staticname return a name backed by a static data symbol.
// Callers should set n.Name.Readonly = true on the
// returned node for readonly nodes.
func staticname(t *Type) *Node {
n := newname(LookupN("statictmp_", statuniqgen))
statuniqgen++
if ctxt == inInitFunction {
n.Name.Readonly = true
}
addvar(n, t, PEXTERN)
return n
}
......@@ -684,7 +685,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
if ctxt == inNonInitFunction {
// put everything into static array
vstat := staticname(t, ctxt)
vstat := staticname(t)
fixedlit(ctxt, initKindStatic, n, vstat, init)
fixedlit(ctxt, initKindDynamic, n, vstat, init)
......@@ -724,7 +725,10 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
mode := getdyn(n, true)
if mode&initConst != 0 {
vstat = staticname(t, ctxt)
vstat = staticname(t)
if ctxt == inInitFunction {
vstat.Name.Readonly = true
}
fixedlit(ctxt, initKindStatic, n, vstat, init)
}
......@@ -819,8 +823,6 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
}
func maplit(ctxt initContext, n *Node, m *Node, init *Nodes) {
ctxt = inInitFunction
// make the map var
nerr := nerrors
......@@ -852,8 +854,10 @@ func maplit(ctxt initContext, n *Node, m *Node, init *Nodes) {
dowidth(tv)
// make and initialize static arrays
vstatk := staticname(tk, ctxt)
vstatv := staticname(tv, ctxt)
vstatk := staticname(tk)
vstatk.Name.Readonly = true
vstatv := staticname(tv)
vstatv.Name.Readonly = true
b := int64(0)
for _, r := range n.List.Slice() {
......@@ -1005,7 +1009,8 @@ func anylit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
if var_.isSimpleName() && n.List.Len() > 4 {
if ctxt == inInitFunction {
// lay out static data
vstat := staticname(t, ctxt)
vstat := staticname(t)
vstat.Name.Readonly = true
litctxt := ctxt
if n.Op == OARRAYLIT {
......
......@@ -1636,7 +1636,8 @@ opswitch:
if isStaticCompositeLiteral(n) {
// n can be directly represented in the read-only data section.
// Make direct reference to the static data. See issue 12841.
vstat := staticname(n.Type, inInitFunction)
vstat := staticname(n.Type)
vstat.Name.Readonly = true
fixedlit(inInitFunction, initKindStatic, n, vstat, init)
n = vstat
n = typecheck(n, Erv)
......
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