LLVM  10.0.0svn
Disassembler.h
Go to the documentation of this file.
1 //===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the interface for the Disassembly library's disassembler
10 // context. The disassembler is responsible for producing strings for
11 // individual instructions according to a given architecture and disassembly
12 // syntax.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
17 #define LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
18 
19 #include "llvm-c/Disassembler.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCInstPrinter.h"
25 #include "llvm/MC/MCInstrInfo.h"
26 #include "llvm/MC/MCRegisterInfo.h"
29 #include <string>
30 #include <utility>
31 
32 namespace llvm {
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,
89  std::unique_ptr<const MCAsmInfo> &&MAI,
90  std::unique_ptr<const MCRegisterInfo> &&MRI,
91  std::unique_ptr<const MCSubtargetInfo> &&MSI,
92  std::unique_ptr<const MCInstrInfo> &&MII,
93  std::unique_ptr<const llvm::MCContext> &&Ctx,
94  std::unique_ptr<const MCDisassembler> &&DisAsm,
95  std::unique_ptr<MCInstPrinter> &&IP)
96  : TripleName(std::move(TripleName)), DisInfo(DisInfo), TagType(TagType),
97  GetOpInfo(GetOpInfo), SymbolLookUp(SymbolLookUp), TheTarget(TheTarget),
98  MAI(std::move(MAI)), MRI(std::move(MRI)), MSI(std::move(MSI)),
99  MII(std::move(MII)), Ctx(std::move(Ctx)), DisAsm(std::move(DisAsm)),
100  IP(std::move(IP)), Options(0), CommentStream(CommentsToEmit) {}
101  const std::string &getTripleName() const { return TripleName; }
102  void *getDisInfo() const { return DisInfo; }
103  int getTagType() const { return TagType; }
104  LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }
106  return SymbolLookUp;
107  }
108  const Target *getTarget() const { return TheTarget; }
109  const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
110  const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
111  const MCInstrInfo *getInstrInfo() const { return MII.get(); }
112  const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); }
113  const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); }
114  MCInstPrinter *getIP() { return IP.get(); }
115  void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); }
116  uint64_t getOptions() const { return Options; }
117  void addOptions(uint64_t Options) { this->Options |= Options; }
118  StringRef getCPU() const { return CPU; }
119  void setCPU(const char *CPU) { this->CPU = CPU; }
120 };
121 
122 } // namespace llvm
123 
124 #endif
void setIP(MCInstPrinter *NewIP)
Definition: Disassembler.h:115
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Superclass for all disassemblers.
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:530
LLVMSymbolLookupCallback getSymbolLookupCallback() const
Definition: Disassembler.h:105
LLVMOpInfoCallback getGetOpInfo() const
Definition: Disassembler.h:104
Definition: BitVector.h:937
void * getDisInfo() const
Definition: Disassembler.h:102
MCInstPrinter * getIP()
Definition: Disassembler.h:114
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.
const MCRegisterInfo * getRegisterInfo() const
Definition: Disassembler.h:112
raw_svector_ostream CommentStream
Definition: Disassembler.h:83
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:23
const MCSubtargetInfo * getSubtargetInfo() const
Definition: Disassembler.h:113
const MCInstrInfo * getInstrInfo() const
Definition: Disassembler.h:111
const MCAsmInfo * getAsmInfo() const
Definition: Disassembler.h:110
const Target * getTarget() const
Definition: Disassembler.h:108
Target - Wrapper for Target specific information.
StringRef getCPU() const
Definition: Disassembler.h:118
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:39
uint64_t getOptions() const
Definition: Disassembler.h:116
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:44
Generic base class for all target subtargets.
const MCRegisterDesc & get(MCRegister RegNo) const
Provide a get method, equivalent to [], but more useful with a pointer to this object.
void addOptions(uint64_t Options)
Definition: Disassembler.h:117
void setCPU(const char *CPU)
Definition: Disassembler.h:119
const std::string & getTripleName() const
Definition: Disassembler.h:101
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
LLVMDisasmContext(std::string TripleName, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, const Target *TheTarget, std::unique_ptr< const MCAsmInfo > &&MAI, std::unique_ptr< const MCRegisterInfo > &&MRI, std::unique_ptr< const MCSubtargetInfo > &&MSI, std::unique_ptr< const MCInstrInfo > &&MII, std::unique_ptr< const llvm::MCContext > &&Ctx, std::unique_ptr< const MCDisassembler > &&DisAsm, std::unique_ptr< MCInstPrinter > &&IP)
Definition: Disassembler.h:85
const MCDisassembler * getDisAsm() const
Definition: Disassembler.h:109
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
SmallString< 128 > CommentsToEmit
Definition: Disassembler.h:82