llvm.org GIT mirror llvm / e68e775
Move ftostr into its last user (cppbackend) and simplify it a bit. New code should use raw_ostream. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153326 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 8 years ago
3 changed file(s) with 13 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
1414 #define LLVM_ADT_STRINGEXTRAS_H
1515
1616 #include "llvm/Support/DataTypes.h"
17 #include "llvm/ADT/APFloat.h"
18 #include "llvm/ADT/DenseMapInfo.h"
1917 #include "llvm/ADT/StringRef.h"
20 #include
21 #include
22 #include
2318
2419 namespace llvm {
2520 template class SmallVectorImpl;
10095 return utostr(static_cast(X));
10196 }
10297
103 static inline std::string ftostr(double V) {
104 char Buffer[200];
105 sprintf(Buffer, "%20.6e", V);
106 char *B = Buffer;
107 while (*B == ' ') ++B;
108 return B;
109 }
110
111 static inline std::string ftostr(const APFloat& V) {
112 if (&V.getSemantics() == &APFloat::IEEEdouble)
113 return ftostr(V.convertToDouble());
114 else if (&V.getSemantics() == &APFloat::IEEEsingle)
115 return ftostr((double)V.convertToFloat());
116 return ""; // error
117 }
118
11998 /// StrInStrNoCase - Portable version of strcasestr. Locates the first
12099 /// occurrence of string 's1' in string 's2', ignoring case. Returns
121100 /// the offset of s2 in s1 or npos if s2 cannot be found.
192192
193193 void CppWriter::error(const std::string& msg) {
194194 report_fatal_error(msg);
195 }
196
197 static inline std::string ftostr(const APFloat& V) {
198 std::string Buf;
199 if (&V.getSemantics() == &APFloat::IEEEdouble) {
200 raw_string_ostream(Buf) << V.convertToDouble();
201 return Buf;
202 } else if (&V.getSemantics() == &APFloat::IEEEsingle) {
203 raw_string_ostream(Buf) << (double)V.convertToFloat();
204 return Buf;
205 }
206 return ""; // error
195207 }
196208
197209 // printCFP - Print a floating point constant .. very carefully :)
1717 #include "llvm/MC/MCExpr.h"
1818 #include "llvm/MC/MCInst.h"
1919 #include "llvm/MC/MCSymbol.h"
20 #include "llvm/ADT/APFloat.h"
2021 #include "llvm/ADT/StringExtras.h"
2122 #include "llvm/Support/ErrorHandling.h"
2223 #include "llvm/Support/raw_ostream.h"