summaryrefslogtreecommitdiffstats
path: root/llvm/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
commitbed9dc423ceadd08500869cf03e4c0819145d48b (patch)
tree1f39c25a045eca2e6d11262ae1be517e661d4010 /llvm/tools/llvm2cpp/CppWriter.cpp
parenta07765b8f4d9da2836d8f89b26d7f476715dffb4 (diff)
downloadbcm5719-llvm-bed9dc423ceadd08500869cf03e4c0819145d48b.tar.gz
bcm5719-llvm-bed9dc423ceadd08500869cf03e4c0819145d48b.zip
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.) llvm-svn: 41747
Diffstat (limited to 'llvm/tools/llvm2cpp/CppWriter.cpp')
-rw-r--r--llvm/tools/llvm2cpp/CppWriter.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/tools/llvm2cpp/CppWriter.cpp b/llvm/tools/llvm2cpp/CppWriter.cpp
index 0b7b0eea002..1551dc3be78 100644
--- a/llvm/tools/llvm2cpp/CppWriter.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud