Skip to content

Commit 4b199bb

Browse files
committed
rs: add access mode to sparc operand
1 parent f8f2520 commit 4b199bb

File tree

2 files changed

+217
-65
lines changed

2 files changed

+217
-65
lines changed

capstone-rs/src/arch/sparc.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Contains sparc-specific types
22
3-
use core::convert::From;
3+
use core::convert::{From, TryInto};
44
use core::{cmp, fmt, slice};
55

66
// XXX todo(tmfink): create rusty versions
@@ -16,13 +16,35 @@ use capstone_sys::{cs_sparc, cs_sparc_op, sparc_op_mem, sparc_op_type};
1616
pub use crate::arch::arch_builder::sparc::*;
1717
use crate::arch::DetailsArchInsn;
1818
use crate::instruction::{RegId, RegIdInt};
19+
use crate::RegAccessType;
1920

2021
/// Contains SPARC-specific details for an instruction
2122
pub struct SparcInsnDetail<'a>(pub(crate) &'a cs_sparc);
2223

2324
/// SPARC operand
25+
#[derive(Clone, Debug, Eq, PartialEq, Default)]
26+
pub struct SparcOperand {
27+
/// Operand type
28+
pub op_type: SparcOperandType,
29+
30+
/// How is this operand accessed?
31+
///
32+
/// NOTE: this field is always `None` if the "full" feataure is not enabled.
33+
pub access: Option<RegAccessType>,
34+
}
35+
36+
impl From<&cs_sparc_op> for SparcOperand {
37+
fn from(op: &cs_sparc_op) -> SparcOperand {
38+
let op_type = SparcOperandType::from(op);
39+
SparcOperand {
40+
op_type,
41+
access: op.access.try_into().ok(),
42+
}
43+
}
44+
}
45+
2446
#[derive(Clone, Debug, Eq, PartialEq)]
25-
pub enum SparcOperand {
47+
pub enum SparcOperandType {
2648
/// Register
2749
Reg(RegId),
2850

@@ -58,9 +80,9 @@ impl_PartialEq_repr_fields!(SparcInsnDetail<'a> [ 'a ];
5880
cc, hint, operands
5981
);
6082

61-
impl Default for SparcOperand {
83+
impl Default for SparcOperandType {
6284
fn default() -> Self {
63-
SparcOperand::Invalid
85+
SparcOperandType::Invalid
6486
}
6587
}
6688

@@ -91,21 +113,25 @@ impl_PartialEq_repr_fields!(SparcOpMem;
91113

92114
impl cmp::Eq for SparcOpMem {}
93115

94-
impl From<&cs_sparc_op> for SparcOperand {
95-
fn from(insn: &cs_sparc_op) -> SparcOperand {
116+
impl From<&cs_sparc_op> for SparcOperandType {
117+
fn from(insn: &cs_sparc_op) -> SparcOperandType {
96118
match insn.type_ {
97119
sparc_op_type::SPARC_OP_REG => {
98-
SparcOperand::Reg(RegId(unsafe { insn.__bindgen_anon_1.reg } as RegIdInt))
120+
SparcOperandType::Reg(RegId(unsafe { insn.__bindgen_anon_1.reg } as RegIdInt))
121+
}
122+
sparc_op_type::SPARC_OP_IMM => {
123+
SparcOperandType::Imm(unsafe { insn.__bindgen_anon_1.imm })
99124
}
100-
sparc_op_type::SPARC_OP_IMM => SparcOperand::Imm(unsafe { insn.__bindgen_anon_1.imm }),
101125
sparc_op_type::SPARC_OP_MEM => {
102-
SparcOperand::Mem(SparcOpMem(unsafe { insn.__bindgen_anon_1.mem }))
126+
SparcOperandType::Mem(SparcOpMem(unsafe { insn.__bindgen_anon_1.mem }))
103127
}
104128
sparc_op_type::SPARC_OP_MEMBAR_TAG => {
105-
SparcOperand::MembarTag(unsafe { insn.__bindgen_anon_1.membar_tag })
129+
SparcOperandType::MembarTag(unsafe { insn.__bindgen_anon_1.membar_tag })
130+
}
131+
sparc_op_type::SPARC_OP_ASI => {
132+
SparcOperandType::Asi(unsafe { insn.__bindgen_anon_1.asi })
106133
}
107-
sparc_op_type::SPARC_OP_ASI => SparcOperand::Asi(unsafe { insn.__bindgen_anon_1.asi }),
108-
sparc_op_type::SPARC_OP_INVALID => SparcOperand::Invalid,
134+
sparc_op_type::SPARC_OP_INVALID => SparcOperandType::Invalid,
109135
}
110136
}
111137
}

0 commit comments

Comments
 (0)