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/ADT/OwningPtr.h"
20 #include "llvm/MC/MCRelocationInfo.h"
21 #include "llvm/Support/Compiler.h"
22 #include "llvm/Support/DataTypes.h"
30 /// \brief Symbolize and annotate disassembled instructions.
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.
40 MCSymbolizer(const MCSymbolizer &) LLVM_DELETED_FUNCTION;
41 void operator=(const MCSymbolizer &) LLVM_DELETED_FUNCTION;
45 OwningPtr<MCRelocationInfo> RelInfo;
48 /// \brief Construct an MCSymbolizer, taking ownership of \p RelInfo.
49 MCSymbolizer(MCContext &Ctx, OwningPtr<MCRelocationInfo> &RelInfo);
50 virtual ~MCSymbolizer();
52 /// \brief Try to add a symbolic operand instead of \p Value to the MCInst.
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;
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,
76 uint64_t Address) = 0;