LLVM  15.0.0git
MCDisassembler.cpp
Go to the documentation of this file.
1 //===- MCDisassembler.cpp - Disassembler interface ------------------------===//
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 
10 #include "llvm/ADT/ArrayRef.h"
11 
12 using namespace llvm;
13 
15 
18  ArrayRef<uint8_t> Bytes, uint64_t Address,
19  raw_ostream &CStream) const {
20  return None;
21 }
22 
24  uint64_t Address, bool IsBranch,
25  uint64_t Offset,
26  uint64_t InstSize) const {
27  if (Symbolizer)
28  return Symbolizer->tryAddingSymbolicOperand(
29  Inst, *CommentStream, Value, Address, IsBranch, Offset, InstSize);
30  return false;
31 }
32 
34  uint64_t Address) const {
35  if (Symbolizer)
36  Symbolizer->tryAddingPcLoadReferenceComment(*CommentStream, Value, Address);
37 }
38 
39 void MCDisassembler::setSymbolizer(std::unique_ptr<MCSymbolizer> Symzer) {
40  Symbolizer = std::move(Symzer);
41 }
42 
43 #define SMC_PCASE(A, P) \
44  case XCOFF::XMC_##A: \
45  return P;
46 
48  switch (SMC) {
49  SMC_PCASE(PR, 1)
50  SMC_PCASE(RO, 1)
51  SMC_PCASE(DB, 1)
52  SMC_PCASE(GL, 1)
53  SMC_PCASE(XO, 1)
54  SMC_PCASE(SV, 1)
55  SMC_PCASE(SV64, 1)
56  SMC_PCASE(SV3264, 1)
57  SMC_PCASE(TI, 1)
58  SMC_PCASE(TB, 1)
59  SMC_PCASE(RW, 1)
60  SMC_PCASE(TC0, 0)
61  SMC_PCASE(TC, 1)
62  SMC_PCASE(TD, 1)
63  SMC_PCASE(DS, 1)
64  SMC_PCASE(UA, 1)
65  SMC_PCASE(BS, 1)
66  SMC_PCASE(UC, 1)
67  SMC_PCASE(TL, 1)
68  SMC_PCASE(UL, 1)
69  SMC_PCASE(TE, 1)
70 #undef SMC_PCASE
71  }
72  return 0;
73 }
74 
75 /// The function is for symbol sorting when symbols have the same address.
76 /// The symbols in the same section are sorted in ascending order.
77 /// llvm-objdump -D will choose the highest priority symbol to display when
78 /// there are symbols with the same address.
80  // Label symbols have higher priority than non-label symbols.
81  if (IsLabel != SymInfo.IsLabel)
82  return SymInfo.IsLabel;
83 
84  // Symbols with a StorageMappingClass have higher priority than those without.
85  if (StorageMappingClass.hasValue() != SymInfo.StorageMappingClass.hasValue())
86  return SymInfo.StorageMappingClass.hasValue();
87 
88  if (StorageMappingClass.hasValue()) {
89  return getSMCPriority(StorageMappingClass.getValue()) <
90  getSMCPriority(SymInfo.StorageMappingClass.getValue());
91  }
92 
93  return false;
94 }
llvm::XCOFFSymbolInfo
Definition: MCDisassembler.h:22
getSMCPriority
static uint8_t getSMCPriority(XCOFF::StorageMappingClass SMC)
Definition: MCDisassembler.cpp:47
llvm::XCOFFSymbolInfo::operator<
bool operator<(const XCOFFSymbolInfo &SymInfo) const
The function is for symbol sorting when symbols have the same address.
Definition: MCDisassembler.cpp:79
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
MCDisassembler.h
llvm::SymbolInfoTy
Definition: MCDisassembler.h:33
llvm::MCDisassembler::onSymbolStart
virtual Optional< DecodeStatus > onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const
Used to perform separate target specific disassembly for a particular symbol.
Definition: MCDisassembler.cpp:17
llvm::Optional
Definition: APInt.h:33
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::X86II::TB
@ TB
Definition: X86BaseInfo.h:805
llvm::MCDisassembler::CommentStream
raw_ostream * CommentStream
Definition: MCDisassembler.h:201
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::MCDisassembler::setSymbolizer
void setSymbolizer(std::unique_ptr< MCSymbolizer > Symzer)
Set Symzer as the current symbolizer.
Definition: MCDisassembler.cpp:39
llvm::None
const NoneType None
Definition: None.h:24
llvm::XCOFF::StorageMappingClass
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:87
uint64_t
llvm::MCDisassembler::~MCDisassembler
virtual ~MCDisassembler()
llvm::MCDisassembler::tryAddingPcLoadReferenceComment
void tryAddingPcLoadReferenceComment(int64_t Value, uint64_t Address) const
Definition: MCDisassembler.cpp:33
llvm::SIInstrFlags::DS
@ DS
Definition: SIDefines.h:60
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
ArrayRef.h
llvm::MCDisassembler::tryAddingSymbolicOperand
bool tryAddingSymbolicOperand(MCInst &Inst, int64_t Value, uint64_t Address, bool IsBranch, uint64_t Offset, uint64_t InstSize) const
Definition: MCDisassembler.cpp:23
llvm::ArrayRef< uint8_t >
SMC_PCASE
#define SMC_PCASE(A, P)
Definition: MCDisassembler.cpp:43
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
llvm::XCOFFSymbolInfo::IsLabel
bool IsLabel
Definition: MCDisassembler.h:25
SymInfo
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
Definition: DWARFContext.cpp:1467
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCDisassembler::Symbolizer
std::unique_ptr< MCSymbolizer > Symbolizer
Definition: MCDisassembler.h:180