[dev.ssa] cmd/compile: refactor out zero value creation
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>
diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go
index 2dad3e1..d4e4298 100644
--- a/src/cmd/compile/internal/gc/ssa.go
+++ b/src/cmd/compile/internal/gc/ssa.go
@@ -663,16 +663,7 @@
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 @@
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 {