mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: make sinit consts Go-ish
Passes toolstash -cmp. Change-Id: Ie11912a16d2cd54500e2f6e84316519b80e7c304 Reviewed-on: https://go-review.googlesource.com/20672 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
e6ed3e8a46
commit
4e75932cf7
1 changed files with 13 additions and 12 deletions
|
|
@ -525,37 +525,38 @@ func litas(l *Node, r *Node, init *Nodes) {
|
||||||
init.Append(a)
|
init.Append(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// initGenType is a bitmap indicating the types of generation that will occur for a static value.
|
||||||
|
type initGenType uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
MODEDYNAM = 1
|
initDynamic initGenType = 1 << iota // contains some dynamic values, for which init code will be generated
|
||||||
MODECONST = 2
|
initConst // contains some constant values, which may be written into data symbols
|
||||||
)
|
)
|
||||||
|
|
||||||
func getdyn(n *Node, top int) int {
|
func getdyn(n *Node, top int) initGenType {
|
||||||
mode := 0
|
|
||||||
switch n.Op {
|
switch n.Op {
|
||||||
default:
|
default:
|
||||||
if isliteral(n) {
|
if isliteral(n) {
|
||||||
return MODECONST
|
return initConst
|
||||||
}
|
}
|
||||||
return MODEDYNAM
|
return initDynamic
|
||||||
|
|
||||||
case OARRAYLIT:
|
case OARRAYLIT:
|
||||||
if top == 0 && n.Type.Bound < 0 {
|
if top == 0 && n.Type.Bound < 0 {
|
||||||
return MODEDYNAM
|
return initDynamic
|
||||||
}
|
}
|
||||||
fallthrough
|
|
||||||
|
|
||||||
case OSTRUCTLIT:
|
case OSTRUCTLIT:
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var mode initGenType
|
||||||
for _, n1 := range n.List.Slice() {
|
for _, n1 := range n.List.Slice() {
|
||||||
value := n1.Right
|
value := n1.Right
|
||||||
mode |= getdyn(value, 0)
|
mode |= getdyn(value, 0)
|
||||||
if mode == MODEDYNAM|MODECONST {
|
if mode == initDynamic|initConst {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mode
|
return mode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -737,7 +738,7 @@ func slicelit(ctxt int, n *Node, var_ *Node, init *Nodes) {
|
||||||
var vstat *Node
|
var vstat *Node
|
||||||
|
|
||||||
mode := getdyn(n, 1)
|
mode := getdyn(n, 1)
|
||||||
if mode&MODECONST != 0 {
|
if mode&initConst != 0 {
|
||||||
vstat = staticname(t, ctxt)
|
vstat = staticname(t, ctxt)
|
||||||
arraylit(ctxt, 1, n, vstat, init)
|
arraylit(ctxt, 1, n, vstat, init)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue