diff --git a/ssa/expr.go b/ssa/expr.go index 50f6f732..19674755 100644 --- a/ssa/expr.go +++ b/ssa/expr.go @@ -107,6 +107,11 @@ func (p Program) IntVal(v uint64, t Type) Expr { return Expr{ret, t} } +func (p Program) FloatVal(v float64, t Type) Expr { + ret := llvm.ConstFloat(t.ll, v) + return Expr{ret, t} +} + // Val returns a constant expression. func (p Program) Val(v interface{}) Expr { switch v := v.(type) { @@ -130,7 +135,7 @@ func (b Builder) Const(v constant.Value, typ Type) Expr { if v == nil { return prog.Null(typ) } - switch t := typ.t.(type) { + switch t := types.Default(typ.t).(type) { case *types.Basic: kind := t.Kind() switch { @@ -140,6 +145,10 @@ func (b Builder) Const(v constant.Value, typ Type) Expr { if v, exact := constant.Uint64Val(v); exact { return prog.IntVal(v, typ) } + case kind == types.Float32 || kind == types.Float64: + if v, exact := constant.Float64Val(v); exact { + return prog.FloatVal(v, typ) + } case kind == types.String: return prog.StringVal(constant.StringVal(v)) } diff --git a/ssa/type.go b/ssa/type.go index 6b02513a..b5e4bb85 100644 --- a/ssa/type.go +++ b/ssa/type.go @@ -208,7 +208,7 @@ func (p Program) tyInt64() llvm.Type { } func (p Program) toLLVMType(typ types.Type) Type { - switch t := typ.(type) { + switch t := types.Default(typ).(type) { case *types.Basic: switch t.Kind() { case types.Int: