Copy printfloat() from original runtime

I've tried writing my own, but I couldn't make it correct in all cases.
So just copy the one from upstream for now, hopefully to be replaced at
some point.

TODO: add a printfloat32() implementation, now it just casts to float64.
This will be useful for embedded systems that sometimes have float32 but
not float64.
This commit is contained in:
Ayke van Laethem
2018-08-31 21:25:32 +02:00
parent 46d2d2e777
commit 94ce893ab4
2 changed files with 90 additions and 0 deletions
+4
View File
@@ -1303,6 +1303,10 @@ func (c *Compiler) parseBuiltin(frame *Frame, args []ssa.Value, callName string)
c.builder.CreateCall(fn, []llvm.Value{value}, "")
} else if typ.Kind() == types.Bool {
c.builder.CreateCall(c.mod.NamedFunction("runtime.printbool"), []llvm.Value{value}, "")
} else if typ.Kind() == types.Float32 {
c.builder.CreateCall(c.mod.NamedFunction("runtime.printfloat32"), []llvm.Value{value}, "")
} else if typ.Kind() == types.Float64 {
c.builder.CreateCall(c.mod.NamedFunction("runtime.printfloat64"), []llvm.Value{value}, "")
} else {
return llvm.Value{}, errors.New("unknown basic arg type: " + typ.String())
}