]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: refactor out zero value creation
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 20 Jul 2015 22:30:52 +0000 (15:30 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 21 Jul 2015 00:08:59 +0000 (00:08 +0000)
This will be used in a subsequent commit.

Change-Id: I43eca21f4692d99e164c9f6be0760597c46e6a26
Reviewed-on: https://go-review.googlesource.com/12440
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/ssa.go

index 2dad3e1a10da5ccfddd8ffc8d8818c4d5bc2d093..d4e4298b39659779b0d2e2d98ed32d52424cd976 100644 (file)
@@ -663,16 +663,7 @@ func (s *state) assign(op uint8, left *Node, right *Node) {
                        s.vars[&memvar] = s.newValue2I(ssa.OpZero, ssa.TypeMem, t.Size(), addr, s.mem())
                        return
                }
-               switch {
-               case t.IsString():
-                       val = s.entryNewValue0A(ssa.OpConst, left.Type, "")
-               case t.IsInteger() || t.IsPtr():
-                       val = s.entryNewValue0(ssa.OpConst, left.Type)
-               case t.IsBoolean():
-                       val = s.entryNewValue0A(ssa.OpConst, left.Type, false) // TODO: store bools as 0/1 in AuxInt?
-               default:
-                       s.Unimplementedf("zero for type %v not implemented", t)
-               }
+               val = s.zeroVal(t)
        } else {
                val = s.expr(right)
        }
@@ -686,6 +677,20 @@ func (s *state) assign(op uint8, left *Node, right *Node) {
        s.vars[&memvar] = s.newValue3(ssa.OpStore, ssa.TypeMem, addr, val, s.mem())
 }
 
+// zeroVal returns the zero value for type t.
+func (s *state) zeroVal(t *Type) *ssa.Value {
+       switch {
+       case t.IsString():
+               return s.entryNewValue0A(ssa.OpConst, t, "")
+       case t.IsInteger() || t.IsPtr():
+               return s.entryNewValue0(ssa.OpConst, t)
+       case t.IsBoolean():
+               return s.entryNewValue0A(ssa.OpConst, t, false) // TODO: store bools as 0/1 in AuxInt?
+       }
+       s.Unimplementedf("zero for type %v not implemented", t)
+       return nil
+}
+
 // addr converts the address of the expression n to SSA, adds it to s and returns the SSA result.
 // The value that the returned Value represents is guaranteed to be non-nil.
 func (s *state) addr(n *Node) *ssa.Value {