1*9880d681SAndroid Build Coastguard Worker //===-- llvm/MC/MCSymbolizer.h - MCSymbolizer class -------------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file contains the declaration of the MCSymbolizer class, which is used 11*9880d681SAndroid Build Coastguard Worker // to symbolize instructions decoded from an object, that is, transform their 12*9880d681SAndroid Build Coastguard Worker // immediate operands to MCExprs. 13*9880d681SAndroid Build Coastguard Worker // 14*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 15*9880d681SAndroid Build Coastguard Worker 16*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_MC_MCDISASSEMBLER_MCSYMBOLIZER_H 17*9880d681SAndroid Build Coastguard Worker #define LLVM_MC_MCDISASSEMBLER_MCSYMBOLIZER_H 18*9880d681SAndroid Build Coastguard Worker 19*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCDisassembler/MCRelocationInfo.h" 20*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Compiler.h" 21*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/DataTypes.h" 22*9880d681SAndroid Build Coastguard Worker #include <cassert> 23*9880d681SAndroid Build Coastguard Worker #include <memory> 24*9880d681SAndroid Build Coastguard Worker 25*9880d681SAndroid Build Coastguard Worker namespace llvm { 26*9880d681SAndroid Build Coastguard Worker 27*9880d681SAndroid Build Coastguard Worker class MCContext; 28*9880d681SAndroid Build Coastguard Worker class MCInst; 29*9880d681SAndroid Build Coastguard Worker class raw_ostream; 30*9880d681SAndroid Build Coastguard Worker 31*9880d681SAndroid Build Coastguard Worker /// \brief Symbolize and annotate disassembled instructions. 32*9880d681SAndroid Build Coastguard Worker /// 33*9880d681SAndroid Build Coastguard Worker /// For now this mimics the old symbolization logic (from both ARM and x86), that 34*9880d681SAndroid Build Coastguard Worker /// relied on user-provided (C API) callbacks to do the actual symbol lookup in 35*9880d681SAndroid Build Coastguard Worker /// the object file. This was moved to MCExternalSymbolizer. 36*9880d681SAndroid Build Coastguard Worker /// A better API would not rely on actually calling the two methods here from 37*9880d681SAndroid Build Coastguard Worker /// inside each disassembler, but would use the instr info to determine what 38*9880d681SAndroid Build Coastguard Worker /// operands are actually symbolizable, and in what way. I don't think this 39*9880d681SAndroid Build Coastguard Worker /// information exists right now. 40*9880d681SAndroid Build Coastguard Worker class MCSymbolizer { 41*9880d681SAndroid Build Coastguard Worker MCSymbolizer(const MCSymbolizer &) = delete; 42*9880d681SAndroid Build Coastguard Worker void operator=(const MCSymbolizer &) = delete; 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard Worker protected: 45*9880d681SAndroid Build Coastguard Worker MCContext &Ctx; 46*9880d681SAndroid Build Coastguard Worker std::unique_ptr<MCRelocationInfo> RelInfo; 47*9880d681SAndroid Build Coastguard Worker 48*9880d681SAndroid Build Coastguard Worker public: 49*9880d681SAndroid Build Coastguard Worker /// \brief Construct an MCSymbolizer, taking ownership of \p RelInfo. MCSymbolizer(MCContext & Ctx,std::unique_ptr<MCRelocationInfo> RelInfo)50*9880d681SAndroid Build Coastguard Worker MCSymbolizer(MCContext &Ctx, std::unique_ptr<MCRelocationInfo> RelInfo) 51*9880d681SAndroid Build Coastguard Worker : Ctx(Ctx), RelInfo(std::move(RelInfo)) { 52*9880d681SAndroid Build Coastguard Worker } 53*9880d681SAndroid Build Coastguard Worker 54*9880d681SAndroid Build Coastguard Worker virtual ~MCSymbolizer(); 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker /// \brief Try to add a symbolic operand instead of \p Value to the MCInst. 57*9880d681SAndroid Build Coastguard Worker /// 58*9880d681SAndroid Build Coastguard Worker /// Instead of having a difficult to read immediate, a symbolic operand would 59*9880d681SAndroid Build Coastguard Worker /// represent this immediate in a more understandable way, for instance as a 60*9880d681SAndroid Build Coastguard Worker /// symbol or an offset from a symbol. Relocations can also be used to enrich 61*9880d681SAndroid Build Coastguard Worker /// the symbolic expression. 62*9880d681SAndroid Build Coastguard Worker /// \param Inst - The MCInst where to insert the symbolic operand. 63*9880d681SAndroid Build Coastguard Worker /// \param cStream - Stream to print comments and annotations on. 64*9880d681SAndroid Build Coastguard Worker /// \param Value - Operand value, pc-adjusted by the caller if necessary. 65*9880d681SAndroid Build Coastguard Worker /// \param Address - Load address of the instruction. 66*9880d681SAndroid Build Coastguard Worker /// \param IsBranch - Is the instruction a branch? 67*9880d681SAndroid Build Coastguard Worker /// \param Offset - Byte offset of the operand inside the inst. 68*9880d681SAndroid Build Coastguard Worker /// \param InstSize - Size of the instruction in bytes. 69*9880d681SAndroid Build Coastguard Worker /// \return Whether a symbolic operand was added. 70*9880d681SAndroid Build Coastguard Worker virtual bool tryAddingSymbolicOperand(MCInst &Inst, raw_ostream &cStream, 71*9880d681SAndroid Build Coastguard Worker int64_t Value, uint64_t Address, 72*9880d681SAndroid Build Coastguard Worker bool IsBranch, uint64_t Offset, 73*9880d681SAndroid Build Coastguard Worker uint64_t InstSize) = 0; 74*9880d681SAndroid Build Coastguard Worker 75*9880d681SAndroid Build Coastguard Worker /// \brief Try to add a comment on the PC-relative load. 76*9880d681SAndroid Build Coastguard Worker /// For instance, in Mach-O, this is used to add annotations to instructions 77*9880d681SAndroid Build Coastguard Worker /// that use C string literals, as found in __cstring. 78*9880d681SAndroid Build Coastguard Worker virtual void tryAddingPcLoadReferenceComment(raw_ostream &cStream, 79*9880d681SAndroid Build Coastguard Worker int64_t Value, 80*9880d681SAndroid Build Coastguard Worker uint64_t Address) = 0; 81*9880d681SAndroid Build Coastguard Worker }; 82*9880d681SAndroid Build Coastguard Worker 83*9880d681SAndroid Build Coastguard Worker } 84*9880d681SAndroid Build Coastguard Worker 85*9880d681SAndroid Build Coastguard Worker #endif 86