Allow SymbolUserOpInterface operators to be used in RemoveDeadValues Pass (#117405)
[llvm-project.git] / llvm / tools / llvm-exegesis / lib / DisassemblerHelper.h
blobb946e976fdd5396b3cde515fbf4b1038812584eb
1 //===-- DisassemblerHelper.h ------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// Helper class for decoding machine instructions and printing them in an
11 /// assembler form.
12 ///
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"
24 #include <memory>
26 namespace llvm {
27 namespace exegesis {
29 // A helper class for decoding and printing machine instructions.
30 class DisassemblerHelper {
31 public:
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());
43 private:
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
52 } // namespace llvm
54 #endif // LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H