1 //===-- llvm/MC/MCObjectDisassembler.h --------------------------*- 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 MCObjectDisassembler class, which
11 // can be used to construct an MCModule and an MC CFG from an ObjectFile.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MC_MCOBJECTDISASSEMBLER_H
16 #define LLVM_MC_MCOBJECTDISASSEMBLER_H
27 class MCInstrAnalysis;
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;
41 MCObjectDisassembler(const object::ObjectFile &Obj,
42 const MCDisassembler &Dis,
43 const MCInstrAnalysis &MIA);
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);
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);
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);