#pragma once // // This file is distributed under the MIT License. See LICENSE.md for details. // #include #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDisassembler/MCDisassembler.h" #include "llvm/MC/MCInstPrinter.h" #include "llvm/MC/MCInstrInfo.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCRegisterInfo.h" #include "llvm/MC/MCSubtargetInfo.h" #include "revng/Model/DisassemblyConfiguration.h" #include "revng/Support/MetaAddress.h" #include "revng/Yield/Instruction.h" class LLVMDisassemblerInterface { private: std::unique_ptr SubtargetInformation; std::unique_ptr RegisterInformation; std::unique_ptr AssemblyInformation; std::unique_ptr ObjectFileInformation; std::unique_ptr Context; std::unique_ptr InstructionInformation; std::unique_ptr Disassembler; std::unique_ptr Printer; public: explicit LLVMDisassemblerInterface(MetaAddressType::Values AddressType, const model::DisassemblyConfiguration &); struct Disassembled { MetaAddress Address; std::string Text; std::string OpcodeIdentifier; std::vector Tags; std::string Comment; std::string Error; bool HasDelaySlot = false; uint64_t Size = 0; }; Disassembled instruction(const MetaAddress &Where, llvm::ArrayRef RawBytes); public: inline llvm::StringRef getCommentString() const { return AssemblyInformation->getCommentString(); } inline llvm::StringRef getLabelSuffix() const { return AssemblyInformation->getLabelSuffix(); } private: std::pair, uint64_t> disassemble(const MetaAddress &Address, llvm::ArrayRef RawBytes, const llvm::MCDisassembler &Disassembler); Disassembled parse(const llvm::MCInst &Instruction, const MetaAddress &Address, llvm::MCInstPrinter &Printer, const llvm::MCSubtargetInfo &SI); };