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))
// 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)
// 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
}
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)
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)
}
}
func maplit(ctxt initContext, n *Node, m *Node, init *Nodes) {
- ctxt = inInitFunction
-
// make the map var
nerr := nerrors
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() {
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 {