Commit 6ee8c6a7 authored by Matthew Dempsky's avatar Matthew Dempsky

cmd/compile/internal/gc: simplify generating static data

Passes toolstash -cmp.

Change-Id: I4a72e3e130c38868ee8ecef32cad58748aa5be52
Reviewed-on: https://go-review.googlesource.com/36353Reviewed-by: default avatarJosh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent ad784caa
...@@ -1349,22 +1349,7 @@ func isvaluelit(n *Node) bool { ...@@ -1349,22 +1349,7 @@ func isvaluelit(n *Node) bool {
return n.Op == OARRAYLIT || n.Op == OSTRUCTLIT return n.Op == OARRAYLIT || n.Op == OSTRUCTLIT
} }
// gen_as_init attempts to emit static data for n and reports whether it succeeded. func genAsInitNoCheck(n *Node) bool {
// If reportOnly is true, it does not emit static data and does not modify the AST.
func gen_as_init(n *Node, reportOnly bool) bool {
success := genAsInitNoCheck(n, reportOnly)
if !success && n.IsStatic {
Dump("\ngen_as_init", n)
Fatalf("gen_as_init couldn't generate static data")
}
return success
}
func genAsInitNoCheck(n *Node, reportOnly bool) bool {
if !n.IsStatic {
return false
}
nr := n.Right nr := n.Right
nl := n.Left nl := n.Left
if nr == nil { if nr == nil {
...@@ -1412,7 +1397,6 @@ func genAsInitNoCheck(n *Node, reportOnly bool) bool { ...@@ -1412,7 +1397,6 @@ func genAsInitNoCheck(n *Node, reportOnly bool) bool {
return false return false
} }
if !reportOnly {
nam.Xoffset += int64(array_array) nam.Xoffset += int64(array_array)
gdata(&nam, ptr, Widthptr) gdata(&nam, ptr, Widthptr)
...@@ -1423,14 +1407,11 @@ func genAsInitNoCheck(n *Node, reportOnly bool) bool { ...@@ -1423,14 +1407,11 @@ func genAsInitNoCheck(n *Node, reportOnly bool) bool {
nam.Xoffset += int64(array_cap) - int64(array_nel) nam.Xoffset += int64(array_cap) - int64(array_nel)
gdata(&nam, &nod1, Widthint) gdata(&nam, &nod1, Widthint)
}
return true return true
case OLITERAL: case OLITERAL:
if !reportOnly {
gdata(&nam, nr, int(nr.Type.Width)) gdata(&nam, nr, int(nr.Type.Width))
}
return true return true
} }
} }
...@@ -643,9 +643,10 @@ func (s *state) stmt(n *Node) { ...@@ -643,9 +643,10 @@ func (s *state) stmt(n *Node) {
case OAS, OASWB: case OAS, OASWB:
// Generate static data rather than code, if possible. // Generate static data rather than code, if possible.
if gen_as_init(n, true) { if n.IsStatic {
if !gen_as_init(n, false) { if !genAsInitNoCheck(n) {
Fatalf("non-static data marked as static: %v\n\n", n) Dump("\ngen_as_init", n)
Fatalf("gen_as_init couldn't generate static data")
} }
return return
} }
......
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