LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MCModule.h
Go to the documentation of this file.
1 //===-- llvm/MC/MCModule.h - MCModule 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 MCModule class, which is used to
11 // represent a complete, disassembled object file or executable.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_MC_MCMODULE_H
16 #define LLVM_MC_MCMODULE_H
17 
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/DataTypes.h"
21 #include <vector>
22 
23 namespace llvm {
24 
25 class MCAtom;
26 class MCBasicBlock;
27 class MCDataAtom;
28 class MCFunction;
29 class MCObjectDisassembler;
30 class MCTextAtom;
31 
32 /// \brief A completely disassembled object file or executable.
33 /// It comprises a list of MCAtom's, each representing a contiguous range of
34 /// either instructions or data.
35 /// An MCModule is created using MCObjectDisassembler::buildModule.
36 class MCModule {
37  /// \name Atom tracking
38  /// @{
39 
40  /// \brief Atoms in this module, sorted by begin address.
41  /// FIXME: This doesn't handle overlapping atoms (which happen when a basic
42  /// block starts in the middle of an instruction of another basic block.)
43  typedef std::vector<MCAtom*> AtomListTy;
44  AtomListTy Atoms;
45 
46  // For access to map/remap.
47  friend class MCAtom;
48 
49  /// \brief Remap \p Atom to the given range, and update its Begin/End fields.
50  /// \param Atom An atom belonging to this module.
51  /// An atom should always use this method to update its bounds, because this
52  /// enables the owning MCModule to keep track of its atoms.
53  void remap(MCAtom *Atom, uint64_t NewBegin, uint64_t NewEnd);
54 
55  /// \brief Insert an atom in the module, using its Begin and End addresses.
56  void map(MCAtom *NewAtom);
57  /// @}
58 
59  /// \name Basic block tracking
60  /// @{
61  typedef std::vector<MCBasicBlock*> BBsByAtomTy;
62  BBsByAtomTy BBsByAtom;
63 
64  // For access to basic block > atom tracking.
65  friend class MCBasicBlock;
66  friend class MCTextAtom;
67 
68  /// \brief Keep track of \p BBBackedByAtom as being backed by \p Atom.
69  /// This is used to update succs/preds when \p Atom is split.
70  void trackBBForAtom(const MCTextAtom *Atom, MCBasicBlock *BBBackedByAtom);
71  void splitBasicBlocksForAtom(const MCTextAtom *TA, const MCTextAtom *NewTA);
72  /// @}
73 
74  /// \name Function tracking
75  /// @{
76  typedef std::vector<MCFunction*> FunctionListTy;
77  FunctionListTy Functions;
78  /// @}
79 
80  /// The address of the entrypoint function.
81  uint64_t Entrypoint;
82 
84  MCModule& operator=(const MCModule &) LLVM_DELETED_FUNCTION;
85 
86  // MCObjectDisassembler creates MCModules.
87  friend class MCObjectDisassembler;
88 
89 public:
90  MCModule() : Entrypoint(0) { }
91  ~MCModule();
92 
93  /// \name Create a new MCAtom covering the specified offset range.
94  /// @{
95  MCTextAtom *createTextAtom(uint64_t Begin, uint64_t End);
96  MCDataAtom *createDataAtom(uint64_t Begin, uint64_t End);
97  /// @}
98 
99  /// \name Access to the owned atom list, ordered by begin address.
100  /// @{
101  const MCAtom *findAtomContaining(uint64_t Addr) const;
102  MCAtom *findAtomContaining(uint64_t Addr);
103  const MCAtom *findFirstAtomAfter(uint64_t Addr) const;
104  MCAtom *findFirstAtomAfter(uint64_t Addr);
105 
106  typedef AtomListTy::const_iterator const_atom_iterator;
107  typedef AtomListTy:: iterator atom_iterator;
108  const_atom_iterator atom_begin() const { return Atoms.begin(); }
109  atom_iterator atom_begin() { return Atoms.begin(); }
110  const_atom_iterator atom_end() const { return Atoms.end(); }
111  atom_iterator atom_end() { return Atoms.end(); }
112  /// @}
113 
114  /// \brief Create a new MCFunction.
116 
117  /// \name Access to the owned function list.
118  /// @{
119  typedef FunctionListTy::const_iterator const_func_iterator;
120  typedef FunctionListTy:: iterator func_iterator;
121  const_func_iterator func_begin() const { return Functions.begin(); }
122  func_iterator func_begin() { return Functions.begin(); }
123  const_func_iterator func_end() const { return Functions.end(); }
124  func_iterator func_end() { return Functions.end(); }
125  /// @}
126 
127  /// \brief Get the address of the entrypoint function, or 0 if there is none.
128  uint64_t getEntrypoint() const { return Entrypoint; }
129 };
130 
131 }
132 
133 #endif
FunctionListTy::iterator func_iterator
Definition: MCModule.h:120
AtomListTy::iterator atom_iterator
Definition: MCModule.h:107
const MCAtom * findFirstAtomAfter(uint64_t Addr) const
Definition: MCModule.cpp:88
An atom consisting of disassembled instructions.
Definition: MCAtom.h:123
const MCAtom * findAtomContaining(uint64_t Addr) const
Definition: MCModule.cpp:75
An atom consising of a sequence of bytes.
Definition: MCAtom.h:170
uint64_t getEntrypoint() const
Get the address of the entrypoint function, or 0 if there is none.
Definition: MCModule.h:128
MCFunction * createFunction(StringRef Name)
Create a new MCFunction.
Definition: MCModule.cpp:101
MCDataAtom * createDataAtom(uint64_t Begin, uint64_t End)
Definition: MCModule.cpp:46
func_iterator func_end()
Definition: MCModule.h:124
Represents a function in machine code, containing MCBasicBlocks. MCFunctions are created by MCModule...
Definition: MCFunction.h:85
MCTextAtom * createTextAtom(uint64_t Begin, uint64_t End)
Definition: MCModule.cpp:40
const_atom_iterator atom_end() const
Definition: MCModule.h:110
atom_iterator atom_begin()
Definition: MCModule.h:109
Disassemble an ObjectFile to an MCModule and MCFunctions. This class builds on MCDisassembler to disa...
const_func_iterator func_begin() const
Definition: MCModule.h:121
const_func_iterator func_end() const
Definition: MCModule.h:123
AtomListTy::const_iterator const_atom_iterator
Definition: MCModule.h:106
Basic block containing a sequence of disassembled instructions. The basic block is backed by an MCTex...
Definition: MCFunction.h:33
#define LLVM_DELETED_FUNCTION
Definition: Compiler.h:137
atom_iterator atom_end()
Definition: MCModule.h:111
Represents a contiguous range of either instructions (a TextAtom) or data (a DataAtom). Address ranges are expressed as closed intervals.
Definition: MCAtom.h:34
A completely disassembled object file or executable. It comprises a list of MCAtom's, each representing a contiguous range of either instructions or data. An MCModule is created using MCObjectDisassembler::buildModule.
Definition: MCModule.h:36
FunctionListTy::const_iterator const_func_iterator
Definition: MCModule.h:119
func_iterator func_begin()
Definition: MCModule.h:122
const_atom_iterator atom_begin() const
Definition: MCModule.h:108