Home | History | Annotate | Download | only in MC
      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 MCDataAtom;
     27 class MCFunction;
     28 class MCObjectDisassembler;
     29 class MCTextAtom;
     30 
     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.
     35 class MCModule {
     36   /// \name Atom tracking
     37   /// @{
     38 
     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;
     43   AtomListTy Atoms;
     44 
     45   friend class MCAtom;
     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);
     51 
     52   /// \brief Insert an atom in the module, using its Begin and End addresses.
     53   void map(MCAtom *NewAtom);
     54   /// @}
     55 
     56   /// \name Function tracking
     57   /// @{
     58   typedef std::vector<MCFunction*> FunctionListTy;
     59   FunctionListTy Functions;
     60   /// @}
     61 
     62   MCModule           (const MCModule &) LLVM_DELETED_FUNCTION;
     63   MCModule& operator=(const MCModule &) LLVM_DELETED_FUNCTION;
     64 
     65   // MCObjectDisassembler creates MCModules.
     66   friend class MCObjectDisassembler;
     67   MCModule() : Atoms() { }
     68 
     69 public:
     70   ~MCModule();
     71 
     72   /// \name Create a new MCAtom covering the specified offset range.
     73   /// @{
     74   MCTextAtom *createTextAtom(uint64_t Begin, uint64_t End);
     75   MCDataAtom *createDataAtom(uint64_t Begin, uint64_t End);
     76   /// @}
     77 
     78   /// \name Access to the owned atom list, ordered by begin address.
     79   /// @{
     80   const MCAtom *findAtomContaining(uint64_t Addr) const;
     81         MCAtom *findAtomContaining(uint64_t Addr);
     82 
     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(); }
     89   /// @}
     90 
     91   /// \name Create a new MCFunction.
     92   MCFunction *createFunction(const StringRef &Name);
     93 
     94   /// \name Access to the owned function list.
     95   /// @{
     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(); }
    102   /// @}
    103 };
    104 
    105 }
    106 
    107 #endif
    108