Skip to content

Commit c3484b1

Browse files
committed
Add printer for ADR operands.
The ADR immediate operand is PC relative. But it misses its own printing function (in comparision to ADRP for example). If during disassembly the immediate was not resolved to a symbol (which is always the case for CS and llvm-objdump) the immediate is printed as is. Although it should print Address + Imm. This case should now be handled in printAdrLabel()
1 parent fe79def commit c3484b1

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

llvm/lib/Target/AArch64/AArch64InstrFormats.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ def AdrOperand : AsmOperandClass {
297297
}
298298
def adrlabel : Operand<i64> {
299299
let EncoderMethod = "getAdrLabelOpValue";
300+
let PrintMethod = "printAdrLabel";
300301
let ParserMatchClass = AdrOperand;
302+
let OperandType = "OPERAND_PCREL";
301303
}
302304

303305
class SImmOperand<int width> : AsmOperandClass {

llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,29 @@ void AArch64InstPrinter::printAlignedLabel(const MCInst *MI, uint64_t Address,
17731773
}
17741774
}
17751775

1776+
void AArch64InstPrinter::printAdrLabel(const MCInst *MI, uint64_t Address,
1777+
unsigned OpNum,
1778+
const MCSubtargetInfo &STI,
1779+
raw_ostream &O) {
1780+
const MCOperand &Op = MI->getOperand(OpNum);
1781+
1782+
// If the label has already been resolved to an immediate offset (say, when
1783+
// we're running the disassembler), just print the immediate.
1784+
if (Op.isImm()) {
1785+
const int64_t Offset = Op.getImm();
1786+
O << markup("<imm:");
1787+
if (PrintBranchImmAsAddress)
1788+
O << formatHex((Address & -4096) + Offset);
1789+
else
1790+
O << "#" << Offset;
1791+
O << markup(">");
1792+
return;
1793+
}
1794+
1795+
// Otherwise, just print the expression.
1796+
MI->getOperand(OpNum).getExpr()->print(O, &MAI);
1797+
}
1798+
17761799
void AArch64InstPrinter::printAdrpLabel(const MCInst *MI, uint64_t Address,
17771800
unsigned OpNum,
17781801
const MCSubtargetInfo &STI,

llvm/lib/Target/AArch64/MCTargetDesc/AArch64InstPrinter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ class AArch64InstPrinter : public MCInstPrinter {
174174
const MCSubtargetInfo &STI, raw_ostream &O);
175175
void printMatrixIndex(const MCInst *MI, unsigned OpNum,
176176
const MCSubtargetInfo &STI, raw_ostream &O);
177+
void printAdrLabel(const MCInst *MI, uint64_t Address, unsigned OpNum,
178+
const MCSubtargetInfo &STI, raw_ostream &O);
177179
void printAdrpLabel(const MCInst *MI, uint64_t Address, unsigned OpNum,
178180
const MCSubtargetInfo &STI, raw_ostream &O);
179181
void printBarrierOption(const MCInst *MI, unsigned OpNum,

0 commit comments

Comments
 (0)