about summary refs log tree commit diff homepage
path: root/lib/Core
diff options
context:
space:
mode:
authorStepan Dyatkovskiy <stpworld@narod.ru>2012-03-08 07:07:02 +0000
committerStepan Dyatkovskiy <stpworld@narod.ru>2012-03-08 07:07:02 +0000
commit4a6357101c5d7ea3511de73e4aac374c695f82e1 (patch)
tree78ec59ed1e933aa5aad8bebff5c2a9f00f55dc39 /lib/Core
parent710b2fbe5445a843bba2f0edca038b3c9252bc64 (diff)
downloadklee-4a6357101c5d7ea3511de73e4aac374c695f82e1.tar.gz
Taken into account Duncan's comments for r149481 dated by 2nd Feb 2012:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20120130/136146.html

Implemented CaseIterator and it solves almost all described issues: we don't need to mix operand/case/successor indexing anymore. Base iterator class is implemented as a template since it may be initialized either from "const SwitchInst*" or from "SwitchInst*".

ConstCaseIt is just a read-only iterator.
CaseIt is read-write iterator; it allows to change case successor and case value.

Usage of iterator allows totally remove resolveXXXX methods. All indexing convertions done automatically inside the iterator's getters.

Main way of iterator usage looks like this:
SwitchInst *SI = ... // intialize it somehow

for (SwitchInst::CaseIt i = SI->caseBegin(), e = SI->caseEnd(); i != e; ++i) {
  BasicBlock *BB = i.getCaseSuccessor();
  ConstantInt *V = i.getCaseValue();
  // Do something.
}

If you want to convert case number to TerminatorInst successor index, just use getSuccessorIndex iterator's method.
If you want initialize iterator from TerminatorInst successor index, use CaseIt::fromSuccessorIndex(...) method.

There are also related changes in llvm-clients: klee and clang.



git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@152299 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Core')
-rw-r--r--lib/Core/Executor.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index d9983493..96c99ee5 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -1498,7 +1498,6 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
   case Instruction::Switch: {
     SwitchInst *si = cast<SwitchInst>(i);
     ref<Expr> cond = eval(ki, 0, state).value;
-    unsigned cases = si->getNumCases();
     BasicBlock *bb = si->getParent();
 
     cond = toUnique(state, cond);
@@ -1509,7 +1508,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
         cast<IntegerType>(si->getCondition()->getType());
       ConstantInt *ci = ConstantInt::get(Ty, CE->getZExtValue());
 #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1)
-      unsigned index = si->resolveSuccessorIndex(si->findCaseValue(ci));
+      unsigned index = si->findCaseValue(ci).getSuccessorIndex();
 #else
       unsigned index = si->findCaseValue(ci);
 #endif
@@ -1518,11 +1517,12 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
       std::map<BasicBlock*, ref<Expr> > targets;
       ref<Expr> isDefault = ConstantExpr::alloc(1, Expr::Bool);
 #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1)      
-      for (unsigned i=0; i<cases; ++i) {
+      for (SwitchInst::CaseIt i = si->caseBegin(), e = si->caseEnd();
+           i != e; ++i) {
 #else
-      for (unsigned i=1; i<cases; ++i) {  
+      for (unsigned i=1, cases = si->getNumCases(); i<cases; ++i) {
 #endif
-        ref<Expr> value = evalConstant(si->getCaseValue(i));
+        ref<Expr> value = evalConstant(i.getCaseValue());
         ref<Expr> match = EqExpr::create(cond, value);
         isDefault = AndExpr::create(isDefault, Expr::createIsZero(match));
         bool result;
@@ -1531,7 +1531,7 @@ void Executor::executeInstruction(ExecutionState &state, KInstruction *ki) {
         (void) success;
         if (result) {
 #if LLVM_VERSION_CODE >= LLVM_VERSION(3, 1)
-          BasicBlock *caseSuccessor = si->getCaseSuccessor(i);
+          BasicBlock *caseSuccessor = i.getCaseSuccessor();
 #else
           BasicBlock *caseSuccessor = si->getSuccessor(i);
 #endif