Home | History | Annotate | Download | only in MC
      1 //===-- llvm/MC/MCObjectDisassembler.h --------------------------*- 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 MCObjectDisassembler class, which
     11 // can be used to construct an MCModule and an MC CFG from an ObjectFile.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 
     15 #ifndef LLVM_MC_MCOBJECTDISASSEMBLER_H
     16 #define LLVM_MC_MCOBJECTDISASSEMBLER_H
     17 
     18 namespace llvm {
     19 
     20 namespace object {
     21   class ObjectFile;
     22 }
     23 
     24 class MCBasicBlock;
     25 class MCDisassembler;
     26 class MCFunction;
     27 class MCInstrAnalysis;
     28 class MCModule;
     29 
     30 /// \brief Disassemble an ObjectFile to an MCModule and MCFunctions.
     31 /// This class builds on MCDisassembler to disassemble whole sections, creating
     32 /// MCAtom (MCTextAtom for disassembled sections and MCDataAtom for raw data).
     33 /// It can also be used to create a control flow graph consisting of MCFunctions
     34 /// and MCBasicBlocks.
     35 class MCObjectDisassembler {
     36   const object::ObjectFile &Obj;
     37   const MCDisassembler &Dis;
     38   const MCInstrAnalysis &MIA;
     39 
     40 public:
     41   MCObjectDisassembler(const object::ObjectFile &Obj,
     42                        const MCDisassembler &Dis,
     43                        const MCInstrAnalysis &MIA);
     44 
     45   /// \brief Build an MCModule, creating atoms and optionally functions.
     46   /// \param withCFG Also build a CFG by adding MCFunctions to the Module.
     47   /// If withCFG is false, the MCModule built only contains atoms, representing
     48   /// what was found in the object file. If withCFG is true, MCFunctions are
     49   /// created, containing MCBasicBlocks. All text atoms are split to form basic
     50   /// block atoms, which then each back an MCBasicBlock.
     51   MCModule *buildModule(bool withCFG = false);
     52 
     53 private:
     54   /// \brief Fill \p Module by creating an atom for each section.
     55   /// This could be made much smarter, using information like symbols, but also
     56   /// format-specific features, like mach-o function_start or data_in_code LCs.
     57   void buildSectionAtoms(MCModule *Module);
     58 
     59   /// \brief Enrich \p Module with a CFG consisting of MCFunctions.
     60   /// \param Module An MCModule returned by buildModule, with no CFG.
     61   /// NOTE: Each MCBasicBlock in a MCFunction is backed by a single MCTextAtom.
     62   /// When the CFG is built, contiguous instructions that were previously in a
     63   /// single MCTextAtom will be split in multiple basic block atoms.
     64   void buildCFG(MCModule *Module);
     65 };
     66 
     67 }
     68 
     69 #endif
     70