Path: blob/main/contrib/llvm-project/llvm/lib/MC/MCDisassembler/Disassembler.h
35266 views
//===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file defines the interface for the Disassembly library's disassembler9// context. The disassembler is responsible for producing strings for10// individual instructions according to a given architecture and disassembly11// syntax.12//13//===----------------------------------------------------------------------===//1415#ifndef LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H16#define LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H1718#include "llvm-c/DisassemblerTypes.h"19#include "llvm/ADT/SmallString.h"20#include "llvm/MC/MCAsmInfo.h"21#include "llvm/MC/MCContext.h"22#include "llvm/MC/MCDisassembler/MCDisassembler.h"23#include "llvm/MC/MCInstPrinter.h"24#include "llvm/MC/MCInstrInfo.h"25#include "llvm/MC/MCRegisterInfo.h"26#include "llvm/MC/MCSubtargetInfo.h"27#include "llvm/Support/raw_ostream.h"28#include <string>29#include <utility>3031namespace llvm {32class Target;3334//35// This is the disassembler context returned by LLVMCreateDisasm().36//37class LLVMDisasmContext {38private:39//40// The passed parameters when the disassembler context is created.41//42// The TripleName for this disassembler.43std::string TripleName;44// The pointer to the caller's block of symbolic information.45void *DisInfo;46// The Triple specific symbolic information type returned by GetOpInfo.47int TagType;48// The function to get the symbolic information for operands.49LLVMOpInfoCallback GetOpInfo;50// The function to look up a symbol name.51LLVMSymbolLookupCallback SymbolLookUp;52//53// The objects created and saved by LLVMCreateDisasm() then used by54// LLVMDisasmInstruction().55//56// The LLVM target corresponding to the disassembler.57// FIXME: using std::unique_ptr<const llvm::Target> causes a malloc error58// when this LLVMDisasmContext is deleted.59const Target *TheTarget;60// The assembly information for the target architecture.61std::unique_ptr<const llvm::MCAsmInfo> MAI;62// The register information for the target architecture.63std::unique_ptr<const llvm::MCRegisterInfo> MRI;64// The subtarget information for the target architecture.65std::unique_ptr<const llvm::MCSubtargetInfo> MSI;66// The instruction information for the target architecture.67std::unique_ptr<const llvm::MCInstrInfo> MII;68// The assembly context for creating symbols and MCExprs.69std::unique_ptr<const llvm::MCContext> Ctx;70// The disassembler for the target architecture.71std::unique_ptr<const llvm::MCDisassembler> DisAsm;72// The instruction printer for the target architecture.73std::unique_ptr<llvm::MCInstPrinter> IP;74// The options used to set up the disassembler.75uint64_t Options;76// The CPU string.77std::string CPU;7879public:80// Comment stream and backing vector.81SmallString<128> CommentsToEmit;82raw_svector_ostream CommentStream;8384LLVMDisasmContext(std::string TripleName, void *DisInfo, int TagType,85LLVMOpInfoCallback GetOpInfo,86LLVMSymbolLookupCallback SymbolLookUp,87const Target *TheTarget,88std::unique_ptr<const MCAsmInfo> &&MAI,89std::unique_ptr<const MCRegisterInfo> &&MRI,90std::unique_ptr<const MCSubtargetInfo> &&MSI,91std::unique_ptr<const MCInstrInfo> &&MII,92std::unique_ptr<const llvm::MCContext> &&Ctx,93std::unique_ptr<const MCDisassembler> &&DisAsm,94std::unique_ptr<MCInstPrinter> &&IP)95: TripleName(std::move(TripleName)), DisInfo(DisInfo), TagType(TagType),96GetOpInfo(GetOpInfo), SymbolLookUp(SymbolLookUp), TheTarget(TheTarget),97MAI(std::move(MAI)), MRI(std::move(MRI)), MSI(std::move(MSI)),98MII(std::move(MII)), Ctx(std::move(Ctx)), DisAsm(std::move(DisAsm)),99IP(std::move(IP)), Options(0), CommentStream(CommentsToEmit) {}100const std::string &getTripleName() const { return TripleName; }101void *getDisInfo() const { return DisInfo; }102int getTagType() const { return TagType; }103LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }104LLVMSymbolLookupCallback getSymbolLookupCallback() const {105return SymbolLookUp;106}107const Target *getTarget() const { return TheTarget; }108const MCDisassembler *getDisAsm() const { return DisAsm.get(); }109const MCAsmInfo *getAsmInfo() const { return MAI.get(); }110const MCInstrInfo *getInstrInfo() const { return MII.get(); }111const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); }112const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); }113MCInstPrinter *getIP() { return IP.get(); }114void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); }115uint64_t getOptions() const { return Options; }116void addOptions(uint64_t Options) { this->Options |= Options; }117StringRef getCPU() const { return CPU; }118void setCPU(const char *CPU) { this->CPU = CPU; }119};120121} // namespace llvm122123#endif124125126