blob: 473d07bf9949de802599d4764463c8f656c68179 [file] [log] [blame]
Ahmed Bougachaef993562013-05-24 01:07:04 +00001//===-- lib/MC/MCFunction.cpp -----------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/MC/MCFunction.h"
11#include "llvm/MC/MCAtom.h"
12#include "llvm/Support/raw_ostream.h"
13#include <algorithm>
14
15using namespace llvm;
16
17// MCFunction
18
19MCFunction::MCFunction(StringRef Name)
20 : Name(Name)
21{}
22
23MCFunction::~MCFunction() {
24 for (iterator I = begin(), E = end(); I != E; ++I)
25 delete *I;
26}
27
28MCBasicBlock &MCFunction::createBlock(const MCTextAtom &TA) {
29 Blocks.push_back(new MCBasicBlock(TA, this));
30 return *Blocks.back();
31}
32
33// MCBasicBlock
34
35MCBasicBlock::MCBasicBlock(const MCTextAtom &Insts, MCFunction *Parent)
36 : Insts(&Insts), Parent(Parent)
37{}
38
39void MCBasicBlock::addSuccessor(const MCBasicBlock *MCBB) {
Ahmed Bougachadca54ea2013-08-21 07:27:50 +000040 if (!isSuccessor(MCBB))
41 Successors.push_back(MCBB);
Ahmed Bougachaef993562013-05-24 01:07:04 +000042}
43
44bool MCBasicBlock::isSuccessor(const MCBasicBlock *MCBB) const {
45 return std::find(Successors.begin(), Successors.end(),
46 MCBB) != Successors.end();
47}
48
49void MCBasicBlock::addPredecessor(const MCBasicBlock *MCBB) {
Ahmed Bougachadca54ea2013-08-21 07:27:50 +000050 if (!isPredecessor(MCBB))
51 Predecessors.push_back(MCBB);
Ahmed Bougachaef993562013-05-24 01:07:04 +000052}
53
54bool MCBasicBlock::isPredecessor(const MCBasicBlock *MCBB) const {
55 return std::find(Predecessors.begin(), Predecessors.end(),
56 MCBB) != Predecessors.end();
57}