aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/CppBackend/CPPBackend.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-11-23 16:34:03 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-11-23 16:34:03 -0800
commit282c59a821c85d24f48008ec42683cbcb7f1219d (patch)
tree741bfc23abaeaab01524fd4a3e902260cc9da251 /lib/Target/CppBackend/CPPBackend.cpp
parent77581e308ae5d9638e64f8c7eb56b5db7bda69da (diff)
fix sext and refactor
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r--lib/Target/CppBackend/CPPBackend.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp
index b990804f01..85ad96877c 100644
--- a/lib/Target/CppBackend/CPPBackend.cpp
+++ b/lib/Target/CppBackend/CPPBackend.cpp
@@ -1396,7 +1396,7 @@ std::string CppWriter::generateInstruction(const Instruction *I) {
getValueAsParenStr(I->getOperand(1)),
I->getType()
) + ";"; break;
- case Instruction::Add: text += getParenCast(
+ case Instruction::Sub: text += getParenCast(
getValueAsParenStr(I->getOperand(0)) +
" - " +
getValueAsParenStr(I->getOperand(1)),
@@ -1541,17 +1541,22 @@ std::string CppWriter::generateInstruction(const Instruction *I) {
case Instruction::UIToFP:
case Instruction::SIToFP:
case Instruction::BitCast: {
+ text = getAssign(iName, I->getType());
switch (I->getOpcode()) {
case Instruction::Trunc: {
- Value *V = I->getOperand(0);
//unsigned inBits = V->getType()->getIntegerBitWidth();
unsigned outBits = I->getType()->getIntegerBitWidth();
- text = getAssign(iName, I->getType()) + getCppName(I->getOperand(0)) + "&" + utostr(pow(2, outBits)-1) + ";"; break;
+ text += getCppName(I->getOperand(0)) + "&" + utostr(pow(2, outBits)-1);
+ break;
}
- case Instruction::SExt: text = getAssign(iName, I->getOperand(0)->getType()) + getValueAsCastStr(I->getOperand(0)) + ";"; break;
- case Instruction::FPExt: text = getAssign(iName, Type::getFloatTy(I->getContext())) + opNames[0] + ";"; break;
- case Instruction::SIToFP: text = getAssign(iName, I->getType()) + getCast(getValueAsParenStr(I->getOperand(0)), I->getType()) + ";"; break;
- case Instruction::BitCast: text = getAssign(iName, I->getOperand(0)->getType()) + getValueAsCastStr(I->getOperand(0)) + ";"; break;
+ case Instruction::SExt: {
+ std::string bits = utostr(32 - I->getOperand(0)->getType()->getIntegerBitWidth());
+ 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::FPToUI: Out << "FPToUIInst"; break;
@@ -1561,6 +1566,7 @@ std::string CppWriter::generateInstruction(const Instruction *I) {
case Instruction::IntToPtr: Out << "IntToPtrInst"; break;
default: llvm_unreachable("Unreachable");
}
+ text += ";";
break;
}
case Instruction::Call: {