1 //===-- iSwitch.cpp - Implement the Switch instruction --------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the Switch instruction...
12 //===----------------------------------------------------------------------===//
14 #include "llvm/iTerminators.h"
15 #include "llvm/BasicBlock.h"
19 SwitchInst::SwitchInst(Value *V, BasicBlock *DefaultDest,
20 Instruction *InsertBefore)
21 : TerminatorInst(Instruction::Switch, InsertBefore) {
22 assert(V && DefaultDest);
23 Operands.push_back(Use(V, this));
24 Operands.push_back(Use(DefaultDest, this));
27 SwitchInst::SwitchInst(const SwitchInst &SI)
28 : TerminatorInst(Instruction::Switch) {
29 Operands.reserve(SI.Operands.size());
31 for (unsigned i = 0, E = SI.Operands.size(); i != E; i+=2) {
32 Operands.push_back(Use(SI.Operands[i], this));
33 Operands.push_back(Use(SI.Operands[i+1], this));
37 /// addCase - Add an entry to the switch instruction...
39 void SwitchInst::addCase(Constant *OnVal, BasicBlock *Dest) {
40 Operands.push_back(Use((Value*)OnVal, this));
41 Operands.push_back(Use((Value*)Dest, this));
44 /// removeCase - This method removes the specified successor from the switch
45 /// instruction. Note that this cannot be used to remove the default
46 /// destination (successor #0).
48 void SwitchInst::removeCase(unsigned idx) {
49 assert(idx != 0 && "Cannot remove the default case!");
50 assert(idx*2 < Operands.size() && "Successor index out of range!!!");
51 Operands.erase(Operands.begin()+idx*2, Operands.begin()+(idx+1)*2);
54 } // End llvm namespace