]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MC/MCDisassembler/Disassembler.h
Merge llvm trunk r338150 (just before the 7.0.0 branch point), and
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / MC / MCDisassembler / Disassembler.h
1 //===------------- 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 //===----------------------------------------------------------------------===//
16
17 #ifndef LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
18 #define LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
19
20 #include "llvm-c/Disassembler.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
25 #include "llvm/MC/MCInstPrinter.h"
26 #include "llvm/MC/MCInstrInfo.h"
27 #include "llvm/MC/MCRegisterInfo.h"
28 #include "llvm/MC/MCSubtargetInfo.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include <string>
31 #include <utility>
32
33 namespace llvm {
34 class Target;
35
36 //
37 // This is the disassembler context returned by LLVMCreateDisasm().
38 //
39 class LLVMDisasmContext {
40 private:
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 std::unique_ptr<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   std::unique_ptr<const llvm::MCAsmInfo> MAI;
64   // The register information for the target architecture.
65   std::unique_ptr<const llvm::MCRegisterInfo> MRI;
66   // The subtarget information for the target architecture.
67   std::unique_ptr<const llvm::MCSubtargetInfo> MSI;
68   // The instruction information for the target architecture.
69   std::unique_ptr<const llvm::MCInstrInfo> MII;
70   // The assembly context for creating symbols and MCExprs.
71   std::unique_ptr<const llvm::MCContext> Ctx;
72   // The disassembler for the target architecture.
73   std::unique_ptr<const llvm::MCDisassembler> DisAsm;
74   // The instruction printer for the target architecture.
75   std::unique_ptr<llvm::MCInstPrinter> IP;
76   // The options used to set up the disassembler.
77   uint64_t Options;
78   // The CPU string.
79   std::string CPU;
80
81 public:
82   // Comment stream and backing vector.
83   SmallString<128> CommentsToEmit;
84   raw_svector_ostream CommentStream;
85
86   LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
87                     LLVMOpInfoCallback getOpInfo,
88                     LLVMSymbolLookupCallback symbolLookUp,
89                     const Target *theTarget, const MCAsmInfo *mAI,
90                     const MCRegisterInfo *mRI, const MCSubtargetInfo *mSI,
91                     const MCInstrInfo *mII, llvm::MCContext *ctx,
92                     const MCDisassembler *disAsm, MCInstPrinter *iP)
93       : TripleName(std::move(tripleName)), DisInfo(disInfo), TagType(tagType),
94         GetOpInfo(getOpInfo), SymbolLookUp(symbolLookUp), TheTarget(theTarget),
95         Options(0), CommentStream(CommentsToEmit) {
96     MAI.reset(mAI);
97     MRI.reset(mRI);
98     MSI.reset(mSI);
99     MII.reset(mII);
100     Ctx.reset(ctx);
101     DisAsm.reset(disAsm);
102     IP.reset(iP);
103   }
104   const std::string &getTripleName() const { return TripleName; }
105   void *getDisInfo() const { return DisInfo; }
106   int getTagType() const { return TagType; }
107   LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }
108   LLVMSymbolLookupCallback getSymbolLookupCallback() const {
109     return SymbolLookUp;
110   }
111   const Target *getTarget() const { return TheTarget; }
112   const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
113   const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
114   const MCInstrInfo *getInstrInfo() const { return MII.get(); }
115   const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); }
116   const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); }
117   MCInstPrinter *getIP() { return IP.get(); }
118   void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); }
119   uint64_t getOptions() const { return Options; }
120   void addOptions(uint64_t Options) { this->Options |= Options; }
121   StringRef getCPU() const { return CPU; }
122   void setCPU(const char *CPU) { this->CPU = CPU; }
123 };
124
125 } // namespace llvm
126
127 #endif