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