• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
MCAtom(AtomType T,MCModule * P,uint64_t B,uint64_t E)45   MCAtom(AtomType T, MCModule *P, uint64_t B, uint64_t E)
46     : Type(T), Parent(P), Begin(B), End(E) { }
47 
48 public:
isTextAtom()49   bool isTextAtom() { return Type == TextAtom; }
isDataAtom()50   bool isDataAtom() { return Type == DataAtom; }
51 
52   void addInst(const MCInst &I, uint64_t Address, unsigned Size);
53   void addData(const MCData &D);
54 
55   /// split - Splits the atom in two at a given address, which must align with
56   /// and instruction boundary if this is a TextAtom.  Returns the newly created
57   /// atom representing the high part of the split.
58   MCAtom *split(uint64_t SplitPt);
59 
60   /// truncate - Truncates an atom so that TruncPt is the last byte address
61   /// contained in the atom.
62   void truncate(uint64_t TruncPt);
63 };
64 
65 }
66 
67 #endif
68 
69