blob: f0ec42a017a43c82a164a9ddb39b6f142ea399f6 [file] [log] [blame]
Kevin Enderby93f79362011-03-28 18:25:07 +00001//===------------- 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 Redl69ffd7a2011-04-24 15:46:56 +000016
17#ifndef LLVM_MC_DISASSEMBLER_H
18#define LLVM_MC_DISASSEMBLER_H
19
Kevin Enderby93f79362011-03-28 18:25:07 +000020#include "llvm-c/Disassembler.h"
21#include <string>
22#include "llvm/ADT/OwningPtr.h"
23
24namespace llvm {
25class TargetAsmInfo;
26class MCContext;
27class MCAsmInfo;
28class MCDisassembler;
29class MCInstPrinter;
30class Target;
31class TargetMachine;
32
33//
34// This is the disassembler context returned by LLVMCreateDisasm().
35//
36class LLVMDisasmContext {
37private:
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
74public:
75 LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
Kevin Enderbybd332762011-04-11 18:08:50 +000076 LLVMOpInfoCallback getOpInfo,
Kevin Enderby93f79362011-03-28 18:25:07 +000077 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 Redl69ffd7a2011-04-24 15:46:56 +000095
96#endif