Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 39 additions & 49 deletions llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,48 @@ DecodeCoprocPairRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
return MCDisassembler::Success;
}

static DecodeStatus DecodeCall(MCInst &Inst, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder);
static DecodeStatus DecodeSIMM5(MCInst &Inst, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder);
static DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder);
static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch,
uint64_t Address, uint64_t Offset,
uint64_t Width, MCInst &MI,
const MCDisassembler *Decoder) {
return Decoder->tryAddingSymbolicOperand(MI, Value, Address, isBranch, Offset,
Width, /*InstSize=*/4);
}

static DecodeStatus DecodeCall(MCInst &MI, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder) {
int64_t CallOffset = SignExtend64(fieldFromInstruction(insn, 0, 30), 30) * 4;
if (!tryAddingSymbolicOperand(Address + CallOffset, false, Address, 0, 30, MI,
Decoder))
MI.addOperand(MCOperand::createImm(CallOffset));
return MCDisassembler::Success;
}

static DecodeStatus DecodeSIMM5(MCInst &MI, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder) {
assert(isUInt<5>(insn));
MI.addOperand(MCOperand::createImm(SignExtend64<5>(insn)));
return MCDisassembler::Success;
}

static DecodeStatus DecodeSIMM13(MCInst &MI, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder) {
assert(isUInt<13>(insn));
MI.addOperand(MCOperand::createImm(SignExtend64<13>(insn)));
return MCDisassembler::Success;
}

template <unsigned N>
constexpr static DecodeStatus DecodeDisp(MCInst &MI, uint32_t ImmVal,
uint64_t Address,
const MCDisassembler *Decoder);
const MCDisassembler *Decoder) {
int64_t BranchOffset = SignExtend64(ImmVal, N) * 4;
if (!tryAddingSymbolicOperand(Address + BranchOffset, true, Address, 0, N, MI,
Decoder))
MI.addOperand(MCOperand::createImm(BranchOffset));
return MCDisassembler::Success;
}

#include "SparcGenDisassemblerTables.inc"

/// Read four bytes from the ArrayRef and return 32 bit word.
Expand Down Expand Up @@ -321,45 +353,3 @@ DecodeStatus SparcDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,

return Result;
}

static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch,
uint64_t Address, uint64_t Offset,
uint64_t Width, MCInst &MI,
const MCDisassembler *Decoder) {
return Decoder->tryAddingSymbolicOperand(MI, Value, Address, isBranch, Offset,
Width, /*InstSize=*/4);
}

static DecodeStatus DecodeCall(MCInst &MI, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder) {
int64_t CallOffset = SignExtend64(fieldFromInstruction(insn, 0, 30), 30) * 4;
if (!tryAddingSymbolicOperand(Address + CallOffset, false, Address, 0, 30, MI,
Decoder))
MI.addOperand(MCOperand::createImm(CallOffset));
return MCDisassembler::Success;
}

static DecodeStatus DecodeSIMM5(MCInst &MI, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder) {
assert(isUInt<5>(insn));
MI.addOperand(MCOperand::createImm(SignExtend64<5>(insn)));
return MCDisassembler::Success;
}

static DecodeStatus DecodeSIMM13(MCInst &MI, unsigned insn, uint64_t Address,
const MCDisassembler *Decoder) {
assert(isUInt<13>(insn));
MI.addOperand(MCOperand::createImm(SignExtend64<13>(insn)));
return MCDisassembler::Success;
}

template <unsigned N>
constexpr static DecodeStatus DecodeDisp(MCInst &MI, uint32_t ImmVal,
uint64_t Address,
const MCDisassembler *Decoder) {
int64_t BranchOffset = SignExtend64(ImmVal, N) * 4;
if (!tryAddingSymbolicOperand(Address + BranchOffset, true, Address, 0, N, MI,
Decoder))
MI.addOperand(MCOperand::createImm(BranchOffset));
return MCDisassembler::Success;
}