]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify staticname
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 20 Jun 2016 15:18:22 +0000 (08:18 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 4 Sep 2016 18:18:12 +0000 (18:18 +0000)
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: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/walk.go

index a801db9aa50949f27fad530beed857080823f480..b480a8a211fee3090ee483080a4601d924256a5e 100644 (file)
@@ -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 {
index f38e7282baf620df2d4fce041e33cc1d25b64bad..28fe549694c0504eb68c5165b89b3eaa11fa5107 100644 (file)
@@ -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)