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; |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 31 | class MCRegisterInfo; |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 32 | class Target; |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 33 | |
| 34 | // |
| 35 | // This is the disassembler context returned by LLVMCreateDisasm(). |
| 36 | // |
| 37 | class LLVMDisasmContext { |
| 38 | private: |
| 39 | // |
| 40 | // The passed parameters when the disassembler context is created. |
| 41 | // |
| 42 | // The TripleName for this disassembler. |
| 43 | std::string TripleName; |
| 44 | // The pointer to the caller's block of symbolic information. |
| 45 | void *DisInfo; |
| 46 | // The Triple specific symbolic information type returned by GetOpInfo. |
| 47 | int TagType; |
| 48 | // The function to get the symbolic information for operands. |
| 49 | LLVMOpInfoCallback GetOpInfo; |
| 50 | // The function to look up a symbol name. |
| 51 | LLVMSymbolLookupCallback SymbolLookUp; |
| 52 | // |
| 53 | // The objects created and saved by LLVMCreateDisasm() then used by |
| 54 | // LLVMDisasmInstruction(). |
| 55 | // |
| 56 | // The LLVM target corresponding to the disassembler. |
| 57 | // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error |
| 58 | // when this LLVMDisasmContext is deleted. |
| 59 | const Target *TheTarget; |
| 60 | // The assembly information for the target architecture. |
| 61 | llvm::OwningPtr<const llvm::MCAsmInfo> MAI; |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 62 | // The register information for the target architecture. |
| 63 | llvm::OwningPtr<const llvm::MCRegisterInfo> MRI; |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 64 | // The assembly context for creating symbols and MCExprs. |
| 65 | llvm::OwningPtr<const llvm::MCContext> Ctx; |
| 66 | // The disassembler for the target architecture. |
| 67 | llvm::OwningPtr<const llvm::MCDisassembler> DisAsm; |
| 68 | // The instruction printer for the target architecture. |
| 69 | llvm::OwningPtr<llvm::MCInstPrinter> IP; |
| 70 | |
| 71 | public: |
Owen Anderson | 8f29e69 | 2011-09-15 18:37:20 +0000 | [diff] [blame] | 72 | // Comment stream and backing vector. |
| 73 | SmallString<128> CommentsToEmit; |
| 74 | raw_svector_ostream CommentStream; |
| 75 | |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 76 | LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType, |
Kevin Enderby | bd33276 | 2011-04-11 18:08:50 +0000 | [diff] [blame] | 77 | LLVMOpInfoCallback getOpInfo, |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 78 | LLVMSymbolLookupCallback symbolLookUp, |
| 79 | const Target *theTarget, const MCAsmInfo *mAI, |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 80 | const MCRegisterInfo *mRI, |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 81 | llvm::MCContext *ctx, const MCDisassembler *disAsm, |
| 82 | MCInstPrinter *iP) : TripleName(tripleName), |
| 83 | DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo), |
Owen Anderson | 8f29e69 | 2011-09-15 18:37:20 +0000 | [diff] [blame] | 84 | SymbolLookUp(symbolLookUp), TheTarget(theTarget), |
| 85 | CommentStream(CommentsToEmit) { |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 86 | MAI.reset(mAI); |
Evan Cheng | 0e6a052 | 2011-07-18 20:57:22 +0000 | [diff] [blame] | 87 | MRI.reset(mRI); |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 88 | Ctx.reset(ctx); |
| 89 | DisAsm.reset(disAsm); |
| 90 | IP.reset(iP); |
| 91 | } |
| 92 | const MCDisassembler *getDisAsm() const { return DisAsm.get(); } |
Owen Anderson | 8f29e69 | 2011-09-15 18:37:20 +0000 | [diff] [blame] | 93 | const MCAsmInfo *getAsmInfo() const { return MAI.get(); } |
Kevin Enderby | 93f7936 | 2011-03-28 18:25:07 +0000 | [diff] [blame] | 94 | MCInstPrinter *getIP() { return IP.get(); } |
| 95 | }; |
| 96 | |
| 97 | } // namespace llvm |
Sebastian Redl | 69ffd7a | 2011-04-24 15:46:56 +0000 | [diff] [blame] | 98 | |
| 99 | #endif |