1 //===- MCDisassembler.cpp - Disassembler interface ------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCDisassembler/MCDisassembler.h"
10 #include "llvm/ADT/ArrayRef.h"
14 MCDisassembler::~MCDisassembler() = default;
16 Expected
<bool> MCDisassembler::onSymbolStart(SymbolInfoTy
&Symbol
,
18 ArrayRef
<uint8_t> Bytes
,
19 uint64_t Address
) const {
23 uint64_t MCDisassembler::suggestBytesToSkip(ArrayRef
<uint8_t> Bytes
,
24 uint64_t Address
) const {
28 bool MCDisassembler::tryAddingSymbolicOperand(MCInst
&Inst
, int64_t Value
,
29 uint64_t Address
, bool IsBranch
,
30 uint64_t Offset
, uint64_t OpSize
,
31 uint64_t InstSize
) const {
33 return Symbolizer
->tryAddingSymbolicOperand(Inst
, *CommentStream
, Value
,
34 Address
, IsBranch
, Offset
,
39 void MCDisassembler::tryAddingPcLoadReferenceComment(int64_t Value
,
40 uint64_t Address
) const {
42 Symbolizer
->tryAddingPcLoadReferenceComment(*CommentStream
, Value
, Address
);
45 void MCDisassembler::setSymbolizer(std::unique_ptr
<MCSymbolizer
> Symzer
) {
46 Symbolizer
= std::move(Symzer
);
49 #define SMC_PCASE(A, P) \
50 case XCOFF::XMC_##A: \
53 static uint8_t getSMCPriority(XCOFF::StorageMappingClass SMC
) {
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.
85 bool XCOFFSymbolInfoTy::operator<(const XCOFFSymbolInfoTy
&SymInfo
) const {
86 // Label symbols have higher priority than non-label symbols.
87 if (IsLabel
!= SymInfo
.IsLabel
)
88 return SymInfo
.IsLabel
;
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();
95 if (StorageMappingClass
) {
96 return getSMCPriority(*StorageMappingClass
) <
97 getSMCPriority(*SymInfo
.StorageMappingClass
);