1 //===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface for the Disassembly library's disassembler
11 // context. The disassembler is responsible for producing strings for
12 // individual instructions according to a given architecture and disassembly
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_MC_DISASSEMBLER_H
18 #define LLVM_MC_DISASSEMBLER_H
20 #include "llvm-c/Disassembler.h"
21 #include "llvm/ADT/OwningPtr.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/Support/raw_ostream.h"
33 class MCSubtargetInfo;
37 // This is the disassembler context returned by LLVMCreateDisasm().
39 class LLVMDisasmContext {
42 // The passed parameters when the disassembler context is created.
44 // The TripleName for this disassembler.
45 std::string TripleName;
46 // The pointer to the caller's block of symbolic information.
48 // The Triple specific symbolic information type returned by GetOpInfo.
50 // The function to get the symbolic information for operands.
51 LLVMOpInfoCallback GetOpInfo;
52 // The function to look up a symbol name.
53 LLVMSymbolLookupCallback SymbolLookUp;
55 // The objects created and saved by LLVMCreateDisasm() then used by
56 // LLVMDisasmInstruction().
58 // The LLVM target corresponding to the disassembler.
59 // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
60 // when this LLVMDisasmContext is deleted.
61 const Target *TheTarget;
62 // The assembly information for the target architecture.
63 llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
64 // The register information for the target architecture.
65 llvm::OwningPtr<const llvm::MCRegisterInfo> MRI;
66 // The subtarget information for the target architecture.
67 llvm::OwningPtr<const llvm::MCSubtargetInfo> MSI;
68 // The instruction information for the target architecture.
69 llvm::OwningPtr<const llvm::MCInstrInfo> MII;
70 // The assembly context for creating symbols and MCExprs.
71 llvm::OwningPtr<const llvm::MCContext> Ctx;
72 // The disassembler for the target architecture.
73 llvm::OwningPtr<const llvm::MCDisassembler> DisAsm;
74 // The instruction printer for the target architecture.
75 llvm::OwningPtr<llvm::MCInstPrinter> IP;
76 // The options used to set up the disassembler.
80 // Comment stream and backing vector.
81 SmallString<128> CommentsToEmit;
82 raw_svector_ostream CommentStream;
84 LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
85 LLVMOpInfoCallback getOpInfo,
86 LLVMSymbolLookupCallback symbolLookUp,
87 const Target *theTarget, const MCAsmInfo *mAI,
88 const MCRegisterInfo *mRI,
89 const MCSubtargetInfo *mSI,
90 const MCInstrInfo *mII,
91 llvm::MCContext *ctx, const MCDisassembler *disAsm,
92 MCInstPrinter *iP) : TripleName(tripleName),
93 DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
94 SymbolLookUp(symbolLookUp), TheTarget(theTarget),
96 CommentStream(CommentsToEmit) {
102 DisAsm.reset(disAsm);
105 const std::string &getTripleName() const { return TripleName; }
106 void *getDisInfo() const { return DisInfo; }
107 int getTagType() const { return TagType; }
108 LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }
109 LLVMSymbolLookupCallback getSymbolLookupCallback() const {
112 const Target *getTarget() const { return TheTarget; }
113 const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
114 const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
115 const MCInstrInfo *getInstrInfo() const { return MII.get(); }
116 const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); }
117 const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); }
118 MCInstPrinter *getIP() { return IP.get(); }
119 void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); }
120 uint64_t getOptions() const { return Options; }
121 void addOptions(uint64_t Options) { this->Options |= Options; }