diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-11-23 18:58:21 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-11-23 18:58:21 -0800 |
commit | 63ba962a099753627cebaaa0a49440d2b898e7d0 (patch) | |
tree | c2714aad74279179c503339dbbb278bac24978f2 /lib/Target/CppBackend/CPPBackend.cpp | |
parent | d943b3b49ea493997b92610b10013f9bc6ac76e5 (diff) |
use signedness in icmp
Diffstat (limited to 'lib/Target/CppBackend/CPPBackend.cpp')
-rw-r--r-- | lib/Target/CppBackend/CPPBackend.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index d04e148bf4..24d159cfc9 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -192,7 +192,7 @@ namespace { std::string getPtr(const Value* Ptr); std::string getConstant(const Constant*); std::string getValueAsStr(const Value*); - std::string getValueAsCastStr(const Value*); + std::string getValueAsCastStr(const Value*, Signedness sign=ASM_SIGNED); std::string getValueAsParenStr(const Value*); std::string getValueAsCastParenStr(const Value*, Signedness sign=ASM_SIGNED); std::string getCppName(Type* val); @@ -1242,11 +1242,11 @@ std::string CppWriter::getValueAsStr(const Value* V) { } } -std::string CppWriter::getValueAsCastStr(const Value* V) { +std::string CppWriter::getValueAsCastStr(const Value* V, Signedness sign) { if (const Constant *CV = dyn_cast<Constant>(V)) { return getConstant(CV); } else { - return getCast(getCppName(V), V->getType()); + return getCast(getCppName(V), V->getType(), sign); } } @@ -1452,11 +1452,17 @@ std::string CppWriter::generateInstruction(const Instruction *I) { break; } case Instruction::ICmp: { - text = getAssign(iName, Type::getInt32Ty(I->getContext())) + "(" + getValueAsCastStr(I->getOperand(0)) + ")"; - switch (cast<ICmpInst>(I)->getPredicate()) { + unsigned predicate = cast<ICmpInst>(I)->getPredicate(); + Signedness sign = (predicate == ICmpInst::ICMP_ULE || + predicate == ICmpInst::ICMP_UGE || + predicate == ICmpInst::ICMP_ULT || + predicate == ICmpInst::ICMP_UGT) ? ASM_UNSIGNED : ASM_SIGNED; + text = getAssign(iName, Type::getInt32Ty(I->getContext())) + "(" + + getValueAsCastStr(I->getOperand(0), sign) + + ")"; + switch (predicate) { case ICmpInst::ICMP_EQ: text += "=="; break; case ICmpInst::ICMP_NE: text += "!="; break; - // TODO: handle signed and unsigned case ICmpInst::ICMP_ULE: text += "<="; break; case ICmpInst::ICMP_SLE: text += "<="; break; case ICmpInst::ICMP_UGE: text += ">="; break; @@ -1467,7 +1473,9 @@ std::string CppWriter::generateInstruction(const Instruction *I) { case ICmpInst::ICMP_SGT: text += ">"; break; default: text += "ICmpInst::BAD_ICMP_PREDICATE"; break; } - text += "(" + getValueAsCastStr(I->getOperand(1)) + ")"; + text += "(" + + getValueAsCastStr(I->getOperand(1), sign) + + ")"; break; } case Instruction::Alloca: { |