Disassembler.h revision 221337
1250199Sgrehan//===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//
2250199Sgrehan//
3250199Sgrehan//                     The LLVM Compiler Infrastructure
4250199Sgrehan//
5250199Sgrehan// This file is distributed under the University of Illinois Open Source
6250199Sgrehan// License. See LICENSE.TXT for details.
7250199Sgrehan//
8250199Sgrehan//===----------------------------------------------------------------------===//
9250199Sgrehan//
10250199Sgrehan// This file defines the interface for the Disassembly library's disassembler
11250199Sgrehan// context.  The disassembler is responsible for producing strings for
12250199Sgrehan// individual instructions according to a given architecture and disassembly
13250199Sgrehan// syntax.
14250199Sgrehan//
15250199Sgrehan//===----------------------------------------------------------------------===//
16250199Sgrehan
17250199Sgrehan#ifndef LLVM_MC_DISASSEMBLER_H
18250199Sgrehan#define LLVM_MC_DISASSEMBLER_H
19250199Sgrehan
20250199Sgrehan#include "llvm-c/Disassembler.h"
21250199Sgrehan#include <string>
22250199Sgrehan#include "llvm/ADT/OwningPtr.h"
23250199Sgrehan
24250199Sgrehannamespace llvm {
25250199Sgrehanclass TargetAsmInfo;
26250199Sgrehanclass MCContext;
27250199Sgrehanclass MCAsmInfo;
28250199Sgrehanclass MCDisassembler;
29250199Sgrehanclass MCInstPrinter;
30250199Sgrehanclass Target;
31250199Sgrehanclass TargetMachine;
32250199Sgrehan
33250199Sgrehan//
34250199Sgrehan// This is the disassembler context returned by LLVMCreateDisasm().
35250199Sgrehan//
36250199Sgrehanclass LLVMDisasmContext {
37250199Sgrehanprivate:
38250199Sgrehan  //
39250199Sgrehan  // The passed parameters when the disassembler context is created.
40250199Sgrehan  //
41250199Sgrehan  // The TripleName for this disassembler.
42250199Sgrehan  std::string TripleName;
43250199Sgrehan  // The pointer to the caller's block of symbolic information.
44250199Sgrehan  void *DisInfo;
45250199Sgrehan  // The Triple specific symbolic information type returned by GetOpInfo.
46250199Sgrehan  int TagType;
47250199Sgrehan  // The function to get the symbolic information for operands.
48282212Swhu  LLVMOpInfoCallback GetOpInfo;
49282212Swhu  // The function to look up a symbol name.
50282212Swhu  LLVMSymbolLookupCallback SymbolLookUp;
51282212Swhu  //
52282212Swhu  // The objects created and saved by LLVMCreateDisasm() then used by
53282212Swhu  // LLVMDisasmInstruction().
54282212Swhu  //
55282212Swhu  // The LLVM target corresponding to the disassembler.
56282212Swhu  // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
57282212Swhu  //        when this LLVMDisasmContext is deleted.
58282212Swhu  const Target *TheTarget;
59282212Swhu  // The assembly information for the target architecture.
60282212Swhu  llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
61282212Swhu  // The target machine instance.
62282212Swhu  llvm::OwningPtr<llvm::TargetMachine> TM;
63282212Swhu  // The disassembler for the target architecture.
64282212Swhu  // FIXME: using llvm::OwningPtr<const llvm::TargetAsmInfo> causes a malloc
65282212Swhu  //        error when this LLVMDisasmContext is deleted.
66282212Swhu  const TargetAsmInfo *Tai;
67282212Swhu  // The assembly context for creating symbols and MCExprs.
68282212Swhu  llvm::OwningPtr<const llvm::MCContext> Ctx;
69250199Sgrehan  // The disassembler for the target architecture.
70282212Swhu  llvm::OwningPtr<const llvm::MCDisassembler> DisAsm;
71282212Swhu  // The instruction printer for the target architecture.
72282212Swhu  llvm::OwningPtr<llvm::MCInstPrinter> IP;
73282212Swhu
74282212Swhupublic:
75282212Swhu  LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
76282212Swhu                    LLVMOpInfoCallback getOpInfo,
77282212Swhu                    LLVMSymbolLookupCallback symbolLookUp,
78282212Swhu                    const Target *theTarget, const MCAsmInfo *mAI,
79282212Swhu                    llvm::TargetMachine *tM, const TargetAsmInfo *tai,
80282212Swhu                    llvm::MCContext *ctx, const MCDisassembler *disAsm,
81282212Swhu                    MCInstPrinter *iP) : TripleName(tripleName),
82282212Swhu                    DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
83282212Swhu                    SymbolLookUp(symbolLookUp), TheTarget(theTarget), Tai(tai) {
84282212Swhu    TM.reset(tM);
85282212Swhu    MAI.reset(mAI);
86282212Swhu    Ctx.reset(ctx);
87282212Swhu    DisAsm.reset(disAsm);
88282212Swhu    IP.reset(iP);
89295309Ssephe  }
90282212Swhu  const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
91295308Ssephe  MCInstPrinter *getIP() { return IP.get(); }
92295309Ssephe};
93282212Swhu
94282212Swhu} // namespace llvm
95282212Swhu
96282212Swhu#endif
97282212Swhu