[llvm-commits] CVS: llvm/tools/lli/Interpreter/Execution.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Apr 22 15:35:01 PDT 2003
Changes in directory llvm/tools/lli/Interpreter:
Execution.cpp updated: 1.77 -> 1.78
---
Log message:
Add support to LLI for switch instruction
---
Diffs of the changes:
Index: llvm/tools/lli/Interpreter/Execution.cpp
diff -u llvm/tools/lli/Interpreter/Execution.cpp:1.77 llvm/tools/lli/Interpreter/Execution.cpp:1.78
--- llvm/tools/lli/Interpreter/Execution.cpp:1.77 Mon Apr 21 17:43:32 2003
+++ llvm/tools/lli/Interpreter/Execution.cpp Tue Apr 22 15:34:47 2003
@@ -635,6 +635,27 @@
SF.CurInst = SF.CurBB->begin(); // Update new instruction ptr...
}
+static void executeSwitch(SwitchInst &I, ExecutionContext &SF) {
+ GenericValue CondVal = getOperandValue(I.getOperand(0), SF);
+ const Type *ElTy = I.getOperand(0)->getType();
+ SF.PrevBB = SF.CurBB; // Update PrevBB so that PHI nodes work...
+ BasicBlock *Dest = 0;
+
+ // Check to see if any of the cases match...
+ for (unsigned i = 2, e = I.getNumOperands(); i != e; i += 2) {
+ if (executeSetEQInst(CondVal,
+ getOperandValue(I.getOperand(i), SF),ElTy,SF).BoolVal){
+ Dest = cast<BasicBlock>(I.getOperand(i+1));
+ break;
+ }
+ }
+
+ if (!Dest) Dest = I.getDefaultDest(); // No cases matched: use default
+ SF.CurBB = Dest; // Update CurBB to branch destination
+ SF.CurInst = SF.CurBB->begin(); // Update new instruction ptr...
+}
+
+
//===----------------------------------------------------------------------===//
// Memory Instruction Implementations
//===----------------------------------------------------------------------===//
@@ -1106,6 +1127,7 @@
// Terminators
case Instruction::Ret: executeRetInst (cast<ReturnInst>(I), SF); break;
case Instruction::Br: executeBrInst (cast<BranchInst>(I), SF); break;
+ case Instruction::Switch: executeSwitch (cast<SwitchInst>(I), SF); break;
// Memory Instructions
case Instruction::Alloca:
case Instruction::Malloc: executeAllocInst((AllocationInst&)I, SF); break;
More information about the llvm-commits
mailing list