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