1 //===- lib/MC/MCAtom.cpp - MCAtom implementation --------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCAtom.h"
11 #include "llvm/MC/MCModule.h"
12 #include "llvm/Support/ErrorHandling.h"
16 MCAtom *MCAtom::split(uint64_t SplitPt) {
17 assert((SplitPt > Begin && SplitPt <= End) &&
18 "Splitting at point not contained in atom!");
20 // Compute the new begin/end points.
21 uint64_t LeftBegin = Begin;
22 uint64_t LeftEnd = SplitPt - 1;
23 uint64_t RightBegin = SplitPt;
24 uint64_t RightEnd = End;
26 // Remap this atom to become the lower of the two new ones.
27 Parent->remap(this, LeftBegin, LeftEnd);
29 // Create a new atom for the higher atom.
30 MCAtom *RightAtom = Parent->createAtom(Type, RightBegin, RightEnd);
32 // Split the contents of the original atom between it and the new one. The
33 // precise method depends on whether this is a data or a text atom.
35 std::vector<MCData>::iterator I = Data.begin() + (RightBegin - LeftBegin);
37 assert(I != Data.end() && "Split point not found in range!");
39 std::copy(I, Data.end(), RightAtom->Data.end());
40 Data.erase(I, Data.end());
41 } else if (isTextAtom()) {
42 std::vector<std::pair<uint64_t, MCInst> >::iterator I = Text.begin();
44 while (I != Text.end() && I->first < SplitPt) ++I;
46 assert(I != Text.end() && "Split point not found in disassembly!");
47 assert(I->first == SplitPt &&
48 "Split point does not fall on instruction boundary!");
50 std::copy(I, Text.end(), RightAtom->Text.end());
51 Text.erase(I, Text.end());
53 llvm_unreachable("Unknown atom type!");
58 void MCAtom::truncate(uint64_t TruncPt) {
59 assert((TruncPt >= Begin && TruncPt < End) &&
60 "Truncation point not contained in atom!");
62 Parent->remap(this, Begin, TruncPt);
65 Data.resize(TruncPt - Begin + 1);
66 } else if (isTextAtom()) {
67 std::vector<std::pair<uint64_t, MCInst> >::iterator I = Text.begin();
69 while (I != Text.end() && I->first <= TruncPt) ++I;
71 assert(I != Text.end() && "Truncation point not found in disassembly!");
72 assert(I->first == TruncPt+1 &&
73 "Truncation point does not fall on instruction boundary");
75 Text.erase(I, Text.end());
77 llvm_unreachable("Unknown atom type!");