Files
revng-revng/include/revng/Yield/Assembly/LLVMDisassemblerInterface.h
Ivan Krysak e5328290c6 Yield: reorder disassembly processing
This commit moves stuff around to enforce complete information being
present by the time the "Internal" assembly output is ready.

Because of that, the "Internal" format needed to change, now it uses
tag representation close to PTML as opposed to the one close to LLVM's
used before now.
2024-03-18 10:58:52 +00:00

72 lines
2.2 KiB
C++

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