~ubuntu-branches/ubuntu/trusty/llvm-toolchain-snapshot/trusty-201310232150

« back to all changes in this revision

Viewing changes to lib/MC/MCModule.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-27 15:01:57 UTC
  • mfrom: (0.10.1) (0.9.1) (0.8.1) (0.7.1) (0.6.1) (0.5.2)
  • Revision ID: package-import@ubuntu.com-20130527150157-tdkrsjpuvht7v0qx
Tags: 1:3.4~svn182733-1~exp1
* New snapshot release (3.4 release)
* Add a symlink of libLLVM-3.4.so.1 to usr/lib/llvm-3.4/lib/libLLVM-3.4.so
    to fix make the llvm-config-3.4 --libdir work (Closes: #708677)
  * Various packages rename to allow co installations:
    * libclang1 => libclang1-3.4
    * libclang1-dbg => libclang1-3.4-dbg
    * libclang-dev => libclang-3.4-dev
    * libclang-common-dev => libclang-common-3.4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
//
8
8
//===----------------------------------------------------------------------===//
9
9
 
 
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
#include <algorithm>
12
14
 
13
15
using namespace llvm;
14
16
 
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;
 
19
}
 
20
 
 
21
void MCModule::map(MCAtom *NewAtom) {
 
22
  uint64_t Begin = NewAtom->Begin;
 
23
 
 
24
  assert(Begin < NewAtom->End && "Creating MCAtom with endpoints reversed?");
18
25
 
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!");
22
 
 
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(),
 
28
                                            Begin, AtomComp);
 
29
  assert((I == atom_end() || (*I)->getBeginAddr() > NewAtom->End)
 
30
         && "Offset range already occupied!");
 
31
 
 
32
  // Insert the new atom to the list.
 
33
  Atoms.insert(I, NewAtom);
 
34
}
 
35
 
 
36
MCTextAtom *MCModule::createTextAtom(uint64_t Begin, uint64_t End) {
 
37
  MCTextAtom *NewAtom = new MCTextAtom(this, Begin, End);
 
38
  map(NewAtom);
 
39
  return NewAtom;
 
40
}
 
41
 
 
42
MCDataAtom *MCModule::createDataAtom(uint64_t Begin, uint64_t End) {
 
43
  MCDataAtom *NewAtom = new MCDataAtom(this, Begin, End);
 
44
  map(NewAtom);
27
45
  return NewAtom;
28
46
}
29
47
 
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!");
36
 
  I.erase();
 
55
  Atoms.erase(I);
37
56
 
38
57
  // Insert the new mapping.
39
 
  OffsetMap.insert(NewBegin, NewEnd, Atom);
 
58
  AtomListTy::iterator NewI = std::lower_bound(atom_begin(), atom_end(),
 
59
                                               NewBegin, AtomComp);
 
60
  Atoms.insert(NewI, Atom);
40
61
 
41
62
  // Update the atom internal bounds.
42
63
  Atom->Begin = NewBegin;
43
64
  Atom->End = NewEnd;
44
65
}
45
66
 
 
67
const MCAtom *MCModule::findAtomContaining(uint64_t Addr) const {
 
68
  AtomListTy::const_iterator I = std::lower_bound(atom_begin(), atom_end(),
 
69
                                                  Addr, AtomComp);
 
70
  if (I != atom_end() && (*I)->getBeginAddr() <= Addr)
 
71
    return *I;
 
72
  return 0;
 
73
}
 
74
 
 
75
MCAtom *MCModule::findAtomContaining(uint64_t Addr) {
 
76
  AtomListTy::iterator I = std::lower_bound(atom_begin(), atom_end(),
 
77
                                            Addr, AtomComp);
 
78
  if (I != atom_end() && (*I)->getBeginAddr() <= Addr)
 
79
    return *I;
 
80
  return 0;
 
81
}
 
82
 
 
83
MCFunction *MCModule::createFunction(const StringRef &Name) {
 
84
  Functions.push_back(new MCFunction(Name));
 
85
  return Functions.back();
 
86
}
 
87
 
 
88
MCModule::~MCModule() {
 
89
  for (AtomListTy::iterator AI = atom_begin(),
 
90
                            AE = atom_end();
 
91
                            AI != AE; ++AI)
 
92
    delete *AI;
 
93
  for (FunctionListTy::iterator FI = func_begin(),
 
94
                                FE = func_end();
 
95
                                FI != FE; ++FI)
 
96
    delete *FI;
 
97
}