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