#include "llvm/MC/MCDisassembler/MCDisassembler.h"
#include "llvm/ADT/ArrayRef.h"
using namespace llvm;
MCDisassembler::~MCDisassembler() = default;
Optional<MCDisassembler::DecodeStatus>
MCDisassembler::onSymbolStart(SymbolInfoTy &Symbol, uint64_t &Size,
ArrayRef<uint8_t> Bytes, uint64_t Address,
raw_ostream &CStream) const {
return None;
}
uint64_t MCDisassembler::suggestBytesToSkip(ArrayRef<uint8_t> Bytes,
uint64_t Address) const {
return 1;
}
bool MCDisassembler::tryAddingSymbolicOperand(MCInst &Inst, int64_t Value,
uint64_t Address, bool IsBranch,
uint64_t Offset, uint64_t OpSize,
uint64_t InstSize) const {
if (Symbolizer)
return Symbolizer->tryAddingSymbolicOperand(Inst, *CommentStream, Value,
Address, IsBranch, Offset,
OpSize, InstSize);
return false;
}
void MCDisassembler::tryAddingPcLoadReferenceComment(int64_t Value,
uint64_t Address) const {
if (Symbolizer)
Symbolizer->tryAddingPcLoadReferenceComment(*CommentStream, Value, Address);
}
void MCDisassembler::setSymbolizer(std::unique_ptr<MCSymbolizer> Symzer) {
Symbolizer = std::move(Symzer);
}
#define SMC_PCASE(A, P) \
case XCOFF::XMC_##A: \
return P;
static uint8_t getSMCPriority(XCOFF::StorageMappingClass SMC) {
switch (SMC) {
SMC_PCASE(PR, 1)
SMC_PCASE(RO, 1)
SMC_PCASE(DB, 1)
SMC_PCASE(GL, 1)
SMC_PCASE(XO, 1)
SMC_PCASE(SV, 1)
SMC_PCASE(SV64, 1)
SMC_PCASE(SV3264, 1)
SMC_PCASE(TI, 1)
SMC_PCASE(TB, 1)
SMC_PCASE(RW, 1)
SMC_PCASE(TC0, 0)
SMC_PCASE(TC, 1)
SMC_PCASE(TD, 1)
SMC_PCASE(DS, 1)
SMC_PCASE(UA, 1)
SMC_PCASE(BS, 1)
SMC_PCASE(UC, 1)
SMC_PCASE(TL, 1)
SMC_PCASE(UL, 1)
SMC_PCASE(TE, 1)
#undef SMC_PCASE
}
return 0;
}
bool XCOFFSymbolInfo::operator<(const XCOFFSymbolInfo &SymInfo) const {
if (IsLabel != SymInfo.IsLabel)
return SymInfo.IsLabel;
if (StorageMappingClass.has_value() !=
SymInfo.StorageMappingClass.has_value())
return SymInfo.StorageMappingClass.has_value();
if (StorageMappingClass) {
return getSMCPriority(StorageMappingClass.value()) <
getSMCPriority(SymInfo.StorageMappingClass.value());
}
return false;
}