1 //===-- llvm/MC/MCModule.h - MCModule class ---------------------*- C++ -*-===//
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 // This file contains the declaration of the MCModule class, which is used to
11 // represent a complete, disassembled object file or executable.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MC_MCMODULE_H
16 #define LLVM_MC_MCMODULE_H
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/Support/Compiler.h"
20 #include "llvm/Support/DataTypes.h"
29 class MCObjectDisassembler;
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.
37 /// \name Atom tracking
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;
46 // For access to map/remap.
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);
55 /// \brief Insert an atom in the module, using its Begin and End addresses.
56 void map(MCAtom *NewAtom);
59 /// \name Basic block tracking
61 typedef std::vector<MCBasicBlock*> BBsByAtomTy;
62 BBsByAtomTy BBsByAtom;
64 // For access to basic block > atom tracking.
65 friend class MCBasicBlock;
66 friend class MCTextAtom;
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);
74 /// \name Function tracking
76 typedef std::vector<std::unique_ptr<MCFunction>> FunctionListTy;
77 FunctionListTy Functions;
80 /// The address of the entrypoint function.
83 MCModule (const MCModule &) LLVM_DELETED_FUNCTION;
84 MCModule& operator=(const MCModule &) LLVM_DELETED_FUNCTION;
86 // MCObjectDisassembler creates MCModules.
87 friend class MCObjectDisassembler;
93 /// \name Create a new MCAtom covering the specified offset range.
95 MCTextAtom *createTextAtom(uint64_t Begin, uint64_t End);
96 MCDataAtom *createDataAtom(uint64_t Begin, uint64_t End);
99 /// \name Access to the owned atom list, ordered by begin address.
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);
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(); }
114 /// \brief Create a new MCFunction.
115 MCFunction *createFunction(StringRef Name);
117 /// \name Access to the owned function list.
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(); }
127 /// \brief Get the address of the entrypoint function, or 0 if there is none.
128 uint64_t getEntrypoint() const { return Entrypoint; }