blob: 8740c5c893516c1bb9e084f44122f4751f07ed51 [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;
Evan Cheng0e6a0522011-07-18 20:57:22 +000030class MCRegisterInfo;
Kevin Enderby93f79362011-03-28 18:25:07 +000031class Target;
32class TargetMachine;
33
34//
35// This is the disassembler context returned by LLVMCreateDisasm().
36//
37class LLVMDisasmContext {
38private:
39 //
40 // The passed parameters when the disassembler context is created.
41 //
42 // The TripleName for this disassembler.
43 std::string TripleName;
44 // The pointer to the caller's block of symbolic information.
45 void *DisInfo;
46 // The Triple specific symbolic information type returned by GetOpInfo.
47 int TagType;
48 // The function to get the symbolic information for operands.
49 LLVMOpInfoCallback GetOpInfo;
50 // The function to look up a symbol name.
51 LLVMSymbolLookupCallback SymbolLookUp;
52 //
53 // The objects created and saved by LLVMCreateDisasm() then used by
54 // LLVMDisasmInstruction().
55 //
56 // The LLVM target corresponding to the disassembler.
57 // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
58 // when this LLVMDisasmContext is deleted.
59 const Target *TheTarget;
60 // The assembly information for the target architecture.
61 llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
Evan Cheng0e6a0522011-07-18 20:57:22 +000062 // The register information for the target architecture.
63 llvm::OwningPtr<const llvm::MCRegisterInfo> MRI;
Kevin Enderby93f79362011-03-28 18:25:07 +000064 // The target machine instance.
65 llvm::OwningPtr<llvm::TargetMachine> TM;
66 // The disassembler for the target architecture.
67 // FIXME: using llvm::OwningPtr<const llvm::TargetAsmInfo> causes a malloc
68 // error when this LLVMDisasmContext is deleted.
69 const TargetAsmInfo *Tai;
70 // The assembly context for creating symbols and MCExprs.
71 llvm::OwningPtr<const llvm::MCContext> Ctx;
72 // The disassembler for the target architecture.
73 llvm::OwningPtr<const llvm::MCDisassembler> DisAsm;
74 // The instruction printer for the target architecture.
75 llvm::OwningPtr<llvm::MCInstPrinter> IP;
76
77public:
78 LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
Kevin Enderbybd332762011-04-11 18:08:50 +000079 LLVMOpInfoCallback getOpInfo,
Kevin Enderby93f79362011-03-28 18:25:07 +000080 LLVMSymbolLookupCallback symbolLookUp,
81 const Target *theTarget, const MCAsmInfo *mAI,
Evan Cheng0e6a0522011-07-18 20:57:22 +000082 const MCRegisterInfo *mRI,
Kevin Enderby93f79362011-03-28 18:25:07 +000083 llvm::TargetMachine *tM, const TargetAsmInfo *tai,
84 llvm::MCContext *ctx, const MCDisassembler *disAsm,
85 MCInstPrinter *iP) : TripleName(tripleName),
86 DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
87 SymbolLookUp(symbolLookUp), TheTarget(theTarget), Tai(tai) {
88 TM.reset(tM);
89 MAI.reset(mAI);
Evan Cheng0e6a0522011-07-18 20:57:22 +000090 MRI.reset(mRI);
Kevin Enderby93f79362011-03-28 18:25:07 +000091 Ctx.reset(ctx);
92 DisAsm.reset(disAsm);
93 IP.reset(iP);
94 }
95 const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
96 MCInstPrinter *getIP() { return IP.get(); }
97};
98
99} // namespace llvm
Sebastian Redl69ffd7a2011-04-24 15:46:56 +0000100
101#endif