Disassembler.h revision 221337
1221337Sdim//===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//
2221337Sdim//
3221337Sdim//                     The LLVM Compiler Infrastructure
4221337Sdim//
5221337Sdim// This file is distributed under the University of Illinois Open Source
6221337Sdim// License. See LICENSE.TXT for details.
7221337Sdim//
8221337Sdim//===----------------------------------------------------------------------===//
9221337Sdim//
10221337Sdim// This file defines the interface for the Disassembly library's disassembler
11221337Sdim// context.  The disassembler is responsible for producing strings for
12221337Sdim// individual instructions according to a given architecture and disassembly
13221337Sdim// syntax.
14221337Sdim//
15221337Sdim//===----------------------------------------------------------------------===//
16221337Sdim
17221337Sdim#ifndef LLVM_MC_DISASSEMBLER_H
18221337Sdim#define LLVM_MC_DISASSEMBLER_H
19221337Sdim
20221337Sdim#include "llvm-c/Disassembler.h"
21221337Sdim#include <string>
22221337Sdim#include "llvm/ADT/OwningPtr.h"
23221337Sdim
24221337Sdimnamespace llvm {
25221337Sdimclass TargetAsmInfo;
26221337Sdimclass MCContext;
27221337Sdimclass MCAsmInfo;
28221337Sdimclass MCDisassembler;
29221337Sdimclass MCInstPrinter;
30221337Sdimclass Target;
31221337Sdimclass TargetMachine;
32221337Sdim
33221337Sdim//
34221337Sdim// This is the disassembler context returned by LLVMCreateDisasm().
35221337Sdim//
36221337Sdimclass LLVMDisasmContext {
37221337Sdimprivate:
38221337Sdim  //
39221337Sdim  // The passed parameters when the disassembler context is created.
40221337Sdim  //
41221337Sdim  // The TripleName for this disassembler.
42221337Sdim  std::string TripleName;
43221337Sdim  // The pointer to the caller's block of symbolic information.
44221337Sdim  void *DisInfo;
45221337Sdim  // The Triple specific symbolic information type returned by GetOpInfo.
46221337Sdim  int TagType;
47221337Sdim  // The function to get the symbolic information for operands.
48221337Sdim  LLVMOpInfoCallback GetOpInfo;
49221337Sdim  // The function to look up a symbol name.
50221337Sdim  LLVMSymbolLookupCallback SymbolLookUp;
51221337Sdim  //
52221337Sdim  // The objects created and saved by LLVMCreateDisasm() then used by
53221337Sdim  // LLVMDisasmInstruction().
54221337Sdim  //
55221337Sdim  // The LLVM target corresponding to the disassembler.
56221337Sdim  // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
57221337Sdim  //        when this LLVMDisasmContext is deleted.
58221337Sdim  const Target *TheTarget;
59221337Sdim  // The assembly information for the target architecture.
60221337Sdim  llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
61221337Sdim  // The target machine instance.
62221337Sdim  llvm::OwningPtr<llvm::TargetMachine> TM;
63221337Sdim  // The disassembler for the target architecture.
64221337Sdim  // FIXME: using llvm::OwningPtr<const llvm::TargetAsmInfo> causes a malloc
65221337Sdim  //        error when this LLVMDisasmContext is deleted.
66221337Sdim  const TargetAsmInfo *Tai;
67221337Sdim  // The assembly context for creating symbols and MCExprs.
68221337Sdim  llvm::OwningPtr<const llvm::MCContext> Ctx;
69221337Sdim  // The disassembler for the target architecture.
70221337Sdim  llvm::OwningPtr<const llvm::MCDisassembler> DisAsm;
71221337Sdim  // The instruction printer for the target architecture.
72221337Sdim  llvm::OwningPtr<llvm::MCInstPrinter> IP;
73221337Sdim
74221337Sdimpublic:
75221337Sdim  LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
76221337Sdim                    LLVMOpInfoCallback getOpInfo,
77221337Sdim                    LLVMSymbolLookupCallback symbolLookUp,
78221337Sdim                    const Target *theTarget, const MCAsmInfo *mAI,
79221337Sdim                    llvm::TargetMachine *tM, const TargetAsmInfo *tai,
80221337Sdim                    llvm::MCContext *ctx, const MCDisassembler *disAsm,
81221337Sdim                    MCInstPrinter *iP) : TripleName(tripleName),
82221337Sdim                    DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
83221337Sdim                    SymbolLookUp(symbolLookUp), TheTarget(theTarget), Tai(tai) {
84221337Sdim    TM.reset(tM);
85221337Sdim    MAI.reset(mAI);
86221337Sdim    Ctx.reset(ctx);
87221337Sdim    DisAsm.reset(disAsm);
88221337Sdim    IP.reset(iP);
89221337Sdim  }
90221337Sdim  const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
91221337Sdim  MCInstPrinter *getIP() { return IP.get(); }
92221337Sdim};
93221337Sdim
94221337Sdim} // namespace llvm
95221337Sdim
96221337Sdim#endif
97