1 //===-- iSwitch.cpp - Implement the Switch instruction -----------*- C++ -*--=//
3 // This file implements the Switch instruction...
5 //===----------------------------------------------------------------------===//
7 #include "llvm/iTerminators.h"
8 #include "llvm/BasicBlock.h"
10 SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
11 Instruction *InsertBefore)
12 : TerminatorInst(Instruction::Switch, InsertBefore) {
13 assert(V && DefaultDest);
14 Operands.push_back(Use(V, this));
15 Operands.push_back(Use(DefaultDest, this));
18 SwitchInst::SwitchInst(const SwitchInst &SI)
19 : TerminatorInst(Instruction::Switch) {
20 Operands.reserve(SI.Operands.size());
22 for (unsigned i = 0, E = SI.Operands.size(); i != E; i+=2) {
23 Operands.push_back(Use(SI.Operands[i], this));
24 Operands.push_back(Use(SI.Operands[i+1], this));
28 /// addCase - Add an entry to the switch instruction...
30 void SwitchInst::addCase(Constant *OnVal, BasicBlock *Dest) {
31 Operands.push_back(Use((Value*)OnVal, this));
32 Operands.push_back(Use((Value*)Dest, this));
35 /// removeCase - This method removes the specified successor from the switch
36 /// instruction. Note that this cannot be used to remove the default
37 /// destination (successor #0).
39 void SwitchInst::removeCase(unsigned idx) {
40 assert(idx != 0 && "Cannot remove the default case!");
41 assert(idx*2 < Operands.size() && "Successor index out of range!!!");
42 Operands.erase(Operands.begin()+idx*2, Operands.begin()+(idx+1)*2);