Owen Anderson | 124e182 | 2011-09-22 22:32:22 +0000 | [diff] [blame^] | 1 | //===- lib/MC/MCModule.cpp - MCModule implementation --------------------------===// |
| 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/MCAtom.h" |
| 11 | #include "llvm/MC/MCModule.h" |
| 12 | |
| 13 | using namespace llvm; |
| 14 | |
| 15 | MCAtom *MCModule::createAtom(MCAtom::AtomType Type, |
| 16 | uint64_t Begin, uint64_t End) { |
| 17 | assert(Begin < End && "Creating MCAtom with endpoints reversed?"); |
| 18 | |
| 19 | // 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 | return NewAtom; |
| 28 | } |
| 29 | |
| 30 | // remap - Update the interval mapping for an atom. |
| 31 | void MCModule::remap(MCAtom *Atom, uint64_t NewBegin, uint64_t NewEnd) { |
| 32 | // 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!"); |
| 35 | assert(*I == Atom && "Previous atom mapping was invalid!"); |
| 36 | I.erase(); |
| 37 | |
| 38 | // Insert the new mapping. |
| 39 | OffsetMap.insert(NewBegin, NewEnd, Atom); |
| 40 | |
| 41 | // Update the atom internal bounds. |
| 42 | Atom->Begin = NewBegin; |
| 43 | Atom->End = NewEnd; |
| 44 | } |
| 45 | |