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
This commit is contained in:
Ahmed Bougacha
2013-08-21 07:28:17 +00:00
parent 9bfc0626c0
commit 46d353f8e8
4 changed files with 30 additions and 5 deletions

View File

@ -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();