capstone_git/arch/
sysz.rs

1//! Contains sysz-specific types
2
3use core::convert::From;
4use core::{cmp, fmt, slice};
5
6// XXX todo(garnt): create rusty versions
7pub use capstone_sys::sysz_insn_group as SysZInsnGroup;
8pub use capstone_sys::sysz_insn as SysZInsn;
9pub use capstone_sys::sysz_reg as SysZReg;
10use capstone_sys::{cs_sysz, cs_sysz_op, sysz_op_mem, sysz_op_type};
11
12pub use crate::arch::arch_builder::sysz::*;
13use crate::arch::DetailsArchInsn;
14use crate::instruction::{RegId, RegIdInt};
15
16/// Contains sysz-specific details for an instruction
17pub struct SysZInsnDetail<'a>(pub(crate) &'a cs_sysz);
18
19impl_PartialEq_repr_fields!(SysZInsnDetail<'a> [ 'a ];
20    operands
21);
22
23/// SysZ operand
24#[derive(Clone, Debug, Eq, PartialEq)]
25pub enum SysZOperand {
26    /// Register
27    Reg(RegId),
28
29    /// Immediate
30    Imm(i64),
31
32    /// Memory
33    Mem(SysZOpMem),
34
35    /// Access Register
36    AcReg(RegId),
37
38    /// Invalid
39    Invalid,
40}
41
42impl Default for SysZOperand {
43    fn default() -> Self {
44        SysZOperand::Invalid
45    }
46}
47
48/// SysZ memory operand
49#[derive(Debug, Copy, Clone)]
50pub struct SysZOpMem(pub(crate) sysz_op_mem);
51
52impl SysZOpMem {
53    /// Base register
54    pub fn base(&self) -> u8 {
55        self.0.base
56    }
57
58    /// Index register
59    pub fn index(&self) -> u8 {
60        self.0.index
61    }
62
63    /// BDLAddr operand
64    pub fn length(&self) -> u64 {
65        self.0.length
66    }
67
68    /// Disp value
69    pub fn disp(&self) -> i64 {
70        self.0.disp
71    }
72}
73
74impl_PartialEq_repr_fields!(SysZOpMem;
75    base, index, length, disp
76);
77
78impl cmp::Eq for SysZOpMem {}
79
80impl  From<&cs_sysz_op> for SysZOperand {
81    fn from(insn: &cs_sysz_op) -> SysZOperand {
82        match insn.type_ {
83            sysz_op_type::SYSZ_OP_REG => {
84                SysZOperand::Reg(RegId(unsafe { insn.__bindgen_anon_1.reg } as RegIdInt))
85            },
86            sysz_op_type::SYSZ_OP_IMM => SysZOperand::Imm(unsafe { insn.__bindgen_anon_1.imm }),
87            sysz_op_type::SYSZ_OP_MEM => {
88                SysZOperand::Mem(SysZOpMem(unsafe { insn.__bindgen_anon_1.mem }))
89            },
90            sysz_op_type::SYSZ_OP_ACREG => {
91                SysZOperand::AcReg(RegId(unsafe { insn.__bindgen_anon_1.reg } as RegIdInt))
92            },
93            sysz_op_type::SYSZ_OP_INVALID => SysZOperand::Invalid,
94        }
95    }
96}
97
98def_arch_details_struct!(
99    InsnDetail = SysZInsnDetail;
100    Operand = SysZOperand;
101    OperandIterator = SysZOperandIterator;
102    OperandIteratorLife = SysZOperandIterator<'a>;
103    [ pub struct SysZOperandIterator<'a>(slice::Iter<'a, cs_sysz_op>); ]
104    cs_arch_op = cs_sysz_op;
105    cs_arch = cs_sysz;
106);