use binbun_isa::{Architecture, Flow};
use crate::{Encoding, Error, Instruction, Operand, decode_bytes};
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub enum Mode {
#[default]
A64,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub struct AArch64;
impl Architecture for AArch64 {
type Instruction = Instruction;
type Error = Error;
type Mode = Mode;
const MAX_LENGTH: usize = 4;
fn decode(&self, bytes: &[u8], mode: Mode) -> Result<Instruction, Error> {
let Mode::A64 = mode;
decode_bytes(bytes)
}
}
impl binbun_isa::Instruction for Instruction {
fn len(&self) -> usize {
4
}
fn flow(&self, address: u64) -> Flow {
Instruction::flow(*self, address)
}
fn computed_address(&self, address: u64) -> Option<u64> {
if self.encoding() != Encoding::ADR_only_pcreladdr {
return None;
}
self.operands().iter().find_map(|operand| match *operand {
Operand::Label(label) => Some(label.target(address)),
Operand::Register(_)
| Operand::List(_)
| Operand::Immediate(_)
| Operand::Float(_)
| Operand::Shift(_)
| Operand::Extend(_)
| Operand::Memory(_)
| Operand::Writeback(_)
| Operand::Condition(_)
| Operand::SystemRegister(_)
| Operand::Named(_)
| Operand::Za(_)
| Operand::ZaList(_)
| Operand::TableSlice(_)
| Operand::IndexedRegister(_) => None,
})
}
}