diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-09-29 20:21:17 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-09-29 20:21:17 +0000 |
commit | bb5a7442e362776621112dc9453e546a55878e79 (patch) | |
tree | 6f504615cfbcf1d88494b1688f90eecb2998855a /lib/Target/CppBackend | |
parent | 0066f9290e95dddedc47472e927319893929b05b (diff) | |
download | llvm-bb5a7442e362776621112dc9453e546a55878e79.tar.gz llvm-bb5a7442e362776621112dc9453e546a55878e79.tar.bz2 llvm-bb5a7442e362776621112dc9453e546a55878e79.tar.xz |
Clean up uses of switch instructions so they are not dependent on the operand ordering. Patch by Stepan Dyatkovskiy.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140803 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/CppBackend')
-rw-r--r-- | lib/Target/CppBackend/CPPBackend.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp index 8d6eda1204..16401a8f98 100644 --- a/lib/Target/CppBackend/CPPBackend.cpp +++ b/lib/Target/CppBackend/CPPBackend.cpp @@ -154,7 +154,7 @@ namespace { void printFunctionHead(const Function *F); void printFunctionBody(const Function *F); void printInstruction(const Instruction *I, const std::string& bbname); - std::string getOpName(Value*); + std::string getOpName(const Value*); void printModuleBody(); }; @@ -979,7 +979,7 @@ void CppWriter::printVariableBody(const GlobalVariable *GV) { } } -std::string CppWriter::getOpName(Value* V) { +std::string CppWriter::getOpName(const Value* V) { if (!isa<Instruction>(V) || DefinedValues.find(V) != DefinedValues.end()) return getCppName(V); @@ -1044,14 +1044,17 @@ void CppWriter::printInstruction(const Instruction *I, case Instruction::Switch: { const SwitchInst *SI = cast<SwitchInst>(I); Out << "SwitchInst* " << iName << " = SwitchInst::Create(" - << opNames[0] << ", " - << opNames[1] << ", " + << getOpName(SI->getCondition()) << ", " + << getOpName(SI->getDefaultDest()) << ", " << SI->getNumCases() << ", " << bbname << ");"; nl(Out); - for (unsigned i = 2; i != SI->getNumOperands(); i += 2) { + unsigned NumCases = SI->getNumCases(); + for (unsigned i = 1; i < NumCases; ++i) { + const ConstantInt* CaseVal = SI->getCaseValue(i); + const BasicBlock* BB = SI->getSuccessor(i); Out << iName << "->addCase(" - << opNames[i] << ", " - << opNames[i+1] << ");"; + << getOpName(CaseVal) << ", " + << getOpName(BB) << ");"; nl(Out); } break; |