diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-11-23 11:18:43 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-11-23 11:18:43 -0800 |
commit | 977c5ca8661d21cce6d232d9b196a06e31e0afc9 (patch) | |
tree | 2c6b6ff7f09159a3168bf94868fed8453a8faaf3 /lib/Target/CppBackend/CPPBackend.cpp | |
parent | 7d90819cb991b4537b1f6857b0a61ac955285b56 (diff) |
split out cast and non-cast versions of getValueAsStr
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r-- | lib/Target/CppBackend/CPPBackend.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index 159d048690..d4d720366c 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -187,7 +187,9 @@ namespace { std::string getPtr(const Value* Ptr); std::string getConstant(const Constant*); std::string getValueAsStr(const Value*); + std::string getValueAsCastStr(const Value*); std::string getValueAsParenStr(const Value*); + std::string getValueAsCastParenStr(const Value*); std::string getCppName(Type* val); inline void printCppName(Type* val); @@ -1181,6 +1183,14 @@ std::string CppWriter::getValueAsStr(const Value* V) { if (const Constant *CV = dyn_cast<Constant>(V)) { return getConstant(CV); } else { + return getCppName(V); + } +} + +std::string CppWriter::getValueAsCastStr(const Value* V) { + if (const Constant *CV = dyn_cast<Constant>(V)) { + return getConstant(CV); + } else { return getCast(getCppName(V), V->getType()); } } @@ -1189,6 +1199,10 @@ std::string CppWriter::getValueAsParenStr(const Value* V) { return "(" + getValueAsStr(V) + ")"; } +std::string CppWriter::getValueAsCastParenStr(const Value* V) { + return "(" + getValueAsCastStr(V) + ")"; +} + // generateInstruction - This member is called for each Instruction in a function. std::string CppWriter::generateInstruction(const Instruction *I) { std::string text = ""; @@ -1219,7 +1233,7 @@ std::string CppWriter::generateInstruction(const Instruction *I) { if (RV == NULL) { text += ";"; } else { - text += " " + getValueAsStr(RV) + ";"; + text += " " + getValueAsCastStr(RV) + ";"; } break; } @@ -1365,7 +1379,7 @@ std::string CppWriter::generateInstruction(const Instruction *I) { break; } case Instruction::ICmp: { - text = getAssign(iName, Type::getInt32Ty(I->getContext())) + "(" + getValueAsStr(I->getOperand(0)) + ")"; + text = getAssign(iName, Type::getInt32Ty(I->getContext())) + "(" + getValueAsCastStr(I->getOperand(0)) + ")"; switch (cast<ICmpInst>(I)->getPredicate()) { case ICmpInst::ICMP_EQ: text += "=="; break; case ICmpInst::ICMP_NE: text += "!="; break; @@ -1380,7 +1394,7 @@ std::string CppWriter::generateInstruction(const Instruction *I) { case ICmpInst::ICMP_SGT: text += ">"; break; default: text += "ICmpInst::BAD_ICMP_PREDICATE"; break; } - text += "(" + getValueAsStr(I->getOperand(1)) + ")"; + text += "(" + getValueAsCastStr(I->getOperand(1)) + ")"; break; } case Instruction::Alloca: { @@ -1453,10 +1467,10 @@ std::string CppWriter::generateInstruction(const Instruction *I) { unsigned outBits = I->getType()->getIntegerBitWidth(); text = getAssign(iName, I->getType()) + getCppName(I->getOperand(0)) + "&" + utostr(pow(2, outBits)-1) + ";"; break; } - case Instruction::SExt: text = getAssign(iName, I->getOperand(0)->getType()) + getValueAsStr(I->getOperand(0)) + ";"; 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()) + getValueAsStr(I->getOperand(0)) + ";"; break; + case Instruction::BitCast: text = getAssign(iName, I->getOperand(0)->getType()) + getValueAsCastStr(I->getOperand(0)) + ";"; break; case Instruction::FPTrunc: Out << "FPTruncInst"; break; case Instruction::ZExt: Out << "ZExtInst"; break; case Instruction::FPToUI: Out << "FPToUIInst"; break; @@ -1480,7 +1494,7 @@ std::string CppWriter::generateInstruction(const Instruction *I) { if (t && (GV = dyn_cast<GlobalVariable>(Arg))) { text += utostr(getGlobalAddress(GV->getName().str())); } else { - text += getValueAsStr(call->getArgOperand(i)); + text += getValueAsCastStr(call->getArgOperand(i)); // FIXME: differentiate ffi calls } if (i < numArgs - 1) text += ", "; } |