LLVM: lib/MC/MCDisassembler/Disassembler.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

31#include

32#include

33

34using namespace llvm;

35

36

37

38

39

40

41

42

45 const char *Features, void *DisInfo, int TagType,

48

49 std::string Error;

51 if (!TheTarget)

52 return nullptr;

53

54 std::unique_ptr MRI(TheTarget->createMCRegInfo(TT));

56 return nullptr;

57

59

60 std::unique_ptr MAI(

62 if (!MAI)

63 return nullptr;

64

65 std::unique_ptr MII(TheTarget->createMCInstrInfo());

66 if (!MII)

67 return nullptr;

68

69 std::unique_ptr STI(

71 if (!STI)

72 return nullptr;

73

74

75 std::unique_ptr Ctx(

77 if (!Ctx)

78 return nullptr;

79

80

81 std::unique_ptr DisAsm(

83 if (!DisAsm)

84 return nullptr;

85

86 std::unique_ptr RelInfo(

88 if (!RelInfo)

89 return nullptr;

90

91 std::unique_ptr Symbolizer(TheTarget->createMCSymbolizer(

92 TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx.get(), std::move(RelInfo)));

93 DisAsm->setSymbolizer(std::move(Symbolizer));

94

95

96 int AsmPrinterVariant = MAI->getAssemblerDialect();

98 Triple(TT), AsmPrinterVariant, *MAI, *MII, *MRI));

99 if (!IP)

100 return nullptr;

101

103 TT, DisInfo, TagType, GetOpInfo, SymbolLookUp, TheTarget, std::move(MAI),

104 std::move(MRI), std::move(STI), std::move(MII), std::move(Ctx),

105 std::move(DisAsm), std::move(IP));

106 if (!DC)

107 return nullptr;

108

110 return DC;

111}

112

118 SymbolLookUp);

119}

120

125 SymbolLookUp);

126}

127

128

129

130

133 delete DC;

134}

135

136

137

140

142

146 bool IsFirst = true;

147 while (!Comments.empty()) {

148 if (!IsFirst)

149 FormattedOS << '\n';

150

152 size_t Position = Comments.find('\n');

153 FormattedOS << CommentBegin << ' ' << Comments.substr(0, Position);

154

155 Comments = Comments.substr(Position+1);

156 IsFirst = false;

157 }

158 FormattedOS.flush();

159

160

162}

163

164

165

171

172

174 return;

175

177}

178

179

180

181

182

183

184

185

186

187

188

189

190

193 size_t OutStringSize){

195

197

206 switch (S) {

209

210 return 0;

211

214

218

222 }

223

225 FormattedOS);

226

229

231

232 assert(OutStringSize != 0 && "Output buffer cannot be zero size");

233 size_t OutputSize = std::min(OutStringSize-1, InsnStr.size());

234 std::memcpy(OutString, InsnStr.data(), OutputSize);

235 OutString[OutputSize] = '\0';

236

238 }

239 }

241}

242

243

244

245

246

253 Options &= ~LLVMDisassembler_Option_UseMarkup;

254 }

260 Options &= ~LLVMDisassembler_Option_PrintImmHex;

261 }

264

269 AsmPrinterVariant = AsmPrinterVariant == 0 ? 1 : 0;

272 if (IP) {

275 Options &= ~LLVMDisassembler_Option_AsmPrinterVariant;

276 }

277 }

283 Options &= ~LLVMDisassembler_Option_SetInstrComments;

284 }

288 Options &= ~LLVMDisassembler_Option_PrintLatency;

289 }

293 Options &= ~LLVMDisassembler_Option_Color;

294 }

296}

unsigned const MachineRegisterInfo * MRI

static void emitComments(LLVMDisasmContext *DC, formatted_raw_ostream &FormattedOS)

Emits the comments that are stored in DC comment stream.

static void emitLatency(LLVMDisasmContext *DC, const MCInst &Inst)

Emits latency information in DC->CommentStream for Inst, based on the information available in DC.

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

This file defines the SmallVector class.

Annotations lets you mark points and ranges inside source code, for tests:

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

Lightweight error class with error context and mandatory checking.

const MCDisassembler * getDisAsm() const

void setCPU(const char *CPU)

void addOptions(uint64_t Options)

raw_svector_ostream CommentStream

void setIP(MCInstPrinter *NewIP)

const MCSubtargetInfo * getSubtargetInfo() const

const MCAsmInfo * getAsmInfo() const

uint64_t getOptions() const

const MCRegisterInfo * getRegisterInfo() const

