LLVM  3.7.0
lib/MC/MCDisassembler/Disassembler.h
Go to the documentation of this file.
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"
23 #include <string>
24 
25 namespace llvm {
26 class MCContext;
27 class MCAsmInfo;
28 class MCDisassembler;
29 class MCInstPrinter;
30 class MCInstrInfo;
31 class MCRegisterInfo;
32 class MCSubtargetInfo;
33 class Target;
34 
35 //
36 // This is the disassembler context returned by LLVMCreateDisasm().
37 //
39 private:
40  //
41  // The passed parameters when the disassembler context is created.
42  //
43  // The TripleName for this disassembler.
44  std::string TripleName;
45  // The pointer to the caller's block of symbolic information.
46  void *DisInfo;
47  // The Triple specific symbolic information type returned by GetOpInfo.
48  int TagType;
49  // The function to get the symbolic information for operands.
50  LLVMOpInfoCallback GetOpInfo;
51  // The function to look up a symbol name.
52  LLVMSymbolLookupCallback SymbolLookUp;
53  //
54  // The objects created and saved by LLVMCreateDisasm() then used by
55  // LLVMDisasmInstruction().
56  //
57  // The LLVM target corresponding to the disassembler.
58  // FIXME: using std::unique_ptr<const llvm::Target> causes a malloc error
59  // when this LLVMDisasmContext is deleted.
60  const Target *TheTarget;
61  // The assembly information for the target architecture.
62  std::unique_ptr<const llvm::MCAsmInfo> MAI;
63  // The register information for the target architecture.
64  std::unique_ptr<const llvm::MCRegisterInfo> MRI;
65  // The subtarget information for the target architecture.
66  std::unique_ptr<const llvm::MCSubtargetInfo> MSI;
67  // The instruction information for the target architecture.
68  std::unique_ptr<const llvm::MCInstrInfo> MII;
69  // The assembly context for creating symbols and MCExprs.
70  std::unique_ptr<const llvm::MCContext> Ctx;
71  // The disassembler for the target architecture.
72  std::unique_ptr<const llvm::MCDisassembler> DisAsm;
73  // The instruction printer for the target architecture.
74  std::unique_ptr<llvm::MCInstPrinter> IP;
75  // The options used to set up the disassembler.
76  uint64_t Options;
77  // The CPU string.
78  std::string CPU;
79 
80 public:
81  // Comment stream and backing vector.
84 
85  LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
86  LLVMOpInfoCallback getOpInfo,
87  LLVMSymbolLookupCallback symbolLookUp,
88  const Target *theTarget, const MCAsmInfo *mAI,
89  const MCRegisterInfo *mRI,
90  const MCSubtargetInfo *mSI,
91  const MCInstrInfo *mII,
92  llvm::MCContext *ctx, const MCDisassembler *disAsm,
93  MCInstPrinter *iP) : TripleName(tripleName),
94  DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
95  SymbolLookUp(symbolLookUp), TheTarget(theTarget),
96  Options(0),
98  MAI.reset(mAI);
99  MRI.reset(mRI);
100  MSI.reset(mSI);
101  MII.reset(mII);
102  Ctx.reset(ctx);
103  DisAsm.reset(disAsm);
104  IP.reset(iP);
105  }
106  const std::string &getTripleName() const { return TripleName; }
107  void *getDisInfo() const { return DisInfo; }
108  int getTagType() const { return TagType; }
109  LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }
111  return SymbolLookUp;
112  }
113  const Target *getTarget() const { return TheTarget; }
114  const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
115  const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
116  const MCInstrInfo *getInstrInfo() const { return MII.get(); }
117  const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); }
118  const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); }
119  MCInstPrinter *getIP() { return IP.get(); }
120  void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); }
121  uint64_t getOptions() const { return Options; }
122  void addOptions(uint64_t Options) { this->Options |= Options; }
123  StringRef getCPU() const { return CPU; }
124  void setCPU(const char *CPU) { this->CPU = CPU; }
125 };
126 
127 } // namespace llvm
128 
129 #endif
const MCRegisterInfo * getRegisterInfo() const
Superclass for all disassemblers.
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
LLVMOpInfoCallback getGetOpInfo() const
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:488
const std::string & getTripleName() const
LLVMSymbolLookupCallback getSymbolLookupCallback() const
const MCDisassembler * getDisAsm() const
const MCSubtargetInfo * getSubtargetInfo() const
LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType, LLVMOpInfoCallback getOpInfo, LLVMSymbolLookupCallback symbolLookUp, const Target *theTarget, const MCAsmInfo *mAI, const MCRegisterInfo *mRI, const MCSubtargetInfo *mSI, const MCInstrInfo *mII, llvm::MCContext *ctx, const MCDisassembler *disAsm, MCInstPrinter *iP)
Context object for machine code objects.
Definition: MCContext.h:48
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
const MCInstrInfo * getInstrInfo() const
Target - Wrapper for Target specific information.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:38
MCSubtargetInfo - Generic base class for all target subtargets.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
int(* LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t Size, int TagType, void *TagBuf)
The type for the operand information call back function.