mirror of
https://github.com/golang/go.git
synced 2025-05-29 03:11:26 +00:00
[dev.ssa] cmd/compile: add constBool helpers
Change-Id: I1f93ea65bbdc895cd4eff7545e1688a64d85aae5 Reviewed-on: https://go-review.googlesource.com/14520 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
f5c53e0deb
commit
cea441427e
@ -371,7 +371,10 @@ func (s *state) entryNewValue2(op ssa.Op, t ssa.Type, arg0, arg1 *ssa.Value) *ss
|
|||||||
return s.f.Entry.NewValue2(s.peekLine(), op, t, arg0, arg1)
|
return s.f.Entry.NewValue2(s.peekLine(), op, t, arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// constInt* routines add a new const int value to the entry block.
|
// const* routines add a new const value to the entry block.
|
||||||
|
func (s *state) constBool(c bool) *ssa.Value {
|
||||||
|
return s.f.ConstBool(s.peekLine(), Types[TBOOL], c)
|
||||||
|
}
|
||||||
func (s *state) constInt8(t ssa.Type, c int8) *ssa.Value {
|
func (s *state) constInt8(t ssa.Type, c int8) *ssa.Value {
|
||||||
return s.f.ConstInt8(s.peekLine(), t, c)
|
return s.f.ConstInt8(s.peekLine(), t, c)
|
||||||
}
|
}
|
||||||
@ -647,7 +650,7 @@ func (s *state) stmt(n *Node) {
|
|||||||
if n.Left != nil {
|
if n.Left != nil {
|
||||||
cond = s.expr(n.Left)
|
cond = s.expr(n.Left)
|
||||||
} else {
|
} else {
|
||||||
cond = s.entryNewValue0I(ssa.OpConstBool, Types[TBOOL], 1) // 1 = true
|
cond = s.constBool(true)
|
||||||
}
|
}
|
||||||
b = s.endBlock()
|
b = s.endBlock()
|
||||||
b.Kind = ssa.BlockIf
|
b.Kind = ssa.BlockIf
|
||||||
@ -1223,11 +1226,7 @@ func (s *state) expr(n *Node) *ssa.Value {
|
|||||||
case CTSTR:
|
case CTSTR:
|
||||||
return s.entryNewValue0A(ssa.OpConstString, n.Type, n.Val().U)
|
return s.entryNewValue0A(ssa.OpConstString, n.Type, n.Val().U)
|
||||||
case CTBOOL:
|
case CTBOOL:
|
||||||
if n.Val().U.(bool) {
|
return s.constBool(n.Val().U.(bool))
|
||||||
return s.entryNewValue0I(ssa.OpConstBool, Types[TBOOL], 1) // 1 = true
|
|
||||||
} else {
|
|
||||||
return s.entryNewValue0I(ssa.OpConstBool, Types[TBOOL], 0) // 0 = false
|
|
||||||
}
|
|
||||||
case CTNIL:
|
case CTNIL:
|
||||||
t := n.Type
|
t := n.Type
|
||||||
switch {
|
switch {
|
||||||
@ -1947,7 +1946,7 @@ func (s *state) zeroVal(t *Type) *ssa.Value {
|
|||||||
case t.IsPtr():
|
case t.IsPtr():
|
||||||
return s.entryNewValue0(ssa.OpConstNil, t)
|
return s.entryNewValue0(ssa.OpConstNil, t)
|
||||||
case t.IsBoolean():
|
case t.IsBoolean():
|
||||||
return s.entryNewValue0I(ssa.OpConstBool, Types[TBOOL], 0) // 0 = false
|
return s.constBool(false)
|
||||||
case t.IsInterface():
|
case t.IsInterface():
|
||||||
return s.entryNewValue0(ssa.OpConstInterface, t)
|
return s.entryNewValue0(ssa.OpConstInterface, t)
|
||||||
case t.IsSlice():
|
case t.IsSlice():
|
||||||
|
@ -266,6 +266,14 @@ func (b *Block) NewValue3I(line int32, op Op, t Type, aux int64, arg0, arg1, arg
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConstInt returns an int constant representing its argument.
|
// ConstInt returns an int constant representing its argument.
|
||||||
|
func (f *Func) ConstBool(line int32, t Type, c bool) *Value {
|
||||||
|
// TODO: cache?
|
||||||
|
i := int64(0)
|
||||||
|
if c {
|
||||||
|
i = 1
|
||||||
|
}
|
||||||
|
return f.Entry.NewValue0I(line, OpConstBool, t, i)
|
||||||
|
}
|
||||||
func (f *Func) ConstInt8(line int32, t Type, c int8) *Value {
|
func (f *Func) ConstInt8(line int32, t Type, c int8) *Value {
|
||||||
// TODO: cache?
|
// TODO: cache?
|
||||||
return f.Entry.NewValue0I(line, OpConst8, t, int64(c))
|
return f.Entry.NewValue0I(line, OpConst8, t, int64(c))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user