#include <algorithm>
#include <sstream>
+
+/* FIXME: This should be autoconf'd! */
+#define HAS_C99_HEXADECIMAL_CONSTANTS 1
+
namespace {
class CWriter : public Pass, public InstVisitor<CWriter> {
std::ostream &Out;
// only deal in IEEE FP).
//
static bool isFPCSafeToPrint(const ConstantFP *CFP) {
+#if HAS_C99_HEXADECIMAL_CONSTANTS
+ char Buffer[100];
+ sprintf(Buffer, "%a", CFP->getValue());
+
+ if (!strncmp(Buffer, "0x", 2) ||
+ !strncmp(Buffer, "-0x", 3) ||
+ !strncmp(Buffer, "+0x", 3))
+ return atof(Buffer) == CFP->getValue();
+ return false;
+#else
std::string StrVal = ftostr(CFP->getValue());
while (StrVal[0] == ' ')
// Reparse stringized version!
return atof(StrVal.c_str()) == CFP->getValue();
return false;
+#endif
}
// printConstant - The LLVM Constant to C Constant converter.
Out << "(*(" << (FPC->getType() == Type::FloatTy ? "float" : "double")
<< "*)&FPConstant" << I->second << ")";
} else {
+#if HAS_C99_HEXADECIMAL_CONSTANTS
// Print out the constant as a floating point number.
+ char Buffer[100];
+ sprintf(Buffer, "%a", FPC->getValue());
+ Out << Buffer << " /*" << FPC->getValue() << "*/ ";
+#else
Out << ftostr(FPC->getValue());
+#endif
}
break;
}
emittedInvoke = true;
}
-static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
+static bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
// If PHI nodes need copies, we need the copy code...
if (isa<PHINode>(To->front()) ||
From->getNext() != To) // Not directly successor, need goto
//
void CWriter::visitBranchInst(BranchInst &I) {
if (I.isConditional()) {
- if (isGotoCodeNeccessary(I.getParent(), I.getSuccessor(0))) {
+ if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(0))) {
Out << " if (";
writeOperand(I.getCondition());
Out << ") {\n";
printBranchToBlock(I.getParent(), I.getSuccessor(0), 2);
- if (isGotoCodeNeccessary(I.getParent(), I.getSuccessor(1))) {
+ if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(1))) {
Out << " } else {\n";
printBranchToBlock(I.getParent(), I.getSuccessor(1), 2);
}
#include <algorithm>
#include <sstream>
+
+/* FIXME: This should be autoconf'd! */
+#define HAS_C99_HEXADECIMAL_CONSTANTS 1
+
namespace {
class CWriter : public Pass, public InstVisitor<CWriter> {
std::ostream &Out;
// only deal in IEEE FP).
//
static bool isFPCSafeToPrint(const ConstantFP *CFP) {
+#if HAS_C99_HEXADECIMAL_CONSTANTS
+ char Buffer[100];
+ sprintf(Buffer, "%a", CFP->getValue());
+
+ if (!strncmp(Buffer, "0x", 2) ||
+ !strncmp(Buffer, "-0x", 3) ||
+ !strncmp(Buffer, "+0x", 3))
+ return atof(Buffer) == CFP->getValue();
+ return false;
+#else
std::string StrVal = ftostr(CFP->getValue());
while (StrVal[0] == ' ')
// Reparse stringized version!
return atof(StrVal.c_str()) == CFP->getValue();
return false;
+#endif
}
// printConstant - The LLVM Constant to C Constant converter.
Out << "(*(" << (FPC->getType() == Type::FloatTy ? "float" : "double")
<< "*)&FPConstant" << I->second << ")";
} else {
+#if HAS_C99_HEXADECIMAL_CONSTANTS
// Print out the constant as a floating point number.
+ char Buffer[100];
+ sprintf(Buffer, "%a", FPC->getValue());
+ Out << Buffer << " /*" << FPC->getValue() << "*/ ";
+#else
Out << ftostr(FPC->getValue());
+#endif
}
break;
}
emittedInvoke = true;
}
-static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
+static bool isGotoCodeNecessary(BasicBlock *From, BasicBlock *To) {
// If PHI nodes need copies, we need the copy code...
if (isa<PHINode>(To->front()) ||
From->getNext() != To) // Not directly successor, need goto
//
void CWriter::visitBranchInst(BranchInst &I) {
if (I.isConditional()) {
- if (isGotoCodeNeccessary(I.getParent(), I.getSuccessor(0))) {
+ if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(0))) {
Out << " if (";
writeOperand(I.getCondition());
Out << ") {\n";
printBranchToBlock(I.getParent(), I.getSuccessor(0), 2);
- if (isGotoCodeNeccessary(I.getParent(), I.getSuccessor(1))) {
+ if (isGotoCodeNecessary(I.getParent(), I.getSuccessor(1))) {
Out << " } else {\n";
printBranchToBlock(I.getParent(), I.getSuccessor(1), 2);
}