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"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Support/raw_ostream.h"
17 MCDisassembler::~MCDisassembler() = default;
19 Optional
<MCDisassembler::DecodeStatus
>
20 MCDisassembler::onSymbolStart(SymbolInfoTy
&Symbol
, uint64_t &Size
,
21 ArrayRef
<uint8_t> Bytes
, uint64_t Address
,
22 raw_ostream
&CStream
) const {
26 bool MCDisassembler::tryAddingSymbolicOperand(MCInst
&Inst
, int64_t Value
,
27 uint64_t Address
, bool IsBranch
,
29 uint64_t InstSize
) const {
31 return Symbolizer
->tryAddingSymbolicOperand(
32 Inst
, *CommentStream
, Value
, Address
, IsBranch
, Offset
, InstSize
);
36 void MCDisassembler::tryAddingPcLoadReferenceComment(int64_t Value
,
37 uint64_t Address
) const {
39 Symbolizer
->tryAddingPcLoadReferenceComment(*CommentStream
, Value
, Address
);
42 void MCDisassembler::setSymbolizer(std::unique_ptr
<MCSymbolizer
> Symzer
) {
43 Symbolizer
= std::move(Symzer
);
46 #define SMC_PCASE(A, P) \
47 case XCOFF::XMC_##A: \
50 static uint8_t getSMCPriority(XCOFF::StorageMappingClass SMC
) {
78 /// The function is for symbol sorting when symbols have the same address.
79 /// The symbols in the same section are sorted in ascending order.
80 /// llvm-objdump -D will choose the highest priority symbol to display when
81 /// there are symbols with the same address.
82 bool XCOFFSymbolInfo::operator<(const XCOFFSymbolInfo
&SymInfo
) const {
83 // Label symbols have higher priority than non-label symbols.
84 if (IsLabel
!= SymInfo
.IsLabel
)
85 return SymInfo
.IsLabel
;
87 // Symbols with a StorageMappingClass have higher priority than those without.
88 if (StorageMappingClass
.hasValue() != SymInfo
.StorageMappingClass
.hasValue())
89 return SymInfo
.StorageMappingClass
.hasValue();
91 if (StorageMappingClass
.hasValue()) {
92 return getSMCPriority(StorageMappingClass
.getValue()) <
93 getSMCPriority(SymInfo
.StorageMappingClass
.getValue());