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 Function tracking
61 typedef std::vector<MCFunction*> FunctionListTy;
62 FunctionListTy Functions;
65 /// The address of the entrypoint function.
68 MCModule (const MCModule &) LLVM_DELETED_FUNCTION;
69 MCModule& operator=(const MCModule &) LLVM_DELETED_FUNCTION;
71 // MCObjectDisassembler creates MCModules.
72 friend class MCObjectDisassembler;
75 MCModule() : Entrypoint(0) { }
78 /// \name Create a new MCAtom covering the specified offset range.
80 MCTextAtom *createTextAtom(uint64_t Begin, uint64_t End);
81 MCDataAtom *createDataAtom(uint64_t Begin, uint64_t End);
84 /// \name Access to the owned atom list, ordered by begin address.
86 const MCAtom *findAtomContaining(uint64_t Addr) const;
87 MCAtom *findAtomContaining(uint64_t Addr);
88 const MCAtom *findFirstAtomAfter(uint64_t Addr) const;
89 MCAtom *findFirstAtomAfter(uint64_t Addr);
91 typedef AtomListTy::const_iterator const_atom_iterator;
92 typedef AtomListTy:: iterator atom_iterator;
93 const_atom_iterator atom_begin() const { return Atoms.begin(); }
94 atom_iterator atom_begin() { return Atoms.begin(); }
95 const_atom_iterator atom_end() const { return Atoms.end(); }
96 atom_iterator atom_end() { return Atoms.end(); }
99 /// \brief Create a new MCFunction.
100 MCFunction *createFunction(StringRef Name);
102 /// \name Access to the owned function list.
104 typedef FunctionListTy::const_iterator const_func_iterator;
105 typedef FunctionListTy:: iterator func_iterator;
106 const_func_iterator func_begin() const { return Functions.begin(); }
107 func_iterator func_begin() { return Functions.begin(); }
108 const_func_iterator func_end() const { return Functions.end(); }
109 func_iterator func_end() { return Functions.end(); }
112 /// \brief Get the address of the entrypoint function, or 0 if there is none.
113 uint64_t getEntrypoint() const { return Entrypoint; }