Merge pull request #77 from visualfc/float
ssa: builder.const add float
This commit is contained in:
11
ssa/expr.go
11
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))
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user