diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-11-23 19:50:54 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-11-23 19:50:54 -0800 |
commit | 618396e526c9abe855215bcc09e1151958086b2b (patch) | |
tree | 81c6d19c2ed0e7156c52cb98d78ca0c4a3dfdf5b /lib/Target/CppBackend/CPPBackend.cpp | |
parent | 63ba962a099753627cebaaa0a49440d2b898e7d0 (diff) |
handle int/float bitcasts
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r-- | lib/Target/CppBackend/CPPBackend.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index 24d159cfc9..8ef978d037 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -1539,8 +1539,7 @@ std::string CppWriter::generateInstruction(const Instruction *I) { case Instruction::FPToUI: case Instruction::FPToSI: case Instruction::UIToFP: - case Instruction::SIToFP: - case Instruction::BitCast: { + case Instruction::SIToFP: { text = getAssign(iName, I->getType()); switch (I->getOpcode()) { case Instruction::Trunc: { @@ -1554,14 +1553,13 @@ std::string CppWriter::generateInstruction(const Instruction *I) { text += getValueAsStr(I->getOperand(0)) + " << " + bits + " >> " + bits; break; } - case Instruction::FPExt: text += opNames[0]; break; - case Instruction::SIToFP: text += getCast(getValueAsParenStr(I->getOperand(0)), I->getType()); break; - case Instruction::BitCast: text += getValueAsCastStr(I->getOperand(0)); break; - case Instruction::FPTrunc: Out << "FPTruncInst"; break; case Instruction::ZExt: Out << "ZExtInst"; break; + case Instruction::FPExt: text += opNames[0]; break; // TODO: fround + case Instruction::FPTrunc: text += opNames[0]; break; // TODO: fround + case Instruction::SIToFP: text += getCast(getValueAsCastParenStr(I->getOperand(0), ASM_SIGNED), I->getType()); break; + case Instruction::UIToFP: text += getCast(getValueAsCastParenStr(I->getOperand(0), ASM_UNSIGNED), I->getType()); break; case Instruction::FPToUI: Out << "FPToUIInst"; break; case Instruction::FPToSI: Out << "FPToSIInst"; break; - case Instruction::UIToFP: Out << "UIToFPInst"; break; case Instruction::PtrToInt: Out << "PtrToIntInst"; break; case Instruction::IntToPtr: Out << "IntToPtrInst"; break; default: llvm_unreachable("Unreachable"); @@ -1569,6 +1567,23 @@ std::string CppWriter::generateInstruction(const Instruction *I) { text += ";"; break; } + case Instruction::BitCast: { + text = getAssign(iName, I->getType()); + // Most bitcasts are no-ops for us. However, the exception is int to float and float to int + Type *InType = I->getOperand(0)->getType(); + Type *OutType = I->getType(); + std::string V = getValueAsStr(I->getOperand(0)); + if (InType->isIntegerTy() && OutType->isFloatingPointTy()) { + assert(InType->getIntegerBitWidth() == 32); + text = "HEAP32[tempDoublePtr>>2]=" + V + ";" + text + "HEAPF32[tempDoublePtr>>2];"; + } else if (OutType->isIntegerTy() && InType->isFloatingPointTy()) { + assert(OutType->getIntegerBitWidth() == 32); + text = "HEAPF32[tempDoublePtr>>2]=" + V + ";" + text + "HEAP32[tempDoublePtr>>2];"; + } else { + text += V + ";"; + } + break; + } case Instruction::Call: { const CallInst* call = cast<CallInst>(I); const int numArgs = call->getNumArgOperands(); |