LLVM  6.0.0svn
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"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/MC/MCContext.h"
25 #include "llvm/MC/MCInstPrinter.h"
26 #include "llvm/MC/MCInstrInfo.h"
27 #include "llvm/MC/MCRegisterInfo.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 //
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.
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; }
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
void setIP(MCInstPrinter *NewIP)
Definition: Disassembler.h:118
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Superclass for all disassemblers.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:490
LLVMSymbolLookupCallback getSymbolLookupCallback() const
Definition: Disassembler.h:108
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.
Definition: Disassembler.h:54
LLVMOpInfoCallback getGetOpInfo() const
Definition: Disassembler.h:107
Definition: BitVector.h:920
void * getDisInfo() const
Definition: Disassembler.h:105
MCInstPrinter * getIP()
Definition: Disassembler.h:117
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)
Definition: Disassembler.h:86
const MCRegisterInfo * getRegisterInfo() const
Definition: Disassembler.h:115
Context object for machine code objects.
Definition: MCContext.h:59
raw_svector_ostream CommentStream
Definition: Disassembler.h:84
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:56
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:24
const MCSubtargetInfo * getSubtargetInfo() const
Definition: Disassembler.h:116
const MCInstrInfo * getInstrInfo() const
Definition: Disassembler.h:114
const MCRegisterDesc & get(unsigned RegNo) const
Provide a get method, equivalent to [], but more useful with a pointer to this object.
static const char * Target
const MCAsmInfo * getAsmInfo() const
Definition: Disassembler.h:113
const Target * getTarget() const
Definition: Disassembler.h:111
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
Definition: Disassembler.h:124
Target - Wrapper for Target specific information.
StringRef getCPU() const
Definition: Disassembler.h:121
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:41
uint64_t getOptions() const
Definition: Disassembler.h:119
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:45
MCSubtargetInfo - Generic base class for all target subtargets.
void addOptions(uint64_t Options)
Definition: Disassembler.h:120
void setCPU(const char *CPU)
Definition: Disassembler.h:122
const std::string & getTripleName() const
Definition: Disassembler.h:104
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
const MCDisassembler * getDisAsm() const
Definition: Disassembler.h:112
SmallString< 128 > CommentsToEmit
Definition: Disassembler.h:83