Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===-- llvm/MC/MCExternalSymbolizer.h - ------------------------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains the declaration of the MCExternalSymbolizer class, which |
| 10 | // enables library users to provide callbacks (through the C API) to do the |
| 11 | // symbolization externally. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_MC_MCDISASSEMBLER_MCEXTERNALSYMBOLIZER_H |
| 16 | #define LLVM_MC_MCDISASSEMBLER_MCEXTERNALSYMBOLIZER_H |
| 17 | |
| 18 | #include "llvm-c/Disassembler.h" |
| 19 | #include "llvm/MC/MCDisassembler/MCSymbolizer.h" |
| 20 | #include <memory> |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 24 | /// Symbolize using user-provided, C API, callbacks. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 25 | /// |
| 26 | /// See llvm-c/Disassembler.h. |
| 27 | class MCExternalSymbolizer : public MCSymbolizer { |
| 28 | protected: |
| 29 | /// \name Hooks for symbolic disassembly via the public 'C' interface. |
| 30 | /// @{ |
| 31 | /// The function to get the symbolic information for operands. |
| 32 | LLVMOpInfoCallback GetOpInfo; |
| 33 | /// The function to lookup a symbol name. |
| 34 | LLVMSymbolLookupCallback SymbolLookUp; |
| 35 | /// The pointer to the block of symbolic information for above call back. |
| 36 | void *DisInfo; |
| 37 | /// @} |
| 38 | |
| 39 | public: |
| 40 | MCExternalSymbolizer(MCContext &Ctx, |
| 41 | std::unique_ptr<MCRelocationInfo> RelInfo, |
| 42 | LLVMOpInfoCallback getOpInfo, |
| 43 | LLVMSymbolLookupCallback symbolLookUp, void *disInfo) |
| 44 | : MCSymbolizer(Ctx, std::move(RelInfo)), GetOpInfo(getOpInfo), |
| 45 | SymbolLookUp(symbolLookUp), DisInfo(disInfo) {} |
| 46 | |
| 47 | bool tryAddingSymbolicOperand(MCInst &MI, raw_ostream &CommentStream, |
| 48 | int64_t Value, uint64_t Address, bool IsBranch, |
| 49 | uint64_t Offset, uint64_t InstSize) override; |
| 50 | void tryAddingPcLoadReferenceComment(raw_ostream &CommentStream, |
| 51 | int64_t Value, |
| 52 | uint64_t Address) override; |
| 53 | }; |
| 54 | |
| 55 | } |
| 56 | |
| 57 | #endif |