]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: simplify generating static data
authorMatthew Dempsky <mdempsky@google.com>
Fri, 3 Feb 2017 22:45:26 +0000 (14:45 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Sat, 4 Feb 2017 01:29:40 +0000 (01:29 +0000)
Passes toolstash -cmp.

Change-Id: I4a72e3e130c38868ee8ecef32cad58748aa5be52
Reviewed-on: https://go-review.googlesource.com/36353
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

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

index 29819e92b2ccc9f779c0c34b03f89cab7240d475..756c31d954cea15016524623db1e9763473864ed 100644 (file)
@@ -1349,22 +1349,7 @@ func isvaluelit(n *Node) bool {
        return n.Op == OARRAYLIT || n.Op == OSTRUCTLIT
 }
 
-// gen_as_init attempts to emit static data for n and reports whether it succeeded.
-// 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
-       }
-
+func genAsInitNoCheck(n *Node) bool {
        nr := n.Right
        nl := n.Left
        if nr == nil {
@@ -1412,25 +1397,21 @@ func genAsInitNoCheck(n *Node, reportOnly bool) bool {
                        return false
                }
 
-               if !reportOnly {
-                       nam.Xoffset += int64(array_array)
-                       gdata(&nam, ptr, Widthptr)
+               nam.Xoffset += int64(array_array)
+               gdata(&nam, ptr, Widthptr)
 
-                       nam.Xoffset += int64(array_nel) - int64(array_array)
-                       var nod1 Node
-                       Nodconst(&nod1, Types[TINT], nr.Type.NumElem())
-                       gdata(&nam, &nod1, Widthint)
+               nam.Xoffset += int64(array_nel) - int64(array_array)
+               var nod1 Node
+               Nodconst(&nod1, Types[TINT], nr.Type.NumElem())
+               gdata(&nam, &nod1, Widthint)
 
-                       nam.Xoffset += int64(array_cap) - int64(array_nel)
-                       gdata(&nam, &nod1, Widthint)
-               }
+               nam.Xoffset += int64(array_cap) - int64(array_nel)
+               gdata(&nam, &nod1, Widthint)
 
                return true
 
        case OLITERAL:
-               if !reportOnly {
-                       gdata(&nam, nr, int(nr.Type.Width))
-               }
+               gdata(&nam, nr, int(nr.Type.Width))
                return true
        }
 }
index a1060d9a2b31c1b1c198feee04c2bc7045a65489..42ca491fbbe76fb5dbd1fafe9693224ed6c2fc74 100644 (file)
@@ -643,9 +643,10 @@ func (s *state) stmt(n *Node) {
 
        case OAS, OASWB:
                // Generate static data rather than code, if possible.
-               if gen_as_init(n, true) {
-                       if !gen_as_init(n, false) {
-                               Fatalf("non-static data marked as static: %v\n\n", n)
+               if n.IsStatic {
+                       if !genAsInitNoCheck(n) {
+                               Dump("\ngen_as_init", n)
+                               Fatalf("gen_as_init couldn't generate static data")
                        }
                        return
                }