aboutsummaryrefslogtreecommitdiffstats
path: root/tools/llvm2cpp/CppWriter.cpp
diff options
context:
space:
mode:
authorDale Johannesen <dalej@apple.com>2007-09-06 18:13:44 +0000
committerDale Johannesen <dalej@apple.com>2007-09-06 18:13:44 +0000
commit43421b3dd70af5b70e71816521f37502c397cc65 (patch)
treeb314e17b0444f33dc3be37eaeaeaa8ea7dd1d17e /tools/llvm2cpp/CppWriter.cpp
parent325be7c608a37d87e4f3d731e11fa3dd34f529b5 (diff)
downloadexternal_llvm-43421b3dd70af5b70e71816521f37502c397cc65.zip
external_llvm-43421b3dd70af5b70e71816521f37502c397cc65.tar.gz
external_llvm-43421b3dd70af5b70e71816521f37502c397cc65.tar.bz2
Next round of APFloat changes.
Use APFloat in UpgradeParser and AsmParser. Change all references to ConstantFP to use the APFloat interface rather than double. Remove the ConstantFP double interfaces. Use APFloat functions for constant folding arithmetic and comparisons. (There are still way too many places APFloat is just a wrapper around host float/double, but we're getting there.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41747 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm2cpp/CppWriter.cpp')
-rw-r--r--tools/llvm2cpp/CppWriter.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/tools/llvm2cpp/CppWriter.cpp b/tools/llvm2cpp/CppWriter.cpp
index 0b7b0ee..1551dc3 100644
--- a/tools/llvm2cpp/CppWriter.cpp
+++ b/tools/llvm2cpp/CppWriter.cpp
@@ -209,25 +209,30 @@ CppWriter::error(const std::string& msg) {
// result so that we don't lose precision.
void
CppWriter::printCFP(const ConstantFP *CFP) {
+ APFloat APF = APFloat(CFP->getValueAPF()); // copy
+ if (CFP->getType() == Type::FloatTy)
+ APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
Out << "ConstantFP::get(";
if (CFP->getType() == Type::DoubleTy)
Out << "Type::DoubleTy, ";
else
Out << "Type::FloatTy, ";
+ Out << "APFloat(";
#if HAVE_PRINTF_A
char Buffer[100];
- sprintf(Buffer, "%A", CFP->getValue());
+ sprintf(Buffer, "%A", APF.convertToDouble());
if ((!strncmp(Buffer, "0x", 2) ||
!strncmp(Buffer, "-0x", 3) ||
!strncmp(Buffer, "+0x", 3)) &&
- (atof(Buffer) == CFP->getValue()))
+ APF.bitwiseIsEqual(APFloat(atof(Buffer)))) {
if (CFP->getType() == Type::DoubleTy)
Out << "BitsToDouble(" << Buffer << ")";
else
- Out << "BitsToFloat(" << Buffer << ")";
- else {
+ Out << "BitsToFloat((float)" << Buffer << ")";
+ Out << ")";
+ } else {
#endif
- std::string StrVal = ftostr(CFP->getValue());
+ std::string StrVal = ftostr(CFP->getValueAPF());
while (StrVal[0] == ' ')
StrVal.erase(StrVal.begin());
@@ -237,17 +242,21 @@ CppWriter::printCFP(const ConstantFP *CFP) {
if (((StrVal[0] >= '0' && StrVal[0] <= '9') ||
((StrVal[0] == '-' || StrVal[0] == '+') &&
(StrVal[1] >= '0' && StrVal[1] <= '9'))) &&
- (atof(StrVal.c_str()) == CFP->getValue()))
+ (CFP->isExactlyValue(atof(StrVal.c_str())))) {
if (CFP->getType() == Type::DoubleTy)
Out << StrVal;
else
- Out << StrVal;
+ Out << StrVal << "f";
+ }
else if (CFP->getType() == Type::DoubleTy)
- Out << "BitsToDouble(0x" << std::hex << DoubleToBits(CFP->getValue())
+ Out << "BitsToDouble(0x" << std::hex
+ << DoubleToBits(CFP->getValueAPF().convertToDouble())
<< std::dec << "ULL) /* " << StrVal << " */";
else
- Out << "BitsToFloat(0x" << std::hex << FloatToBits(CFP->getValue())
+ Out << "BitsToFloat(0x" << std::hex
+ << FloatToBits(CFP->getValueAPF().convertToFloat())
<< std::dec << "U) /* " << StrVal << " */";
+ Out << ")";
#if HAVE_PRINTF_A
}
#endif