blob: 322abd5d637a95dfc4647f02f45befd37b82b4b6 [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"
Owen Anderson8f29e692011-09-15 18:37:20 +000023#include "llvm/ADT/SmallString.h"
24#include "llvm/Support/raw_ostream.h"
Kevin Enderby93f79362011-03-28 18:25:07 +000025
26namespace llvm {
Kevin Enderby93f79362011-03-28 18:25:07 +000027class MCContext;
28class MCAsmInfo;
29class MCDisassembler;
30class MCInstPrinter;
Sean Callanan55e79802012-04-06 18:21:09 +000031class MCInstrInfo;
Evan Cheng0e6a0522011-07-18 20:57:22 +000032class MCRegisterInfo;
Sean Callanan55e79802012-04-06 18:21:09 +000033class MCSubtargetInfo;
Kevin Enderby93f79362011-03-28 18:25:07 +000034class Target;
Kevin Enderby93f79362011-03-28 18:25:07 +000035
36//
37// This is the disassembler context returned by LLVMCreateDisasm().
38//
39class LLVMDisasmContext {
40private:
41 //
42 // The passed parameters when the disassembler context is created.
43 //
44 // The TripleName for this disassembler.
45 std::string TripleName;
46 // The pointer to the caller's block of symbolic information.
47 void *DisInfo;
48 // The Triple specific symbolic information type returned by GetOpInfo.
49 int TagType;
50 // The function to get the symbolic information for operands.
51 LLVMOpInfoCallback GetOpInfo;
52 // The function to look up a symbol name.
53 LLVMSymbolLookupCallback SymbolLookUp;
54 //
55 // The objects created and saved by LLVMCreateDisasm() then used by
56 // LLVMDisasmInstruction().
57 //
58 // The LLVM target corresponding to the disassembler.
59 // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
60 // when this LLVMDisasmContext is deleted.
61 const Target *TheTarget;
62 // The assembly information for the target architecture.
63 llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
Evan Cheng0e6a0522011-07-18 20:57:22 +000064 // The register information for the target architecture.
65 llvm::OwningPtr<const llvm::MCRegisterInfo> MRI;
Sean Callanan55e79802012-04-06 18:21:09 +000066 // The subtarget information for the target architecture.
67 llvm::OwningPtr<const llvm::MCSubtargetInfo> MSI;
68 // The instruction information for the target architecture.
69 llvm::OwningPtr<const llvm::MCInstrInfo> MII;
Kevin Enderby93f79362011-03-28 18:25:07 +000070 // 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:
Owen Anderson8f29e692011-09-15 18:37:20 +000078 // Comment stream and backing vector.
79 SmallString<128> CommentsToEmit;
80 raw_svector_ostream CommentStream;
81
Kevin Enderby93f79362011-03-28 18:25:07 +000082 LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
Kevin Enderbybd332762011-04-11 18:08:50 +000083 LLVMOpInfoCallback getOpInfo,
Kevin Enderby93f79362011-03-28 18:25:07 +000084 LLVMSymbolLookupCallback symbolLookUp,
85 const Target *theTarget, const MCAsmInfo *mAI,
Evan Cheng0e6a0522011-07-18 20:57:22 +000086 const MCRegisterInfo *mRI,
Sean Callanan55e79802012-04-06 18:21:09 +000087 const MCSubtargetInfo *mSI,
88 const MCInstrInfo *mII,
Kevin Enderby93f79362011-03-28 18:25:07 +000089 llvm::MCContext *ctx, const MCDisassembler *disAsm,
90 MCInstPrinter *iP) : TripleName(tripleName),
91 DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
Owen Anderson8f29e692011-09-15 18:37:20 +000092 SymbolLookUp(symbolLookUp), TheTarget(theTarget),
93 CommentStream(CommentsToEmit) {
Kevin Enderby93f79362011-03-28 18:25:07 +000094 MAI.reset(mAI);
Evan Cheng0e6a0522011-07-18 20:57:22 +000095 MRI.reset(mRI);
Sean Callanan55e79802012-04-06 18:21:09 +000096 MSI.reset(mSI);
97 MII.reset(mII);
Kevin Enderby93f79362011-03-28 18:25:07 +000098 Ctx.reset(ctx);
99 DisAsm.reset(disAsm);
100 IP.reset(iP);
101 }
Benjamin Kramer8e5271d2012-06-06 20:45:10 +0000102 const std::string &getTripleName() const { return TripleName; }
103 void *getDisInfo() const { return DisInfo; }
104 int getTagType() const { return TagType; }
105 LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }
106 LLVMSymbolLookupCallback getSymbolLookupCallback() const {
107 return SymbolLookUp;
108 }
109 const Target *getTarget() const { return TheTarget; }
Kevin Enderby93f79362011-03-28 18:25:07 +0000110 const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
Owen Anderson8f29e692011-09-15 18:37:20 +0000111 const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
Kevin Enderby93f79362011-03-28 18:25:07 +0000112 MCInstPrinter *getIP() { return IP.get(); }
113};
114
115} // namespace llvm
Sebastian Redl69ffd7a2011-04-24 15:46:56 +0000116
117#endif