LLVM 20.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
12using namespace llvm;
13
15
19 uint64_t Address) const {
20 return false;
21}
22
24 uint64_t Address) const {
25 return 1;
26}
27
29 uint64_t Address, bool IsBranch,
30 uint64_t Offset, uint64_t OpSize,
31 uint64_t InstSize) const {
32 if (Symbolizer)
33 return Symbolizer->tryAddingSymbolicOperand(Inst, *CommentStream, Value,
34 Address, IsBranch, Offset,
35 OpSize, InstSize);
36 return false;
37}
38
40 uint64_t Address) const {
41 if (Symbolizer)
42 Symbolizer->tryAddingPcLoadReferenceComment(*CommentStream, Value, Address);
43}
44
45void MCDisassembler::setSymbolizer(std::unique_ptr<MCSymbolizer> Symzer) {
46 Symbolizer = std::move(Symzer);
47}
48
49#define SMC_PCASE(A, P) \
50 case XCOFF::XMC_##A: \
51 return P;
52
54 switch (SMC) {
55 SMC_PCASE(PR, 1)
56 SMC_PCASE(RO, 1)
57 SMC_PCASE(DB, 1)
58 SMC_PCASE(GL, 1)
59 SMC_PCASE(XO, 1)
60 SMC_PCASE(SV, 1)
61 SMC_PCASE(SV64, 1)
62 SMC_PCASE(SV3264, 1)
63 SMC_PCASE(TI, 1)
64 SMC_PCASE(TB, 1)
65 SMC_PCASE(RW, 1)
66 SMC_PCASE(TC0, 0)
67 SMC_PCASE(TC, 1)
68 SMC_PCASE(TD, 1)
69 SMC_PCASE(DS, 1)
70 SMC_PCASE(UA, 1)
71 SMC_PCASE(BS, 1)
72 SMC_PCASE(UC, 1)
73 SMC_PCASE(TL, 1)
74 SMC_PCASE(UL, 1)
75 SMC_PCASE(TE, 1)
76#undef SMC_PCASE
77 }
78 return 0;
79}
80
81/// The function is for symbol sorting when symbols have the same address.
82/// The symbols in the same section are sorted in ascending order.
83/// llvm-objdump -D will choose the highest priority symbol to display when
84/// there are symbols with the same address.
86 // Label symbols have higher priority than non-label symbols.
87 if (IsLabel != SymInfo.IsLabel)
88 return SymInfo.IsLabel;
89
90 // Symbols with a StorageMappingClass have higher priority than those without.
91 if (StorageMappingClass.has_value() !=
92 SymInfo.StorageMappingClass.has_value())
93 return SymInfo.StorageMappingClass.has_value();
94
97 getSMCPriority(*SymInfo.StorageMappingClass);
98 }
99
100 return false;
101}
uint64_t Size
static uint8_t getSMCPriority(XCOFF::StorageMappingClass SMC)
#define SMC_PCASE(A, P)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Tagged union holding either a T or a Error.
Definition: Error.h:481
virtual Expected< bool > onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address) const
Used to perform separate target specific disassembly for a particular symbol.
bool tryAddingSymbolicOperand(MCInst &Inst, int64_t Value, uint64_t Address, bool IsBranch, uint64_t Offset, uint64_t OpSize, uint64_t InstSize) const
std::unique_ptr< MCSymbolizer > Symbolizer
raw_ostream * CommentStream
void setSymbolizer(std::unique_ptr< MCSymbolizer > Symzer)
Set Symzer as the current symbolizer.
void tryAddingPcLoadReferenceComment(int64_t Value, uint64_t Address) const
virtual uint64_t suggestBytesToSkip(ArrayRef< uint8_t > Bytes, uint64_t Address) const
Suggest a distance to skip in a buffer of data to find the next place to look for the start of an ins...
virtual ~MCDisassembler()
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
LLVM Value Representation.
Definition: Value.h:74
StorageMappingClass
Storage Mapping Class definitions.
Definition: XCOFF.h:103
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
SymInfo contains information about symbol: it's address and section index which is -1LL for absolute ...
bool operator<(const XCOFFSymbolInfoTy &SymInfo) const
The function is for symbol sorting when symbols have the same address.