10b57cec5SDimitry Andric //===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file defines the interface for the Disassembly library's disassembler 100b57cec5SDimitry Andric // context. The disassembler is responsible for producing strings for 110b57cec5SDimitry Andric // individual instructions according to a given architecture and disassembly 120b57cec5SDimitry Andric // syntax. 130b57cec5SDimitry Andric // 140b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric #ifndef LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H 170b57cec5SDimitry Andric #define LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H 180b57cec5SDimitry Andric 19*81ad6265SDimitry Andric #include "llvm-c/DisassemblerTypes.h" 200b57cec5SDimitry Andric #include "llvm/ADT/SmallString.h" 210b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h" 220b57cec5SDimitry Andric #include "llvm/MC/MCContext.h" 230b57cec5SDimitry Andric #include "llvm/MC/MCDisassembler/MCDisassembler.h" 240b57cec5SDimitry Andric #include "llvm/MC/MCInstPrinter.h" 250b57cec5SDimitry Andric #include "llvm/MC/MCInstrInfo.h" 260b57cec5SDimitry Andric #include "llvm/MC/MCRegisterInfo.h" 270b57cec5SDimitry Andric #include "llvm/MC/MCSubtargetInfo.h" 280b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h" 290b57cec5SDimitry Andric #include <string> 300b57cec5SDimitry Andric #include <utility> 310b57cec5SDimitry Andric 320b57cec5SDimitry Andric namespace llvm { 330b57cec5SDimitry Andric class Target; 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric // 360b57cec5SDimitry Andric // This is the disassembler context returned by LLVMCreateDisasm(). 370b57cec5SDimitry Andric // 380b57cec5SDimitry Andric class LLVMDisasmContext { 390b57cec5SDimitry Andric private: 400b57cec5SDimitry Andric // 410b57cec5SDimitry Andric // The passed parameters when the disassembler context is created. 420b57cec5SDimitry Andric // 430b57cec5SDimitry Andric // The TripleName for this disassembler. 440b57cec5SDimitry Andric std::string TripleName; 450b57cec5SDimitry Andric // The pointer to the caller's block of symbolic information. 460b57cec5SDimitry Andric void *DisInfo; 470b57cec5SDimitry Andric // The Triple specific symbolic information type returned by GetOpInfo. 480b57cec5SDimitry Andric int TagType; 490b57cec5SDimitry Andric // The function to get the symbolic information for operands. 500b57cec5SDimitry Andric LLVMOpInfoCallback GetOpInfo; 510b57cec5SDimitry Andric // The function to look up a symbol name. 520b57cec5SDimitry Andric LLVMSymbolLookupCallback SymbolLookUp; 530b57cec5SDimitry Andric // 540b57cec5SDimitry Andric // The objects created and saved by LLVMCreateDisasm() then used by 550b57cec5SDimitry Andric // LLVMDisasmInstruction(). 560b57cec5SDimitry Andric // 570b57cec5SDimitry Andric // The LLVM target corresponding to the disassembler. 580b57cec5SDimitry Andric // FIXME: using std::unique_ptr<const llvm::Target> causes a malloc error 590b57cec5SDimitry Andric // when this LLVMDisasmContext is deleted. 600b57cec5SDimitry Andric const Target *TheTarget; 610b57cec5SDimitry Andric // The assembly information for the target architecture. 620b57cec5SDimitry Andric std::unique_ptr<const llvm::MCAsmInfo> MAI; 630b57cec5SDimitry Andric // The register information for the target architecture. 640b57cec5SDimitry Andric std::unique_ptr<const llvm::MCRegisterInfo> MRI; 650b57cec5SDimitry Andric // The subtarget information for the target architecture. 660b57cec5SDimitry Andric std::unique_ptr<const llvm::MCSubtargetInfo> MSI; 670b57cec5SDimitry Andric // The instruction information for the target architecture. 680b57cec5SDimitry Andric std::unique_ptr<const llvm::MCInstrInfo> MII; 690b57cec5SDimitry Andric // The assembly context for creating symbols and MCExprs. 700b57cec5SDimitry Andric std::unique_ptr<const llvm::MCContext> Ctx; 710b57cec5SDimitry Andric // The disassembler for the target architecture. 720b57cec5SDimitry Andric std::unique_ptr<const llvm::MCDisassembler> DisAsm; 730b57cec5SDimitry Andric // The instruction printer for the target architecture. 740b57cec5SDimitry Andric std::unique_ptr<llvm::MCInstPrinter> IP; 750b57cec5SDimitry Andric // The options used to set up the disassembler. 760b57cec5SDimitry Andric uint64_t Options; 770b57cec5SDimitry Andric // The CPU string. 780b57cec5SDimitry Andric std::string CPU; 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric public: 810b57cec5SDimitry Andric // Comment stream and backing vector. 820b57cec5SDimitry Andric SmallString<128> CommentsToEmit; 830b57cec5SDimitry Andric raw_svector_ostream CommentStream; 840b57cec5SDimitry Andric LLVMDisasmContext(std::string TripleName,void * DisInfo,int TagType,LLVMOpInfoCallback GetOpInfo,LLVMSymbolLookupCallback SymbolLookUp,const Target * TheTarget,std::unique_ptr<const MCAsmInfo> && MAI,std::unique_ptr<const MCRegisterInfo> && MRI,std::unique_ptr<const MCSubtargetInfo> && MSI,std::unique_ptr<const MCInstrInfo> && MII,std::unique_ptr<const llvm::MCContext> && Ctx,std::unique_ptr<const MCDisassembler> && DisAsm,std::unique_ptr<MCInstPrinter> && IP)850b57cec5SDimitry Andric LLVMDisasmContext(std::string TripleName, void *DisInfo, int TagType, 860b57cec5SDimitry Andric LLVMOpInfoCallback GetOpInfo, 870b57cec5SDimitry Andric LLVMSymbolLookupCallback SymbolLookUp, 880b57cec5SDimitry Andric const Target *TheTarget, 890b57cec5SDimitry Andric std::unique_ptr<const MCAsmInfo> &&MAI, 900b57cec5SDimitry Andric std::unique_ptr<const MCRegisterInfo> &&MRI, 910b57cec5SDimitry Andric std::unique_ptr<const MCSubtargetInfo> &&MSI, 920b57cec5SDimitry Andric std::unique_ptr<const MCInstrInfo> &&MII, 930b57cec5SDimitry Andric std::unique_ptr<const llvm::MCContext> &&Ctx, 940b57cec5SDimitry Andric std::unique_ptr<const MCDisassembler> &&DisAsm, 950b57cec5SDimitry Andric std::unique_ptr<MCInstPrinter> &&IP) 960b57cec5SDimitry Andric : TripleName(std::move(TripleName)), DisInfo(DisInfo), TagType(TagType), 970b57cec5SDimitry Andric GetOpInfo(GetOpInfo), SymbolLookUp(SymbolLookUp), TheTarget(TheTarget), 980b57cec5SDimitry Andric MAI(std::move(MAI)), MRI(std::move(MRI)), MSI(std::move(MSI)), 990b57cec5SDimitry Andric MII(std::move(MII)), Ctx(std::move(Ctx)), DisAsm(std::move(DisAsm)), 1000b57cec5SDimitry Andric IP(std::move(IP)), Options(0), CommentStream(CommentsToEmit) {} getTripleName()1010b57cec5SDimitry Andric const std::string &getTripleName() const { return TripleName; } getDisInfo()1020b57cec5SDimitry Andric void *getDisInfo() const { return DisInfo; } getTagType()1030b57cec5SDimitry Andric int getTagType() const { return TagType; } getGetOpInfo()1040b57cec5SDimitry Andric LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; } getSymbolLookupCallback()1050b57cec5SDimitry Andric LLVMSymbolLookupCallback getSymbolLookupCallback() const { 1060b57cec5SDimitry Andric return SymbolLookUp; 1070b57cec5SDimitry Andric } getTarget()1080b57cec5SDimitry Andric const Target *getTarget() const { return TheTarget; } getDisAsm()1090b57cec5SDimitry Andric const MCDisassembler *getDisAsm() const { return DisAsm.get(); } getAsmInfo()1100b57cec5SDimitry Andric const MCAsmInfo *getAsmInfo() const { return MAI.get(); } getInstrInfo()1110b57cec5SDimitry Andric const MCInstrInfo *getInstrInfo() const { return MII.get(); } getRegisterInfo()1120b57cec5SDimitry Andric const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); } getSubtargetInfo()1130b57cec5SDimitry Andric const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); } getIP()1140b57cec5SDimitry Andric MCInstPrinter *getIP() { return IP.get(); } setIP(MCInstPrinter * NewIP)1150b57cec5SDimitry Andric void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); } getOptions()1160b57cec5SDimitry Andric uint64_t getOptions() const { return Options; } addOptions(uint64_t Options)1170b57cec5SDimitry Andric void addOptions(uint64_t Options) { this->Options |= Options; } getCPU()1180b57cec5SDimitry Andric StringRef getCPU() const { return CPU; } setCPU(const char * CPU)1190b57cec5SDimitry Andric void setCPU(const char *CPU) { this->CPU = CPU; } 1200b57cec5SDimitry Andric }; 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andric } // namespace llvm 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric #endif 125