Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4207,6 +4207,17 @@ bool AArch64AsmParser::MatchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
}
}

if (NumOperands == 3 && Tok == "adrp") {
AArch64Operand &ImmOp = static_cast<AArch64Operand &>(*Operands[2]);
const MCConstantExpr *Op2CE = dyn_cast<MCConstantExpr>(ImmOp.getImm());
uint64_t NewOp2Val = Op2CE->getValue() - (Address & ~0xFFF);

const MCExpr *NewOp2 =
MCConstantExpr::create(NewOp2Val, getContext());
Operands[2] = AArch64Operand::CreateImm(
NewOp2, ImmOp.getStartLoc(), ImmOp.getEndLoc(), getContext());
}

MCInst Inst(Address);
// First try to match against the secondary set of tables containing the
// short-form NEON instructions (e.g. "fadd.2s v0, v1, v2").
Expand Down
23 changes: 23 additions & 0 deletions suite/regress/arm64_adrp_imm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python
# KhiemNNM, 2016

# This tests the ADRP Xd, #imm.

# Github issue: #259
# Author: Khiem Nguyen

from keystone import *

import regress

class TestARM(regress.RegressTest):
def runTest(self):
# Initialize Keystone engine
ks = Ks(KS_ARCH_ARM64, 0)
# Assemble to get back insn encoding & statement count
encoding, count = ks.asm(b"ADRP X8,#0x10274400",0x100011C38)
# Assert the result
self.assertEqual(encoding, [ 0x88 ,0x39, 0x01 ,0xF0 ])

if __name__ == '__main__':
regress.main()