blob: 5a5abd28f0fee97356cbfccac5fcddcbfcacb1d9 [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 {
Kevin Enderby93f79362011-03-28 18:25:07 +000025class MCContext;
26class MCAsmInfo;
27class MCDisassembler;
28class MCInstPrinter;
Evan Cheng0e6a0522011-07-18 20:57:22 +000029class MCRegisterInfo;
Kevin Enderby93f79362011-03-28 18:25:07 +000030class Target;
Kevin Enderby93f79362011-03-28 18:25:07 +000031
32//
33// This is the disassembler context returned by LLVMCreateDisasm().
34//
35class LLVMDisasmContext {
36private:
37 //
38 // The passed parameters when the disassembler context is created.
39 //
40 // The TripleName for this disassembler.
41 std::string TripleName;
42 // The pointer to the caller's block of symbolic information.
43 void *DisInfo;
44 // The Triple specific symbolic information type returned by GetOpInfo.
45 int TagType;
46 // The function to get the symbolic information for operands.
47 LLVMOpInfoCallback GetOpInfo;
48 // The function to look up a symbol name.
49 LLVMSymbolLookupCallback SymbolLookUp;
50 //
51 // The objects created and saved by LLVMCreateDisasm() then used by
52 // LLVMDisasmInstruction().
53 //
54 // The LLVM target corresponding to the disassembler.
55 // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
56 // when this LLVMDisasmContext is deleted.
57 const Target *TheTarget;
58 // The assembly information for the target architecture.
59 llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
Evan Cheng0e6a0522011-07-18 20:57:22 +000060 // The register information for the target architecture.
61 llvm::OwningPtr<const llvm::MCRegisterInfo> MRI;
Kevin Enderby93f79362011-03-28 18:25:07 +000062 // The assembly context for creating symbols and MCExprs.
63 llvm::OwningPtr<const llvm::MCContext> Ctx;
64 // The disassembler for the target architecture.
65 llvm::OwningPtr<const llvm::MCDisassembler> DisAsm;
66 // The instruction printer for the target architecture.
67 llvm::OwningPtr<llvm::MCInstPrinter> IP;
68
69public:
70 LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
Kevin Enderbybd332762011-04-11 18:08:50 +000071 LLVMOpInfoCallback getOpInfo,
Kevin Enderby93f79362011-03-28 18:25:07 +000072 LLVMSymbolLookupCallback symbolLookUp,
73 const Target *theTarget, const MCAsmInfo *mAI,
Evan Cheng0e6a0522011-07-18 20:57:22 +000074 const MCRegisterInfo *mRI,
Kevin Enderby93f79362011-03-28 18:25:07 +000075 llvm::MCContext *ctx, const MCDisassembler *disAsm,
76 MCInstPrinter *iP) : TripleName(tripleName),
77 DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
Evan Cheng203576a2011-07-20 19:50:42 +000078 SymbolLookUp(symbolLookUp), TheTarget(theTarget) {
Kevin Enderby93f79362011-03-28 18:25:07 +000079 MAI.reset(mAI);
Evan Cheng0e6a0522011-07-18 20:57:22 +000080 MRI.reset(mRI);
Kevin Enderby93f79362011-03-28 18:25:07 +000081 Ctx.reset(ctx);
82 DisAsm.reset(disAsm);
83 IP.reset(iP);
84 }
85 const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
86 MCInstPrinter *getIP() { return IP.get(); }
87};
88
89} // namespace llvm
Sebastian Redl69ffd7a2011-04-24 15:46:56 +000090
91#endif