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"
28 class MCObjectDisassembler;
31 /// \brief A completely disassembled object file or executable.
32 /// It comprises a list of MCAtom's, each representing a contiguous range of
33 /// either instructions or data.
34 /// An MCModule is created using MCObjectDisassembler::buildModule.
36 /// \name Atom tracking
39 /// \brief Atoms in this module, sorted by begin address.
40 /// FIXME: This doesn't handle overlapping atoms (which happen when a basic
41 /// block starts in the middle of an instruction of another basic block.)
42 typedef std::vector<MCAtom*> AtomListTy;
46 /// \brief Remap \p Atom to the given range, and update its Begin/End fields.
47 /// \param Atom An atom belonging to this module.
48 /// An atom should always use this method to update its bounds, because this
49 /// enables the owning MCModule to keep track of its atoms.
50 void remap(MCAtom *Atom, uint64_t NewBegin, uint64_t NewEnd);
52 /// \brief Insert an atom in the module, using its Begin and End addresses.
53 void map(MCAtom *NewAtom);
56 /// \name Function tracking
58 typedef std::vector<MCFunction*> FunctionListTy;
59 FunctionListTy Functions;
62 MCModule (const MCModule &) LLVM_DELETED_FUNCTION;
63 MCModule& operator=(const MCModule &) LLVM_DELETED_FUNCTION;
65 // MCObjectDisassembler creates MCModules.
66 friend class MCObjectDisassembler;
67 MCModule() : Atoms() { }
72 /// \name Create a new MCAtom covering the specified offset range.
74 MCTextAtom *createTextAtom(uint64_t Begin, uint64_t End);
75 MCDataAtom *createDataAtom(uint64_t Begin, uint64_t End);
78 /// \name Access to the owned atom list, ordered by begin address.
80 const MCAtom *findAtomContaining(uint64_t Addr) const;
81 MCAtom *findAtomContaining(uint64_t Addr);
83 typedef AtomListTy::const_iterator const_atom_iterator;
84 typedef AtomListTy:: iterator atom_iterator;
85 const_atom_iterator atom_begin() const { return Atoms.begin(); }
86 atom_iterator atom_begin() { return Atoms.begin(); }
87 const_atom_iterator atom_end() const { return Atoms.end(); }
88 atom_iterator atom_end() { return Atoms.end(); }
91 /// \name Create a new MCFunction.
92 MCFunction *createFunction(const StringRef &Name);
94 /// \name Access to the owned function list.
96 typedef FunctionListTy::const_iterator const_func_iterator;
97 typedef FunctionListTy:: iterator func_iterator;
98 const_func_iterator func_begin() const { return Functions.begin(); }
99 func_iterator func_begin() { return Functions.begin(); }
100 const_func_iterator func_end() const { return Functions.end(); }
101 func_iterator func_end() { return Functions.end(); }