diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-03-23 11:26:29 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-03-23 11:26:29 +0000 |
commit | cbf108eda6346ebff05af892fc5d4d9df2982802 (patch) | |
tree | 5a180bfddbc36335b3e334dfb5725eef888ba25c /llvm/lib/Target/CppBackend | |
parent | f74a4cd3dd676c58f9a61f20319048b615c41570 (diff) | |
download | bcm5719-llvm-cbf108eda6346ebff05af892fc5d4d9df2982802.tar.gz bcm5719-llvm-cbf108eda6346ebff05af892fc5d4d9df2982802.zip |
Move ftostr into its last user (cppbackend) and simplify it a bit.
New code should use raw_ostream.
llvm-svn: 153326
Diffstat (limited to 'llvm/lib/Target/CppBackend')
-rw-r--r-- | llvm/lib/Target/CppBackend/CPPBackend.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Target/CppBackend/CPPBackend.cpp b/llvm/lib/Target/CppBackend/CPPBackend.cpp index 107c6ccb47d..efa54d20885 100644 --- a/llvm/lib/Target/CppBackend/CPPBackend.cpp +++ b/llvm/lib/Target/CppBackend/CPPBackend.cpp @@ -195,6 +195,18 @@ void CppWriter::error(const std::string& msg) { report_fatal_error(msg); } +static inline std::string ftostr(const APFloat& V) { + std::string Buf; + if (&V.getSemantics() == &APFloat::IEEEdouble) { + raw_string_ostream(Buf) << V.convertToDouble(); + return Buf; + } else if (&V.getSemantics() == &APFloat::IEEEsingle) { + raw_string_ostream(Buf) << (double)V.convertToFloat(); + return Buf; + } + return "<unknown format in ftostr>"; // error +} + // printCFP - Print a floating point constant .. very carefully :) // This makes sure that conversion to/from floating yields the same binary // result so that we don't lose precision. |