Line data Source code
1 : use lief_ffi as ffi;
2 :
3 : use crate::common::FromFFI;
4 : use crate::assembly;
5 : use super::Opcode;
6 :
7 : use crate::declare_fwd_iterator;
8 : use crate::assembly::aarch64;
9 :
10 : /// This structure represents an AArch64 instruction
11 : pub struct Instruction {
12 : ptr: cxx::UniquePtr<ffi::asm_aarch64_Instruction>,
13 : }
14 :
15 : impl FromFFI<ffi::asm_aarch64_Instruction> for Instruction {
16 0 : fn from_ffi(ptr: cxx::UniquePtr<ffi::asm_aarch64_Instruction>) -> Self {
17 0 : Self {
18 0 : ptr,
19 0 : }
20 0 : }
21 : }
22 :
23 : impl assembly::Instruction for Instruction {
24 : #[doc(hidden)]
25 0 : fn as_generic(&self) -> &ffi::asm_Instruction {
26 0 : self.ptr.as_ref().unwrap().as_ref()
27 0 : }
28 : }
29 :
30 : impl Instruction {
31 : /// The instruction opcode as defined in LLVM
32 0 : pub fn opcode(&self) -> Opcode {
33 0 : Opcode::from(self.ptr.opcode())
34 0 : }
35 :
36 : /// Return an iterator over the [`aarch64::Operands`] operands
37 0 : pub fn operands(&self) -> Operands {
38 0 : Operands::new(self.ptr.operands())
39 0 : }
40 : }
41 :
42 :
43 0 : declare_fwd_iterator!(
44 0 : Operands,
45 0 : aarch64::Operands,
46 0 : ffi::asm_Instruction,
47 0 : ffi::asm_aarch64_Operand,
48 0 : ffi::asm_aarch64_Instruction_it_operands
49 0 : );
|