Path: blob/main/contrib/llvm-project/llvm/lib/MC/MCDisassembler/MCDisassembler.cpp
35266 views
//===- MCDisassembler.cpp - Disassembler interface ------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/MC/MCDisassembler/MCDisassembler.h"9#include "llvm/ADT/ArrayRef.h"1011using namespace llvm;1213MCDisassembler::~MCDisassembler() = default;1415Expected<bool> MCDisassembler::onSymbolStart(SymbolInfoTy &Symbol,16uint64_t &Size,17ArrayRef<uint8_t> Bytes,18uint64_t Address) const {19return false;20}2122uint64_t MCDisassembler::suggestBytesToSkip(ArrayRef<uint8_t> Bytes,23uint64_t Address) const {24return 1;25}2627bool MCDisassembler::tryAddingSymbolicOperand(MCInst &Inst, int64_t Value,28uint64_t Address, bool IsBranch,29uint64_t Offset, uint64_t OpSize,30uint64_t InstSize) const {31if (Symbolizer)32return Symbolizer->tryAddingSymbolicOperand(Inst, *CommentStream, Value,33Address, IsBranch, Offset,34OpSize, InstSize);35return false;36}3738void MCDisassembler::tryAddingPcLoadReferenceComment(int64_t Value,39uint64_t Address) const {40if (Symbolizer)41Symbolizer->tryAddingPcLoadReferenceComment(*CommentStream, Value, Address);42}4344void MCDisassembler::setSymbolizer(std::unique_ptr<MCSymbolizer> Symzer) {45Symbolizer = std::move(Symzer);46}4748#define SMC_PCASE(A, P) \49case XCOFF::XMC_##A: \50return P;5152static uint8_t getSMCPriority(XCOFF::StorageMappingClass SMC) {53switch (SMC) {54SMC_PCASE(PR, 1)55SMC_PCASE(RO, 1)56SMC_PCASE(DB, 1)57SMC_PCASE(GL, 1)58SMC_PCASE(XO, 1)59SMC_PCASE(SV, 1)60SMC_PCASE(SV64, 1)61SMC_PCASE(SV3264, 1)62SMC_PCASE(TI, 1)63SMC_PCASE(TB, 1)64SMC_PCASE(RW, 1)65SMC_PCASE(TC0, 0)66SMC_PCASE(TC, 1)67SMC_PCASE(TD, 1)68SMC_PCASE(DS, 1)69SMC_PCASE(UA, 1)70SMC_PCASE(BS, 1)71SMC_PCASE(UC, 1)72SMC_PCASE(TL, 1)73SMC_PCASE(UL, 1)74SMC_PCASE(TE, 1)75#undef SMC_PCASE76}77return 0;78}7980/// The function is for symbol sorting when symbols have the same address.81/// The symbols in the same section are sorted in ascending order.82/// llvm-objdump -D will choose the highest priority symbol to display when83/// there are symbols with the same address.84bool XCOFFSymbolInfoTy::operator<(const XCOFFSymbolInfoTy &SymInfo) const {85// Label symbols have higher priority than non-label symbols.86if (IsLabel != SymInfo.IsLabel)87return SymInfo.IsLabel;8889// Symbols with a StorageMappingClass have higher priority than those without.90if (StorageMappingClass.has_value() !=91SymInfo.StorageMappingClass.has_value())92return SymInfo.StorageMappingClass.has_value();9394if (StorageMappingClass) {95return getSMCPriority(*StorageMappingClass) <96getSMCPriority(*SymInfo.StorageMappingClass);97}9899return false;100}101102103