Again adding a C API to the disassembler for use by such tools as Darwin's
[oota-llvm.git] / lib / MC / MCDisassembler / Disassembler.h
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 //===----------------------------------------------------------------------===//
16 #include "llvm-c/Disassembler.h"
17 #include <string>
18 #include "llvm/ADT/OwningPtr.h"
19
20 namespace llvm {
21 class TargetAsmInfo;
22 class MCContext;
23 class MCAsmInfo;
24 class MCDisassembler;
25 class MCInstPrinter; 
26 class Target;
27 class TargetMachine;
28
29 //
30 // This is the disassembler context returned by LLVMCreateDisasm().
31 //
32 class LLVMDisasmContext {
33 private:
34   //
35   // The passed parameters when the disassembler context is created.
36   //
37   // The TripleName for this disassembler.
38   std::string TripleName;
39   // The pointer to the caller's block of symbolic information.
40   void *DisInfo;
41   // The Triple specific symbolic information type returned by GetOpInfo.
42   int TagType;
43   // The function to get the symbolic information for operands.
44   LLVMOpInfoCallback GetOpInfo;
45   // The function to look up a symbol name.
46   LLVMSymbolLookupCallback SymbolLookUp;
47   //
48   // The objects created and saved by LLVMCreateDisasm() then used by
49   // LLVMDisasmInstruction().
50   //
51   // The LLVM target corresponding to the disassembler.
52   // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
53   //        when this LLVMDisasmContext is deleted.
54   const Target *TheTarget;
55   // The assembly information for the target architecture.
56   llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
57   // The target machine instance.
58   llvm::OwningPtr<llvm::TargetMachine> TM;
59   // The disassembler for the target architecture.
60   // FIXME: using llvm::OwningPtr<const llvm::TargetAsmInfo> causes a malloc
61   //        error when this LLVMDisasmContext is deleted.
62   const TargetAsmInfo *Tai;
63   // The assembly context for creating symbols and MCExprs.
64   llvm::OwningPtr<const llvm::MCContext> Ctx;
65   // The disassembler for the target architecture.
66   llvm::OwningPtr<const llvm::MCDisassembler> DisAsm;
67   // The instruction printer for the target architecture.
68   llvm::OwningPtr<llvm::MCInstPrinter> IP;
69
70 public:
71   LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
72           LLVMOpInfoCallback getOpInfo,
73                     LLVMSymbolLookupCallback symbolLookUp,
74                     const Target *theTarget, const MCAsmInfo *mAI,
75                     llvm::TargetMachine *tM, const TargetAsmInfo *tai,
76                     llvm::MCContext *ctx, const MCDisassembler *disAsm,
77                     MCInstPrinter *iP) : TripleName(tripleName),
78                     DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
79                     SymbolLookUp(symbolLookUp), TheTarget(theTarget), Tai(tai) {
80     TM.reset(tM);
81     MAI.reset(mAI);
82     Ctx.reset(ctx);
83     DisAsm.reset(disAsm);
84     IP.reset(iP);
85   }
86   const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
87   MCInstPrinter *getIP() { return IP.get(); }
88 };
89
90 } // namespace llvm