Move ftostr into its last user (cppbackend) and simplify it a bit.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 23 Mar 2012 11:26:29 +0000 (11:26 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 23 Mar 2012 11:26:29 +0000 (11:26 +0000)
New code should use raw_ostream.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153326 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringExtras.h
lib/Target/CppBackend/CPPBackend.cpp
lib/Target/PTX/InstPrinter/PTXInstPrinter.cpp

index 4e0e018b6bd4189607d81bf662bedc2f055f86c6..655d884e7baaab2677fb8debe622b0ae65fe7062 100644 (file)
 #define LLVM_ADT_STRINGEXTRAS_H
 
 #include "llvm/Support/DataTypes.h"
-#include "llvm/ADT/APFloat.h"
-#include "llvm/ADT/DenseMapInfo.h"
 #include "llvm/ADT/StringRef.h"
-#include <cctype>
-#include <cstdio>
-#include <string>
 
 namespace llvm {
 template<typename T> class SmallVectorImpl;
@@ -101,22 +96,6 @@ static inline std::string itostr(int64_t X) {
     return utostr(static_cast<uint64_t>(X));
 }
 
-static inline std::string ftostr(double V) {
-  char Buffer[200];
-  sprintf(Buffer, "%20.6e", V);
-  char *B = Buffer;
-  while (*B == ' ') ++B;
-  return B;
-}
-
-static inline std::string ftostr(const APFloat& V) {
-  if (&V.getSemantics() == &APFloat::IEEEdouble)
-    return ftostr(V.convertToDouble());
-  else if (&V.getSemantics() == &APFloat::IEEEsingle)
-    return ftostr((double)V.convertToFloat());
-  return "<unknown format in ftostr>"; // error
-}
-
 /// StrInStrNoCase - Portable version of strcasestr.  Locates the first
 /// occurrence of string 's1' in string 's2', ignoring case.  Returns
 /// the offset of s2 in s1 or npos if s2 cannot be found.
index 107c6ccb47dddcc876b882429b8d2fbb8d5da4a0..efa54d20885a778fd58a757102b4cc45768c5e63 100644 (file)
@@ -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.
index ec7e2a75eaa46b9f2747890bdf41904a1bcf6dd4..80fb4de94865eb7ce937490036e42b76315715b0 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCSymbol.h"
+#include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"