|
| 1 | +//! Contains arc-specific types |
| 2 | +
|
| 3 | +use core::convert::{From, TryInto}; |
| 4 | +use core::{cmp, fmt, slice}; |
| 5 | + |
| 6 | +pub use capstone_sys::arc_insn as ArcInsn; |
| 7 | +pub use capstone_sys::arc_reg as ArcReg; |
| 8 | +use capstone_sys::{arc_op_type, cs_arc, cs_arc_op, cs_arc_op__bindgen_ty_1}; |
| 9 | + |
| 10 | +pub use crate::arch::arch_builder::arc::*; |
| 11 | +use crate::arch::DetailsArchInsn; |
| 12 | +use crate::instruction::{RegId, RegIdInt}; |
| 13 | +use crate::RegAccessType; |
| 14 | + |
| 15 | +/// Contains arc-specific details for an instruction |
| 16 | +pub struct ArcInsnDetail<'a>(pub(crate) &'a cs_arc); |
| 17 | + |
| 18 | +impl_PartialEq_repr_fields!(ArcInsnDetail<'a> [ 'a ]; |
| 19 | + operands |
| 20 | +); |
| 21 | + |
| 22 | +/// arc operand |
| 23 | +#[derive(Clone, Debug, Eq, PartialEq, Default)] |
| 24 | +pub struct ArcOperand { |
| 25 | + /// Operand type |
| 26 | + pub op_type: ArcOperandType, |
| 27 | + |
| 28 | + /// How is this operand accessed? |
| 29 | + /// |
| 30 | + /// NOTE: this field is always `None` if the "full" feataure is not enabled. |
| 31 | + pub access: Option<RegAccessType>, |
| 32 | +} |
| 33 | + |
| 34 | +impl From<&cs_arc_op> for ArcOperand { |
| 35 | + fn from(op: &cs_arc_op) -> ArcOperand { |
| 36 | + let op_type = ArcOperandType::new(op.type_, op.__bindgen_anon_1); |
| 37 | + ArcOperand { |
| 38 | + op_type, |
| 39 | + access: op.access.try_into().ok(), |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +/// Arc operand |
| 45 | +#[derive(Clone, Debug, PartialEq)] |
| 46 | +pub enum ArcOperandType { |
| 47 | + /// Register |
| 48 | + Reg(RegId), |
| 49 | + |
| 50 | + /// Immediate |
| 51 | + Imm(i64), |
| 52 | + |
| 53 | + /// Invalid |
| 54 | + Invalid, |
| 55 | +} |
| 56 | + |
| 57 | +impl ArcOperandType { |
| 58 | + fn new(op_type: arc_op_type, value: cs_arc_op__bindgen_ty_1) -> ArcOperandType { |
| 59 | + match op_type { |
| 60 | + arc_op_type::ARC_OP_REG => ArcOperandType::Reg(RegId(unsafe { value.reg } as RegIdInt)), |
| 61 | + arc_op_type::ARC_OP_IMM => ArcOperandType::Imm(unsafe { value.imm }), |
| 62 | + arc_op_type::ARC_OP_INVALID => ArcOperandType::Invalid, |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +impl cmp::Eq for ArcOperandType {} |
| 68 | + |
| 69 | +impl Default for ArcOperandType { |
| 70 | + fn default() -> Self { |
| 71 | + ArcOperandType::Invalid |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +def_arch_details_struct!( |
| 76 | + InsnDetail = ArcInsnDetail; |
| 77 | + Operand = ArcOperand; |
| 78 | + OperandIterator = ArcOperandIterator; |
| 79 | + OperandIteratorLife = ArcOperandIterator<'a>; |
| 80 | + [ pub struct ArcOperandIterator<'a>(slice::Iter<'a, cs_arc_op>); ] |
| 81 | + cs_arch_op = cs_arc_op; |
| 82 | + cs_arch = cs_arc; |
| 83 | +); |
0 commit comments