Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 1 | //===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 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 |
| 13 | // syntax. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 69ffd7a | 2011-04-24 15:46:56 +0000 | [diff] [blame] | 16 | |
| 17 | #ifndef LLVM_MC_DISASSEMBLER_H |
| 18 | #define LLVM_MC_DISASSEMBLER_H |
| 19 | |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 20 | #include "llvm-c/Disassembler.h" |
| 21 | #include <string> |
| 22 | #include "llvm/ADT/OwningPtr.h" |
Owen Anderson | 8f29e69 | 2011-09-15 18:37:20 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/SmallString.h" |
| 24 | #include "llvm/Support/raw_ostream.h" |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 25 | |
| 26 | namespace llvm { |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 27 | class MCContext; |
| 28 | class MCAsmInfo; |
| 29 | class MCDisassembler; |
| 30 | class MCInstPrinter; |
Sean Callanan | 55e7980 | 2012-04-06 18:21:09 +0000 | [diff] [blame] | 31 | class MCInstrInfo; |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 32 | class MCRegisterInfo; |
Sean Callanan | 55e7980 | 2012-04-06 18:21:09 +0000 | [diff] [blame] | 33 | class MCSubtargetInfo; |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 34 | class Target; |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 35 | |
| 36 | // |
| 37 | // This is the disassembler context returned by LLVMCreateDisasm(). |
| 38 | // |
| 39 | class LLVMDisasmContext { |
| 40 | private: |
| 41 | // |
| 42 | // The passed parameters when the disassembler context is created. |
| 43 | // |
| 44 | // The TripleName for this disassembler. |
| 45 | std::string TripleName; |
| 46 | // The pointer to the caller's block of symbolic information. |
| 47 | void *DisInfo; |
| 48 | // The Triple specific symbolic information type returned by GetOpInfo. |
| 49 | int TagType; |
| 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; |
| 54 | // |
| 55 | // The objects created and saved by LLVMCreateDisasm() then used by |
| 56 | // LLVMDisasmInstruction(). |
| 57 | // |
| 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; |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 64 | // The register information for the target architecture. |
| 65 | llvm::OwningPtr<const llvm::MCRegisterInfo> MRI; |
Sean Callanan | 55e7980 | 2012-04-06 18:21:09 +0000 | [diff] [blame] | 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; |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 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 | |
| 77 | public: |
Owen Anderson | 8f29e69 | 2011-09-15 18:37:20 +0000 | [diff] [blame] | 78 | // Comment stream and backing vector. |
| 79 | SmallString<128> CommentsToEmit; |
| 80 | raw_svector_ostream CommentStream; |
| 81 | |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 82 | LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType, |
Kevin Enderby | bd33276 | 2011-04-11 18:08:50 +0000 | [diff] [blame] | 83 | LLVMOpInfoCallback getOpInfo, |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 84 | LLVMSymbolLookupCallback symbolLookUp, |
| 85 | const Target *theTarget, const MCAsmInfo *mAI, |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 86 | const MCRegisterInfo *mRI, |
Sean Callanan | 55e7980 | 2012-04-06 18:21:09 +0000 | [diff] [blame] | 87 | const MCSubtargetInfo *mSI, |
| 88 | const MCInstrInfo *mII, |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 89 | llvm::MCContext *ctx, const MCDisassembler *disAsm, |
| 90 | MCInstPrinter *iP) : TripleName(tripleName), |
| 91 | DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo), |
Owen Anderson | 8f29e69 | 2011-09-15 18:37:20 +0000 | [diff] [blame] | 92 | SymbolLookUp(symbolLookUp), TheTarget(theTarget), |
| 93 | CommentStream(CommentsToEmit) { |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 94 | MAI.reset(mAI); |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 95 | MRI.reset(mRI); |
Sean Callanan | 55e7980 | 2012-04-06 18:21:09 +0000 | [diff] [blame] | 96 | MSI.reset(mSI); |
| 97 | MII.reset(mII); |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 98 | Ctx.reset(ctx); |
| 99 | DisAsm.reset(disAsm); |
| 100 | IP.reset(iP); |
| 101 | } |
Benjamin Kramer | 8e5271d | 2012-06-06 20:45:10 +0000 | [diff] [blame] | 102 | const std::string &getTripleName() const { return TripleName; } |
| 103 | void *getDisInfo() const { return DisInfo; } |
| 104 | int getTagType() const { return TagType; } |
| 105 | LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; } |
| 106 | LLVMSymbolLookupCallback getSymbolLookupCallback() const { |
| 107 | return SymbolLookUp; |
| 108 | } |
| 109 | const Target *getTarget() const { return TheTarget; } |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 110 | const MCDisassembler *getDisAsm() const { return DisAsm.get(); } |
Owen Anderson | 8f29e69 | 2011-09-15 18:37:20 +0000 | [diff] [blame] | 111 | const MCAsmInfo *getAsmInfo() const { return MAI.get(); } |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 112 | MCInstPrinter *getIP() { return IP.get(); } |
| 113 | }; |
| 114 | |
| 115 | } // namespace llvm |
Sebastian Redl | 69ffd7a | 2011-04-24 15:46:56 +0000 | [diff] [blame] | 116 | |
| 117 | #endif |