Skip to content

Commit 474ba1d

Browse files
authored
[NFC][MC][Sparc] Rearrange decode functions in Sparc disassembler (#154973)
Some of the decode function were previously declared before including `SparcGenDisassemblerTables.inc` and then defined later on because the generated code in `SparcGenDisassemblerTables.inc` references these functions and these functions reference `fieldFromInstruction` which used to be generated. Now that `fieldFromInstruction` has moved to MCDecoder.h, we can move these definitions to before including the generated code without any circular references.
1 parent 6dc188d commit 474ba1d

File tree

1 file changed

+40
-51
lines changed

1 file changed

+40
-51
lines changed

llvm/lib/Target/Sparc/Disassembler/SparcDisassembler.cpp

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,47 @@ DecodeCoprocPairRegisterClass(MCInst &Inst, unsigned RegNo, uint64_t Address,
266266
return MCDisassembler::Success;
267267
}
268268

269-
static DecodeStatus DecodeCall(MCInst &Inst, unsigned insn, uint64_t Address,
270-
const MCDisassembler *Decoder);
271-
static DecodeStatus DecodeSIMM5(MCInst &Inst, unsigned insn, uint64_t Address,
272-
const MCDisassembler *Decoder);
273-
static DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn, uint64_t Address,
274-
const MCDisassembler *Decoder);
269+
static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch,
270+
uint64_t Address, uint64_t Offset,
271+
uint64_t Width, MCInst &MI,
272+
const MCDisassembler *Decoder) {
273+
return Decoder->tryAddingSymbolicOperand(MI, Value, Address, isBranch, Offset,
274+
Width, /*InstSize=*/4);
275+
}
276+
277+
static DecodeStatus DecodeCall(MCInst &MI, unsigned insn, uint64_t Address,
278+
const MCDisassembler *Decoder) {
279+
int64_t CallOffset = SignExtend64(fieldFromInstruction(insn, 0, 30), 30) * 4;
280+
if (!tryAddingSymbolicOperand(Address + CallOffset, false, Address, 0, 30, MI,
281+
Decoder))
282+
MI.addOperand(MCOperand::createImm(CallOffset));
283+
return MCDisassembler::Success;
284+
}
285+
286+
static DecodeStatus DecodeSIMM5(MCInst &MI, unsigned insn, uint64_t Address,
287+
const MCDisassembler *Decoder) {
288+
assert(isUInt<5>(insn));
289+
MI.addOperand(MCOperand::createImm(SignExtend64<5>(insn)));
290+
return MCDisassembler::Success;
291+
}
292+
293+
static DecodeStatus DecodeSIMM13(MCInst &MI, unsigned insn, uint64_t Address,
294+
const MCDisassembler *Decoder) {
295+
assert(isUInt<13>(insn));
296+
MI.addOperand(MCOperand::createImm(SignExtend64<13>(insn)));
297+
return MCDisassembler::Success;
298+
}
299+
275300
template <unsigned N>
276-
constexpr static DecodeStatus DecodeDisp(MCInst &MI, uint32_t ImmVal,
277-
uint64_t Address,
278-
const MCDisassembler *Decoder);
301+
static DecodeStatus DecodeDisp(MCInst &MI, uint32_t ImmVal, uint64_t Address,
302+
const MCDisassembler *Decoder) {
303+
int64_t BranchOffset = SignExtend64(ImmVal, N) * 4;
304+
if (!tryAddingSymbolicOperand(Address + BranchOffset, true, Address, 0, N, MI,
305+
Decoder))
306+
MI.addOperand(MCOperand::createImm(BranchOffset));
307+
return MCDisassembler::Success;
308+
}
309+
279310
#include "SparcGenDisassemblerTables.inc"
280311

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

322353
return Result;
323354
}
324-
325-
static bool tryAddingSymbolicOperand(int64_t Value, bool isBranch,
326-
uint64_t Address, uint64_t Offset,
327-
uint64_t Width, MCInst &MI,
328-
const MCDisassembler *Decoder) {
329-
return Decoder->tryAddingSymbolicOperand(MI, Value, Address, isBranch, Offset,
330-
Width, /*InstSize=*/4);
331-
}
332-
333-
static DecodeStatus DecodeCall(MCInst &MI, unsigned insn, uint64_t Address,
334-
const MCDisassembler *Decoder) {
335-
int64_t CallOffset = SignExtend64(fieldFromInstruction(insn, 0, 30), 30) * 4;
336-
if (!tryAddingSymbolicOperand(Address + CallOffset, false, Address, 0, 30, MI,
337-
Decoder))
338-
MI.addOperand(MCOperand::createImm(CallOffset));
339-
return MCDisassembler::Success;
340-
}
341-
342-
static DecodeStatus DecodeSIMM5(MCInst &MI, unsigned insn, uint64_t Address,
343-
const MCDisassembler *Decoder) {
344-
assert(isUInt<5>(insn));
345-
MI.addOperand(MCOperand::createImm(SignExtend64<5>(insn)));
346-
return MCDisassembler::Success;
347-
}
348-
349-
static DecodeStatus DecodeSIMM13(MCInst &MI, unsigned insn, uint64_t Address,
350-
const MCDisassembler *Decoder) {
351-
assert(isUInt<13>(insn));
352-
MI.addOperand(MCOperand::createImm(SignExtend64<13>(insn)));
353-
return MCDisassembler::Success;
354-
}
355-
356-
template <unsigned N>
357-
constexpr static DecodeStatus DecodeDisp(MCInst &MI, uint32_t ImmVal,
358-
uint64_t Address,
359-
const MCDisassembler *Decoder) {
360-
int64_t BranchOffset = SignExtend64(ImmVal, N) * 4;
361-
if (!tryAddingSymbolicOperand(Address + BranchOffset, true, Address, 0, N, MI,
362-
Decoder))
363-
MI.addOperand(MCOperand::createImm(BranchOffset));
364-
return MCDisassembler::Success;
365-
}

0 commit comments

Comments
 (0)