summaryrefslogtreecommitdiff
path: root/lib/MC
diff options
context:
space:
mode:
authorAhmed Bougacha <ahmed.bougacha@gmail.com>2013-08-21 07:28:17 +0000
committerAhmed Bougacha <ahmed.bougacha@gmail.com>2013-08-21 07:28:17 +0000
commit46d353f8e8a2bbe02e8aa6a2292eae930dd3b7e6 (patch)
tree9cc756b7e0d63078710d8bded8550623272474ae /lib/MC
parent9bfc0626c02e449dd321a71a09f005ac8239e921 (diff)
downloadllvm-46d353f8e8a2bbe02e8aa6a2292eae930dd3b7e6.tar.gz
llvm-46d353f8e8a2bbe02e8aa6a2292eae930dd3b7e6.tar.bz2
llvm-46d353f8e8a2bbe02e8aa6a2292eae930dd3b7e6.tar.xz
MC CFG: Add a few needed methods, mainly MCModule::findFirstAtomAfter.
While there, do some minor cleanup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188880 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC')
-rw-r--r--lib/MC/MCFunction.cpp5
-rw-r--r--lib/MC/MCModule.cpp20
2 files changed, 20 insertions, 5 deletions
diff --git a/lib/MC/MCFunction.cpp b/lib/MC/MCFunction.cpp
index 5011d5fd6b..300ab5b1a0 100644
--- a/lib/MC/MCFunction.cpp
+++ b/lib/MC/MCFunction.cpp
@@ -26,8 +26,9 @@ MCFunction::~MCFunction() {
}
MCBasicBlock &MCFunction::createBlock(const MCTextAtom &TA) {
- Blocks.push_back(new MCBasicBlock(TA, this));
- return *Blocks.back();
+ MCBasicBlock *MCBB = new MCBasicBlock(TA, this);
+ Blocks.push_back(MCBB);
+ return *MCBB;
}
const MCBasicBlock *MCFunction::find(uint64_t StartAddr) const {
diff --git a/lib/MC/MCModule.cpp b/lib/MC/MCModule.cpp
index 9a9d90e5b6..bdd5cc6b1c 100644
--- a/lib/MC/MCModule.cpp
+++ b/lib/MC/MCModule.cpp
@@ -18,6 +18,10 @@ static bool AtomComp(const MCAtom *L, uint64_t Addr) {
return L->getEndAddr() < Addr;
}
+static bool AtomCompInv(uint64_t Addr, const MCAtom *R) {
+ return Addr < R->getEndAddr();
+}
+
void MCModule::map(MCAtom *NewAtom) {
uint64_t Begin = NewAtom->Begin;
@@ -77,13 +81,23 @@ const MCAtom *MCModule::findAtomContaining(uint64_t Addr) const {
}
MCAtom *MCModule::findAtomContaining(uint64_t Addr) {
- AtomListTy::iterator I = std::lower_bound(atom_begin(), atom_end(),
- Addr, AtomComp);
- if (I != atom_end() && (*I)->getBeginAddr() <= Addr)
+ return const_cast<MCAtom*>(
+ const_cast<const MCModule *>(this)->findAtomContaining(Addr));
+}
+
+const MCAtom *MCModule::findFirstAtomAfter(uint64_t Addr) const {
+ AtomListTy::const_iterator I = std::upper_bound(atom_begin(), atom_end(),
+ Addr, AtomCompInv);
+ if (I != atom_end())
return *I;
return 0;
}
+MCAtom *MCModule::findFirstAtomAfter(uint64_t Addr) {
+ return const_cast<MCAtom*>(
+ const_cast<const MCModule *>(this)->findFirstAtomAfter(Addr));
+}
+
MCFunction *MCModule::createFunction(StringRef Name) {
Functions.push_back(new MCFunction(Name, this));
return Functions.back();