brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · b946e97 Raw
55 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// Helper class for decoding machine instructions and printing them in an11/// assembler form.12///13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H16#define LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H17 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"23 24#include <memory>25 26namespace llvm {27namespace exegesis {28 29// A helper class for decoding and printing machine instructions.30class DisassemblerHelper {31public:32  DisassemblerHelper(const LLVMState &State);33 34  void printInst(const MCInst *MI, raw_ostream &OS) const {35    const auto &STI = State_.getSubtargetInfo();36    InstPrinter_->printInst(MI, 0, "", STI, OS);37  }38 39  bool decodeInst(MCInst &MI, uint64_t &MISize, ArrayRef<uint8_t> Bytes) const {40    return Disasm_->getInstruction(MI, MISize, Bytes, 0, nulls());41  }42 43private: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_;49};50 51} // namespace exegesis52} // namespace llvm53 54#endif // LLVM_TOOLS_LLVM_EXEGESIS_DISASSEMBLER_HELPER_H55