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"
30 class MCObjectDisassembler;
33 /// \brief A completely disassembled object file or executable.
34 /// It comprises a list of MCAtom's, each representing a contiguous range of
35 /// either instructions or data.
36 /// An MCModule is created using MCObjectDisassembler::buildModule.
38 /// \name Atom tracking
41 /// \brief Atoms in this module, sorted by begin address.
42 /// FIXME: This doesn't handle overlapping atoms (which happen when a basic
43 /// block starts in the middle of an instruction of another basic block.)
44 typedef std::vector<MCAtom*> AtomListTy;
47 // For access to map/remap.
50 /// \brief Remap \p Atom to the given range, and update its Begin/End fields.
51 /// \param Atom An atom belonging to this module.
52 /// An atom should always use this method to update its bounds, because this
53 /// enables the owning MCModule to keep track of its atoms.
54 void remap(MCAtom *Atom, uint64_t NewBegin, uint64_t NewEnd);
56 /// \brief Insert an atom in the module, using its Begin and End addresses.
57 void map(MCAtom *NewAtom);
60 /// \name Basic block tracking
62 typedef std::vector<MCBasicBlock*> BBsByAtomTy;
63 BBsByAtomTy BBsByAtom;
65 // For access to basic block > atom tracking.
66 friend class MCBasicBlock;
67 friend class MCTextAtom;
69 /// \brief Keep track of \p BBBackedByAtom as being backed by \p Atom.
70 /// This is used to update succs/preds when \p Atom is split.
71 void trackBBForAtom(const MCTextAtom *Atom, MCBasicBlock *BBBackedByAtom);
72 void splitBasicBlocksForAtom(const MCTextAtom *TA, const MCTextAtom *NewTA);
75 /// \name Function tracking
77 typedef std::vector<std::unique_ptr<MCFunction>> FunctionListTy;
78 FunctionListTy Functions;
81 /// The address of the entrypoint function.
84 MCModule (const MCModule &) LLVM_DELETED_FUNCTION;
85 MCModule& operator=(const MCModule &) LLVM_DELETED_FUNCTION;
87 // MCObjectDisassembler creates MCModules.
88 friend class MCObjectDisassembler;
94 /// \name Create a new MCAtom covering the specified offset range.
96 MCTextAtom *createTextAtom(uint64_t Begin, uint64_t End);
97 MCDataAtom *createDataAtom(uint64_t Begin, uint64_t End);
100 /// \name Access to the owned atom list, ordered by begin address.
102 const MCAtom *findAtomContaining(uint64_t Addr) const;
103 MCAtom *findAtomContaining(uint64_t Addr);
104 const MCAtom *findFirstAtomAfter(uint64_t Addr) const;
105 MCAtom *findFirstAtomAfter(uint64_t Addr);
107 typedef AtomListTy::const_iterator const_atom_iterator;
108 typedef AtomListTy:: iterator atom_iterator;
109 const_atom_iterator atom_begin() const { return Atoms.begin(); }
110 atom_iterator atom_begin() { return Atoms.begin(); }
111 const_atom_iterator atom_end() const { return Atoms.end(); }
112 atom_iterator atom_end() { return Atoms.end(); }
115 /// \brief Create a new MCFunction.
116 MCFunction *createFunction(StringRef Name);
118 /// \name Access to the owned function list.
120 typedef FunctionListTy::const_iterator const_func_iterator;
121 typedef FunctionListTy:: iterator func_iterator;
122 const_func_iterator func_begin() const { return Functions.begin(); }
123 func_iterator func_begin() { return Functions.begin(); }
124 const_func_iterator func_end() const { return Functions.end(); }
125 func_iterator func_end() { return Functions.end(); }
128 /// \brief Get the address of the entrypoint function, or 0 if there is none.
129 uint64_t getEntrypoint() const { return Entrypoint; }