1 //===-- DisassemblerHelper.h ------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// Helper class for decoding machine instructions and printing them in an
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H
16 #define LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H
18 #include "LlvmState.h"
19 #include "llvm/MC/MCAsmInfo.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
22 #include "llvm/MC/MCInstPrinter.h"
29 // A helper class for decoding and printing machine instructions.
30 class DisassemblerHelper
{
32 DisassemblerHelper(const LLVMState
&State
);
34 void printInst(const MCInst
*MI
, raw_ostream
&OS
) const {
35 const auto &STI
= State_
.getSubtargetInfo();
36 InstPrinter_
->printInst(MI
, 0, "", STI
, OS
);
39 bool decodeInst(MCInst
&MI
, uint64_t &MISize
, ArrayRef
<uint8_t> Bytes
) const {
40 return Disasm_
->getInstruction(MI
, MISize
, Bytes
, 0, nulls());
44 const LLVMState
&State_
;
45 std::unique_ptr
<MCContext
> Context_
;
46 std::unique_ptr
<MCAsmInfo
> AsmInfo_
;
47 std::unique_ptr
<MCInstPrinter
> InstPrinter_
;
48 std::unique_ptr
<MCDisassembler
> Disasm_
;
51 } // namespace exegesis
54 #endif // LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H