diff options
author | Chris Lattner <sabre@nondot.org> | 2001-06-06 20:29:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-06-06 20:29:01 +0000 |
commit | 009505452b713ed2e3a8e99c5545a6e721c65495 (patch) | |
tree | 136a71c5b87bdf534d1f20a67558b49226b5a4d6 /lib/VMCore/iBranch.cpp | |
parent | 8d0afd3d32d1d67f9aa5df250a1d6955aa8f1ac9 (diff) |
Initial revision
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/iBranch.cpp')
-rw-r--r-- | lib/VMCore/iBranch.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/VMCore/iBranch.cpp b/lib/VMCore/iBranch.cpp new file mode 100644 index 0000000000..05f35059a5 --- /dev/null +++ b/lib/VMCore/iBranch.cpp @@ -0,0 +1,69 @@ +//===-- iBranch.cpp - Implement the Branch instruction -----------*- C++ -*--=// +// +// This file implements the 'br' instruction, which can represent either a +// conditional or unconditional branch. +// +//===----------------------------------------------------------------------===// + +#include "llvm/iTerminators.h" +#include "llvm/BasicBlock.h" +#ifndef NDEBUG +#include "llvm/Type.h" // Only used for assertions... +#include "llvm/Assembly/Writer.h" +#endif + +BranchInst::BranchInst(BasicBlock *True, BasicBlock *False, Value *Cond) + : TerminatorInst(Instruction::Br), TrueDest(True, this), + FalseDest(False, this), Condition(Cond, this) { + assert(True != 0 && "True branch destination may not be null!!!"); + +#ifndef NDEBUG + if (Cond != 0 && Cond->getType() != Type::BoolTy) + cerr << "Bad Condition: " << Cond << endl; +#endif + assert((Cond == 0 || Cond->getType() == Type::BoolTy) && + "May only branch on boolean predicates!!!!"); +} + +BranchInst::BranchInst(const BranchInst &BI) + : TerminatorInst(Instruction::Br), TrueDest(BI.TrueDest, this), + FalseDest(BI.FalseDest, this), Condition(BI.Condition, this) { +} + + +void BranchInst::dropAllReferences() { + Condition = 0; + TrueDest = FalseDest = 0; +} + +const Value *BranchInst::getOperand(unsigned i) const { + return (i == 0) ? (Value*)TrueDest : + ((i == 1) ? (Value*)FalseDest : + ((i == 2) ? (Value*)Condition : 0)); +} + +const BasicBlock *BranchInst::getSuccessor(unsigned i) const { + return (i == 0) ? (const BasicBlock*)TrueDest : + ((i == 1) ? (const BasicBlock*)FalseDest : 0); +} + +bool BranchInst::setOperand(unsigned i, Value *Val) { + switch (i) { + case 0: + assert(Val && "Can't change primary direction to 0!"); + assert(Val->getType() == Type::LabelTy); + TrueDest = (BasicBlock*)Val; + return true; + case 1: + assert(Val == 0 || Val->getType() == Type::LabelTy); + FalseDest = (BasicBlock*)Val; + return true; + case 2: + Condition = Val; + assert(!Condition || Condition->getType() == Type::BoolTy && + "Condition expr must be a boolean expression!"); + return true; + } + + return false; +} |