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