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