8
8
//===----------------------------------------------------------------------===//
10
#include "llvm/MC/MCModule.h"
10
11
#include "llvm/MC/MCAtom.h"
11
#include "llvm/MC/MCModule.h"
12
#include "llvm/MC/MCFunction.h"
13
15
using namespace llvm;
15
MCAtom *MCModule::createAtom(MCAtom::AtomType Type,
16
uint64_t Begin, uint64_t End) {
17
assert(Begin < End && "Creating MCAtom with endpoints reversed?");
17
static bool AtomComp(const MCAtom *L, uint64_t Addr) {
18
return L->getEndAddr() < Addr;
21
void MCModule::map(MCAtom *NewAtom) {
22
uint64_t Begin = NewAtom->Begin;
24
assert(Begin < NewAtom->End && "Creating MCAtom with endpoints reversed?");
19
26
// Check for atoms already covering this range.
20
IntervalMap<uint64_t, MCAtom*>::iterator I = OffsetMap.find(Begin);
21
assert((!I.valid() || I.start() < End) && "Offset range already occupied!");
23
// Create the new atom and add it to our maps.
24
MCAtom *NewAtom = new MCAtom(Type, this, Begin, End);
25
AtomAllocationTracker.insert(NewAtom);
26
OffsetMap.insert(Begin, End, NewAtom);
27
AtomListTy::iterator I = std::lower_bound(atom_begin(), atom_end(),
29
assert((I == atom_end() || (*I)->getBeginAddr() > NewAtom->End)
30
&& "Offset range already occupied!");
32
// Insert the new atom to the list.
33
Atoms.insert(I, NewAtom);
36
MCTextAtom *MCModule::createTextAtom(uint64_t Begin, uint64_t End) {
37
MCTextAtom *NewAtom = new MCTextAtom(this, Begin, End);
42
MCDataAtom *MCModule::createDataAtom(uint64_t Begin, uint64_t End) {
43
MCDataAtom *NewAtom = new MCDataAtom(this, Begin, End);
30
48
// remap - Update the interval mapping for an atom.
31
49
void MCModule::remap(MCAtom *Atom, uint64_t NewBegin, uint64_t NewEnd) {
32
50
// Find and erase the old mapping.
33
IntervalMap<uint64_t, MCAtom*>::iterator I = OffsetMap.find(Atom->Begin);
34
assert(I.valid() && "Atom offset not found in module!");
51
AtomListTy::iterator I = std::lower_bound(atom_begin(), atom_end(),
52
Atom->Begin, AtomComp);
53
assert(I != atom_end() && "Atom offset not found in module!");
35
54
assert(*I == Atom && "Previous atom mapping was invalid!");
38
57
// Insert the new mapping.
39
OffsetMap.insert(NewBegin, NewEnd, Atom);
58
AtomListTy::iterator NewI = std::lower_bound(atom_begin(), atom_end(),
60
Atoms.insert(NewI, Atom);
41
62
// Update the atom internal bounds.
42
63
Atom->Begin = NewBegin;
43
64
Atom->End = NewEnd;
67
const MCAtom *MCModule::findAtomContaining(uint64_t Addr) const {
68
AtomListTy::const_iterator I = std::lower_bound(atom_begin(), atom_end(),
70
if (I != atom_end() && (*I)->getBeginAddr() <= Addr)
75
MCAtom *MCModule::findAtomContaining(uint64_t Addr) {
76
AtomListTy::iterator I = std::lower_bound(atom_begin(), atom_end(),
78
if (I != atom_end() && (*I)->getBeginAddr() <= Addr)
83
MCFunction *MCModule::createFunction(const StringRef &Name) {
84
Functions.push_back(new MCFunction(Name));
85
return Functions.back();
88
MCModule::~MCModule() {
89
for (AtomListTy::iterator AI = atom_begin(),
93
for (FunctionListTy::iterator FI = func_begin(),