SmallString< 128 > CommentsToEmit

const MCInstrInfo * getInstrInfo() const

const Target * getTarget() const

const std::string & getTripleName() const

This class is intended to be used as a base class for asm properties and features specific to the tar...

unsigned getAssemblerDialect() const

StringRef getCommentString() const

unsigned getCommentColumn() const

Context object for machine code objects.

Superclass for all disassemblers.

DecodeStatus

Ternary decode status.

virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const =0

Returns the disassembly of a single instruction.

This is an instance of a target assembly language printer that converts an MCInst to valid target ass...

void setCommentStream(raw_ostream &OS)

Specify a stream to emit comments to.

void setUseColor(bool Value)

void setPrintImmHex(bool Value)

void setUseMarkup(bool Value)

virtual void printInst(const MCInst *MI, uint64_t Address, StringRef Annot, const MCSubtargetInfo &STI, raw_ostream &OS)=0

Print the specified MCInst to the specified raw_ostream.

Instances of this class represent a single low-level machine instruction.

Interface to description of machine instruction set.

MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...

Generic base class for all target subtargets.

const MCSchedModel & getSchedModel() const

Get the machine model for this subtarget's CPU.

StringRef str() const

Explicit conversion to StringRef.

pointer data()

Return a pointer to the vector's buffer, even if empty().

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

constexpr StringRef substr(size_t Start, size_t N=npos) const

Return a reference to the substring from [Start, Start + N).

constexpr bool empty() const

empty - Check if the string is empty.

size_t find(char C, size_t From=0) const

Search for the first character C in the string.

Target - Wrapper for Target specific information.

MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const

createMCSubtargetInfo - Create a MCSubtargetInfo implementation.

MCSymbolizer * createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) const

createMCSymbolizer - Create a target specific MCSymbolizer.

MCRelocationInfo * createMCRelocationInfo(StringRef TT, MCContext &Ctx) const

createMCRelocationInfo - Create a target specific MCRelocationInfo.

MCRegisterInfo * createMCRegInfo(StringRef TT) const

createMCRegInfo - Create a MCRegisterInfo implementation.

MCDisassembler * createMCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) const

MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple, const MCTargetOptions &Options) const

createMCAsmInfo - Create a MCAsmInfo implementation for the specified target triple.

MCInstPrinter * createMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) const

MCInstrInfo * createMCInstrInfo() const

createMCInstrInfo - Create a MCInstrInfo implementation.

Triple - Helper class for working with autoconf configuration names.

formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...

formatted_raw_ostream & PadToColumn(unsigned NewCol)

PadToColumn - Align the output to some column number.

virtual void enable_colors(bool enable)

A raw_ostream that writes to an SmallVector or SmallString.

const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)

The type for the symbol lookup function.

LLVMDisasmContextRef LLVMCreateDisasmCPUFeatures(const char *TT, const char *CPU, const char *Features, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp)

Create a disassembler for the TripleName, a specific CPU and specific feature string.

void LLVMDisasmDispose(LLVMDisasmContextRef DCR)

Dispose of a disassembler context.

#define LLVMDisassembler_Option_PrintImmHex

#define LLVMDisassembler_Option_UseMarkup

size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, uint64_t BytesSize, uint64_t PC, char *OutString, size_t OutStringSize)

Disassemble a single instruction using the disassembler context specified in the parameter DC.

#define LLVMDisassembler_Option_PrintLatency

#define LLVMDisassembler_Option_SetInstrComments

LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *TT, const char *CPU, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp)

Create a disassembler for the TripleName and a specific CPU.

#define LLVMDisassembler_Option_Color

int(* LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t OpSize, uint64_t InstSize, int TagType, void *TagBuf)

The type for the operand information call back function.

LLVMDisasmContextRef LLVMCreateDisasm(const char *TT, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp)

Create a disassembler for the TripleName.

int LLVMSetDisasmOptions(LLVMDisasmContextRef DCR, uint64_t Options)

Set the disassembler's options.

#define LLVMDisassembler_Option_AsmPrinterVariant

void * LLVMDisasmContextRef

An opaque reference to a disassembler context.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

This is an optimization pass for GlobalISel generic memory operations.

Machine model for scheduling, bundling, and heuristics.

static int computeInstrLatency(const MCSubtargetInfo &STI, const MCSchedClassDesc &SCDesc)

Returns the latency value for the scheduling class.

static const Target * lookupTarget(StringRef Triple, std::string &Error)

lookupTarget - Lookup a target based on a target triple.