LLVM API Documentation

lib/MC/MCDisassembler/Disassembler.h
Go to the documentation of this file.
00001 //===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the interface for the Disassembly library's disassembler 
00011 // context.  The disassembler is responsible for producing strings for
00012 // individual instructions according to a given architecture and disassembly
00013 // syntax.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
00018 #define LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
00019 
00020 #include "llvm-c/Disassembler.h"
00021 #include "llvm/ADT/SmallString.h"
00022 #include "llvm/Support/raw_ostream.h"
00023 #include <string>
00024 
00025 namespace llvm {
00026 class MCContext;
00027 class MCAsmInfo;
00028 class MCDisassembler;
00029 class MCInstPrinter; 
00030 class MCInstrInfo;
00031 class MCRegisterInfo;
00032 class MCSubtargetInfo;
00033 class Target;
00034 
00035 //
00036 // This is the disassembler context returned by LLVMCreateDisasm().
00037 //
00038 class LLVMDisasmContext {
00039 private:
00040   //
00041   // The passed parameters when the disassembler context is created.
00042   //
00043   // The TripleName for this disassembler.
00044   std::string TripleName;
00045   // The pointer to the caller's block of symbolic information.
00046   void *DisInfo;
00047   // The Triple specific symbolic information type returned by GetOpInfo.
00048   int TagType;
00049   // The function to get the symbolic information for operands.
00050   LLVMOpInfoCallback GetOpInfo;
00051   // The function to look up a symbol name.
00052   LLVMSymbolLookupCallback SymbolLookUp;
00053   //
00054   // The objects created and saved by LLVMCreateDisasm() then used by
00055   // LLVMDisasmInstruction().
00056   //
00057   // The LLVM target corresponding to the disassembler.
00058   // FIXME: using std::unique_ptr<const llvm::Target> causes a malloc error
00059   //        when this LLVMDisasmContext is deleted.
00060   const Target *TheTarget;
00061   // The assembly information for the target architecture.
00062   std::unique_ptr<const llvm::MCAsmInfo> MAI;
00063   // The register information for the target architecture.
00064   std::unique_ptr<const llvm::MCRegisterInfo> MRI;
00065   // The subtarget information for the target architecture.
00066   std::unique_ptr<const llvm::MCSubtargetInfo> MSI;
00067   // The instruction information for the target architecture.
00068   std::unique_ptr<const llvm::MCInstrInfo> MII;
00069   // The assembly context for creating symbols and MCExprs.
00070   std::unique_ptr<const llvm::MCContext> Ctx;
00071   // The disassembler for the target architecture.
00072   std::unique_ptr<const llvm::MCDisassembler> DisAsm;
00073   // The instruction printer for the target architecture.
00074   std::unique_ptr<llvm::MCInstPrinter> IP;
00075   // The options used to set up the disassembler.
00076   uint64_t Options;
00077   // The CPU string.
00078   std::string CPU;
00079 
00080 public:
00081   // Comment stream and backing vector.
00082   SmallString<128> CommentsToEmit;
00083   raw_svector_ostream CommentStream;
00084 
00085   LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
00086                     LLVMOpInfoCallback getOpInfo,
00087                     LLVMSymbolLookupCallback symbolLookUp,
00088                     const Target *theTarget, const MCAsmInfo *mAI,
00089                     const MCRegisterInfo *mRI,
00090                     const MCSubtargetInfo *mSI,
00091                     const MCInstrInfo *mII,
00092                     llvm::MCContext *ctx, const MCDisassembler *disAsm,
00093                     MCInstPrinter *iP) : TripleName(tripleName),
00094                     DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
00095                     SymbolLookUp(symbolLookUp), TheTarget(theTarget),
00096                     Options(0),
00097                     CommentStream(CommentsToEmit) {
00098     MAI.reset(mAI);
00099     MRI.reset(mRI);
00100     MSI.reset(mSI);
00101     MII.reset(mII);
00102     Ctx.reset(ctx);
00103     DisAsm.reset(disAsm);
00104     IP.reset(iP);
00105   }
00106   const std::string &getTripleName() const { return TripleName; }
00107   void *getDisInfo() const { return DisInfo; }
00108   int getTagType() const { return TagType; }
00109   LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }
00110   LLVMSymbolLookupCallback getSymbolLookupCallback() const {
00111     return SymbolLookUp;
00112   }
00113   const Target *getTarget() const { return TheTarget; }
00114   const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
00115   const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
00116   const MCInstrInfo *getInstrInfo() const { return MII.get(); }
00117   const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); }
00118   const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); }
00119   MCInstPrinter *getIP() { return IP.get(); }
00120   void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); }
00121   uint64_t getOptions() const { return Options; }
00122   void addOptions(uint64_t Options) { this->Options |= Options; }
00123   StringRef getCPU() const { return CPU; }
00124   void setCPU(const char *CPU) { this->CPU = CPU; }
00125 };
00126 
00127 } // namespace llvm
00128 
00129 #endif