1*39fc67b8SPavel Kosov //===-- DisassemblerHelper.h ------------------------------------*- C++ -*-===// 2*39fc67b8SPavel Kosov // 3*39fc67b8SPavel Kosov // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*39fc67b8SPavel Kosov // See https://llvm.org/LICENSE.txt for license information. 5*39fc67b8SPavel Kosov // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*39fc67b8SPavel Kosov // 7*39fc67b8SPavel Kosov //===----------------------------------------------------------------------===// 8*39fc67b8SPavel Kosov /// 9*39fc67b8SPavel Kosov /// \file 10*39fc67b8SPavel Kosov /// Helper class for decoding machine instructions and printing them in an 11*39fc67b8SPavel Kosov /// assembler form. 12*39fc67b8SPavel Kosov /// 13*39fc67b8SPavel Kosov //===----------------------------------------------------------------------===// 14*39fc67b8SPavel Kosov 15*39fc67b8SPavel Kosov #ifndef LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H 16*39fc67b8SPavel Kosov #define LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H 17*39fc67b8SPavel Kosov 18*39fc67b8SPavel Kosov #include "LlvmState.h" 19*39fc67b8SPavel Kosov #include "llvm/MC/MCAsmInfo.h" 20*39fc67b8SPavel Kosov #include "llvm/MC/MCContext.h" 21*39fc67b8SPavel Kosov #include "llvm/MC/MCDisassembler/MCDisassembler.h" 22*39fc67b8SPavel Kosov #include "llvm/MC/MCInstPrinter.h" 23*39fc67b8SPavel Kosov 24*39fc67b8SPavel Kosov #include <memory> 25*39fc67b8SPavel Kosov 26*39fc67b8SPavel Kosov namespace llvm { 27*39fc67b8SPavel Kosov namespace exegesis { 28*39fc67b8SPavel Kosov 29*39fc67b8SPavel Kosov // A helper class for decoding and printing machine instructions. 30*39fc67b8SPavel Kosov class DisassemblerHelper { 31*39fc67b8SPavel Kosov public: 32*39fc67b8SPavel Kosov DisassemblerHelper(const LLVMState &State); 33*39fc67b8SPavel Kosov printInst(const MCInst * MI,raw_ostream & OS)34*39fc67b8SPavel Kosov void printInst(const MCInst *MI, raw_ostream &OS) const { 35*39fc67b8SPavel Kosov const auto &STI = State_.getSubtargetInfo(); 36*39fc67b8SPavel Kosov InstPrinter_->printInst(MI, 0, "", STI, OS); 37*39fc67b8SPavel Kosov } 38*39fc67b8SPavel Kosov decodeInst(MCInst & MI,uint64_t & MISize,ArrayRef<uint8_t> Bytes)39*39fc67b8SPavel Kosov bool decodeInst(MCInst &MI, uint64_t &MISize, ArrayRef<uint8_t> Bytes) const { 40*39fc67b8SPavel Kosov return Disasm_->getInstruction(MI, MISize, Bytes, 0, nulls()); 41*39fc67b8SPavel Kosov } 42*39fc67b8SPavel Kosov 43*39fc67b8SPavel Kosov private: 44*39fc67b8SPavel Kosov const LLVMState &State_; 45*39fc67b8SPavel Kosov std::unique_ptr<MCContext> Context_; 46*39fc67b8SPavel Kosov std::unique_ptr<MCAsmInfo> AsmInfo_; 47*39fc67b8SPavel Kosov std::unique_ptr<MCInstPrinter> InstPrinter_; 48*39fc67b8SPavel Kosov std::unique_ptr<MCDisassembler> Disasm_; 49*39fc67b8SPavel Kosov }; 50*39fc67b8SPavel Kosov 51*39fc67b8SPavel Kosov } // namespace exegesis 52*39fc67b8SPavel Kosov } // namespace llvm 53*39fc67b8SPavel Kosov 54*39fc67b8SPavel Kosov #endif // LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H 55