6805c39756c2575e7bf640012b4e9170c8adc9bc
[oota-llvm.git] / include / llvm / MC / MCAtom.h
1 //===-- llvm/MC/MCAtom.h - MCAtom class ---------------------*- C++ -*-===//
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 // This file contains the declaration of the MCAtom class, which is used to
11 // represent a contiguous region in a decoded object that is uniformly data or
12 // instructions;
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_MC_MCATOM_H
17 #define LLVM_MC_MCATOM_H
18
19 #include "llvm/MC/MCInst.h"
20 #include "llvm/Support/DataTypes.h"
21 #include <vector>
22
23 namespace llvm {
24
25 class MCModule;
26
27 /// MCData - An entry in a data MCAtom.
28 // NOTE: This may change to a more complex type in the future.
29 typedef uint8_t MCData;
30
31 /// MCAtom - Represents a contiguous range of either instructions (a TextAtom)
32 /// or data (a DataAtom).  Address ranges are expressed as _closed_ intervals.
33 class MCAtom {
34   friend class MCModule;
35   typedef enum { TextAtom, DataAtom } AtomType;
36
37   AtomType Type;
38   MCModule *Parent;
39   uint64_t Begin, End;
40
41   std::vector<std::pair<uint64_t, MCInst> > Text;
42   std::vector<MCData> Data;
43
44   // Private constructor - only callable by MCModule
45   MCAtom(AtomType T, MCModule *P, uint64_t B, uint64_t E)
46     : Type(T), Parent(P), Begin(B), End(E) { }
47
48 public:
49   bool isTextAtom() { return Type == TextAtom; }
50   bool isDataAtom() { return Type == DataAtom; }
51
52   void addInst(const MCInst &I, uint64_t Address) {
53     assert(Type == TextAtom && "Trying to add MCInst to a non-text atom!");
54     Text.push_back(std::make_pair(Address, I));
55   }
56
57   void addData(const MCData &D) {
58     assert(Type == DataAtom && "Trying to add MCData to a non-data atom!");
59     Data.push_back(D);
60   }
61
62   /// split - Splits the atom in two at a given address, which must align with
63   /// and instruction boundary if this is a TextAtom.  Returns the newly created
64   /// atom representing the high part of the split.
65   MCAtom *split(uint64_t SplitPt);
66
67   /// truncate - Truncates an atom so that TruncPt is the last byte address
68   /// contained in the atom.
69   void truncate(uint64_t TruncPt);
70 };
71
72 }
73
74 #endif
75