1*9880d681SAndroid Build Coastguard Worker //===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===// 2*9880d681SAndroid Build Coastguard Worker // 3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure 4*9880d681SAndroid Build Coastguard Worker // 5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source 6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details. 7*9880d681SAndroid Build Coastguard Worker // 8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 9*9880d681SAndroid Build Coastguard Worker // 10*9880d681SAndroid Build Coastguard Worker // This file defines the interface for the Disassembly library's disassembler 11*9880d681SAndroid Build Coastguard Worker // context. The disassembler is responsible for producing strings for 12*9880d681SAndroid Build Coastguard Worker // individual instructions according to a given architecture and disassembly 13*9880d681SAndroid Build Coastguard Worker // syntax. 14*9880d681SAndroid Build Coastguard Worker // 15*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===// 16*9880d681SAndroid Build Coastguard Worker 17*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H 18*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H 19*9880d681SAndroid Build Coastguard Worker 20*9880d681SAndroid Build Coastguard Worker #include "llvm-c/Disassembler.h" 21*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallString.h" 22*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCAsmInfo.h" 23*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCContext.h" 24*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCDisassembler/MCDisassembler.h" 25*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCInstPrinter.h" 26*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCInstrInfo.h" 27*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCRegisterInfo.h" 28*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCSubtargetInfo.h" 29*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h" 30*9880d681SAndroid Build Coastguard Worker #include <string> 31*9880d681SAndroid Build Coastguard Worker #include <utility> 32*9880d681SAndroid Build Coastguard Worker 33*9880d681SAndroid Build Coastguard Worker namespace llvm { 34*9880d681SAndroid Build Coastguard Worker class Target; 35*9880d681SAndroid Build Coastguard Worker 36*9880d681SAndroid Build Coastguard Worker // 37*9880d681SAndroid Build Coastguard Worker // This is the disassembler context returned by LLVMCreateDisasm(). 38*9880d681SAndroid Build Coastguard Worker // 39*9880d681SAndroid Build Coastguard Worker class LLVMDisasmContext { 40*9880d681SAndroid Build Coastguard Worker private: 41*9880d681SAndroid Build Coastguard Worker // 42*9880d681SAndroid Build Coastguard Worker // The passed parameters when the disassembler context is created. 43*9880d681SAndroid Build Coastguard Worker // 44*9880d681SAndroid Build Coastguard Worker // The TripleName for this disassembler. 45*9880d681SAndroid Build Coastguard Worker std::string TripleName; 46*9880d681SAndroid Build Coastguard Worker // The pointer to the caller's block of symbolic information. 47*9880d681SAndroid Build Coastguard Worker void *DisInfo; 48*9880d681SAndroid Build Coastguard Worker // The Triple specific symbolic information type returned by GetOpInfo. 49*9880d681SAndroid Build Coastguard Worker int TagType; 50*9880d681SAndroid Build Coastguard Worker // The function to get the symbolic information for operands. 51*9880d681SAndroid Build Coastguard Worker LLVMOpInfoCallback GetOpInfo; 52*9880d681SAndroid Build Coastguard Worker // The function to look up a symbol name. 53*9880d681SAndroid Build Coastguard Worker LLVMSymbolLookupCallback SymbolLookUp; 54*9880d681SAndroid Build Coastguard Worker // 55*9880d681SAndroid Build Coastguard Worker // The objects created and saved by LLVMCreateDisasm() then used by 56*9880d681SAndroid Build Coastguard Worker // LLVMDisasmInstruction(). 57*9880d681SAndroid Build Coastguard Worker // 58*9880d681SAndroid Build Coastguard Worker // The LLVM target corresponding to the disassembler. 59*9880d681SAndroid Build Coastguard Worker // FIXME: using std::unique_ptr<const llvm::Target> causes a malloc error 60*9880d681SAndroid Build Coastguard Worker // when this LLVMDisasmContext is deleted. 61*9880d681SAndroid Build Coastguard Worker const Target *TheTarget; 62*9880d681SAndroid Build Coastguard Worker // The assembly information for the target architecture. 63*9880d681SAndroid Build Coastguard Worker std::unique_ptr<const llvm::MCAsmInfo> MAI; 64*9880d681SAndroid Build Coastguard Worker // The register information for the target architecture. 65*9880d681SAndroid Build Coastguard Worker std::unique_ptr<const llvm::MCRegisterInfo> MRI; 66*9880d681SAndroid Build Coastguard Worker // The subtarget information for the target architecture. 67*9880d681SAndroid Build Coastguard Worker std::unique_ptr<const llvm::MCSubtargetInfo> MSI; 68*9880d681SAndroid Build Coastguard Worker // The instruction information for the target architecture. 69*9880d681SAndroid Build Coastguard Worker std::unique_ptr<const llvm::MCInstrInfo> MII; 70*9880d681SAndroid Build Coastguard Worker // The assembly context for creating symbols and MCExprs. 71*9880d681SAndroid Build Coastguard Worker std::unique_ptr<const llvm::MCContext> Ctx; 72*9880d681SAndroid Build Coastguard Worker // The disassembler for the target architecture. 73*9880d681SAndroid Build Coastguard Worker std::unique_ptr<const llvm::MCDisassembler> DisAsm; 74*9880d681SAndroid Build Coastguard Worker // The instruction printer for the target architecture. 75*9880d681SAndroid Build Coastguard Worker std::unique_ptr<llvm::MCInstPrinter> IP; 76*9880d681SAndroid Build Coastguard Worker // The options used to set up the disassembler. 77*9880d681SAndroid Build Coastguard Worker uint64_t Options; 78*9880d681SAndroid Build Coastguard Worker // The CPU string. 79*9880d681SAndroid Build Coastguard Worker std::string CPU; 80*9880d681SAndroid Build Coastguard Worker 81*9880d681SAndroid Build Coastguard Worker public: 82*9880d681SAndroid Build Coastguard Worker // Comment stream and backing vector. 83*9880d681SAndroid Build Coastguard Worker SmallString<128> CommentsToEmit; 84*9880d681SAndroid Build Coastguard Worker raw_svector_ostream CommentStream; 85*9880d681SAndroid Build Coastguard Worker LLVMDisasmContext(std::string tripleName,void * disInfo,int tagType,LLVMOpInfoCallback getOpInfo,LLVMSymbolLookupCallback symbolLookUp,const Target * theTarget,const MCAsmInfo * mAI,const MCRegisterInfo * mRI,const MCSubtargetInfo * mSI,const MCInstrInfo * mII,llvm::MCContext * ctx,const MCDisassembler * disAsm,MCInstPrinter * iP)86*9880d681SAndroid Build Coastguard Worker LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType, 87*9880d681SAndroid Build Coastguard Worker LLVMOpInfoCallback getOpInfo, 88*9880d681SAndroid Build Coastguard Worker LLVMSymbolLookupCallback symbolLookUp, 89*9880d681SAndroid Build Coastguard Worker const Target *theTarget, const MCAsmInfo *mAI, 90*9880d681SAndroid Build Coastguard Worker const MCRegisterInfo *mRI, const MCSubtargetInfo *mSI, 91*9880d681SAndroid Build Coastguard Worker const MCInstrInfo *mII, llvm::MCContext *ctx, 92*9880d681SAndroid Build Coastguard Worker const MCDisassembler *disAsm, MCInstPrinter *iP) 93*9880d681SAndroid Build Coastguard Worker : TripleName(std::move(tripleName)), DisInfo(disInfo), TagType(tagType), 94*9880d681SAndroid Build Coastguard Worker GetOpInfo(getOpInfo), SymbolLookUp(symbolLookUp), TheTarget(theTarget), 95*9880d681SAndroid Build Coastguard Worker Options(0), CommentStream(CommentsToEmit) { 96*9880d681SAndroid Build Coastguard Worker MAI.reset(mAI); 97*9880d681SAndroid Build Coastguard Worker MRI.reset(mRI); 98*9880d681SAndroid Build Coastguard Worker MSI.reset(mSI); 99*9880d681SAndroid Build Coastguard Worker MII.reset(mII); 100*9880d681SAndroid Build Coastguard Worker Ctx.reset(ctx); 101*9880d681SAndroid Build Coastguard Worker DisAsm.reset(disAsm); 102*9880d681SAndroid Build Coastguard Worker IP.reset(iP); 103*9880d681SAndroid Build Coastguard Worker } getTripleName()104*9880d681SAndroid Build Coastguard Worker const std::string &getTripleName() const { return TripleName; } getDisInfo()105*9880d681SAndroid Build Coastguard Worker void *getDisInfo() const { return DisInfo; } getTagType()106*9880d681SAndroid Build Coastguard Worker int getTagType() const { return TagType; } getGetOpInfo()107*9880d681SAndroid Build Coastguard Worker LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; } getSymbolLookupCallback()108*9880d681SAndroid Build Coastguard Worker LLVMSymbolLookupCallback getSymbolLookupCallback() const { 109*9880d681SAndroid Build Coastguard Worker return SymbolLookUp; 110*9880d681SAndroid Build Coastguard Worker } getTarget()111*9880d681SAndroid Build Coastguard Worker const Target *getTarget() const { return TheTarget; } getDisAsm()112*9880d681SAndroid Build Coastguard Worker const MCDisassembler *getDisAsm() const { return DisAsm.get(); } getAsmInfo()113*9880d681SAndroid Build Coastguard Worker const MCAsmInfo *getAsmInfo() const { return MAI.get(); } getInstrInfo()114*9880d681SAndroid Build Coastguard Worker const MCInstrInfo *getInstrInfo() const { return MII.get(); } getRegisterInfo()115*9880d681SAndroid Build Coastguard Worker const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); } getSubtargetInfo()116*9880d681SAndroid Build Coastguard Worker const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); } getIP()117*9880d681SAndroid Build Coastguard Worker MCInstPrinter *getIP() { return IP.get(); } setIP(MCInstPrinter * NewIP)118*9880d681SAndroid Build Coastguard Worker void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); } getOptions()119*9880d681SAndroid Build Coastguard Worker uint64_t getOptions() const { return Options; } addOptions(uint64_t Options)120*9880d681SAndroid Build Coastguard Worker void addOptions(uint64_t Options) { this->Options |= Options; } getCPU()121*9880d681SAndroid Build Coastguard Worker StringRef getCPU() const { return CPU; } setCPU(const char * CPU)122*9880d681SAndroid Build Coastguard Worker void setCPU(const char *CPU) { this->CPU = CPU; } 123*9880d681SAndroid Build Coastguard Worker }; 124*9880d681SAndroid Build Coastguard Worker 125*9880d681SAndroid Build Coastguard Worker } // namespace llvm 126*9880d681SAndroid Build Coastguard Worker 127*9880d681SAndroid Build Coastguard Worker #endif 128