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 {
return s.f.ConstInt8(s.peekLine(), t, c)
}
if n.Left != nil {
cond = s.expr(n.Left)
} else {
- cond = s.entryNewValue0I(ssa.OpConstBool, Types[TBOOL], 1) // 1 = true
+ cond = s.constBool(true)
}
b = s.endBlock()
b.Kind = ssa.BlockIf
case CTSTR:
return s.entryNewValue0A(ssa.OpConstString, n.Type, n.Val().U)
case CTBOOL:
- if 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
- }
+ return s.constBool(n.Val().U.(bool))
case CTNIL:
t := n.Type
switch {
case t.IsPtr():
return s.entryNewValue0(ssa.OpConstNil, t)
case t.IsBoolean():
- return s.entryNewValue0I(ssa.OpConstBool, Types[TBOOL], 0) // 0 = false
+ return s.constBool(false)
case t.IsInterface():
return s.entryNewValue0(ssa.OpConstInterface, t)
case t.IsSlice():
}
// 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 {
// TODO: cache?
return f.Entry.NewValue0I(line, OpConst8, t, int64(c))