Skip to content

Commit

Permalink
put the new functions behind the instr_info feature
Browse files Browse the repository at this point in the history
  • Loading branch information
susitsm authored and Matyas Susits committed Sep 21, 2024
1 parent 0916d0e commit c1d5e8d
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 69 deletions.
2 changes: 2 additions & 0 deletions src/rust/iced-x86/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::iced_constants::IcedConstants;
use crate::iced_error::IcedError;
#[cfg(feature = "instr_info")]
use crate::info::enums::*;
#[cfg(feature = "instr_info")]
use crate::info::info_flags::{code_info_flags, InfoFlags1 as InfoFlags1Type, InfoFlags2 as InfoFlags2Type};
use crate::mnemonics;
use crate::*;
Expand Down Expand Up @@ -45144,6 +45145,7 @@ impl Code {
}
}

#[cfg(feature = "instr_info")]
impl Code {
pub(crate) const fn info_flags(&self) -> &(InfoFlags1Type, InfoFlags2Type) {
code_info_flags(*self)
Expand Down
144 changes: 75 additions & 69 deletions src/rust/iced-x86/src/encoder/op_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct OpCodeInfo {
group_index: i8,
rm_group_index: i8,
op_kinds: [OpCodeOperandKind; IcedConstants::MAX_OP_COUNT],
#[cfg(feature = "instr_info")]
op_accesses: [OpAccess; IcedConstants::MAX_OP_COUNT],
}

Expand Down Expand Up @@ -359,6 +360,7 @@ impl OpCodeInfo {
group_index,
rm_group_index,
op_kinds: [op0_kind, op1_kind, op2_kind, op3_kind, op4_kind],
#[cfg(feature = "instr_info")]
op_accesses: [code.op0_access(), code.op1_access(), code.op2_access(), code.op3_access(), code.op4_access()],
};

Expand Down Expand Up @@ -1302,75 +1304,6 @@ impl OpCodeInfo {
instruction_op_counts::OP_COUNT[self.code() as usize] as u32
}

/// Gets operand #0's OpAccess
#[must_use]
#[inline]
pub const fn op0_access(&self) -> OpAccess {
self.op_accesses[0]
}

/// Gets operand #1's OpAccess
#[must_use]
#[inline]
pub const fn op1_access(&self) -> OpAccess {
self.op_accesses[1]
}

/// Gets operand #2's OpAccess
#[must_use]
#[inline]
pub const fn op2_access(&self) -> OpAccess {
self.op_accesses[2]
}

/// Gets operand #3's OpAccess
#[must_use]
#[inline]
pub const fn op3_access(&self) -> OpAccess {
self.op_accesses[3]
}

/// Gets operand #4's OpAccess
#[must_use]
#[inline]
pub const fn op4_access(&self) -> OpAccess {
self.op_accesses[4]
}

/// Gets an operand's opaccess
///
/// # Arguments
///
/// * `operand`: Operand number, 0-4
#[must_use]
#[inline]
pub fn op_access(&self, operand: u32) -> OpAccess {
match self.op_accesses.get(operand as usize) {
Some(&op_access) => op_access,
None => {
debug_assert!(false, "Invalid operand: {}", operand);
OpAccess::None
}
}
}

#[inline]
#[allow(clippy::missing_inline_in_public_items)]
#[doc(hidden)]
pub fn try_op_access(&self, operand: u32) -> Result<OpAccess, IcedError> {
match self.op_accesses.get(operand as usize) {
Some(&op_access) => Ok(op_access),
None => Err(IcedError::new("Invalid operand")),
}
}

/// Gets all operand accesses
#[must_use]
#[inline]
pub fn op_accesses(&self) -> &[OpAccess] {
&self.op_accesses[0..self.op_count() as usize]
}

/// Gets operand #0's opkind
#[must_use]
#[inline]
Expand Down Expand Up @@ -1493,6 +1426,79 @@ impl OpCodeInfo {
}
}

#[cfg(feature = "instr_info")]
impl OpCodeInfo {
/// Gets operand #0's OpAccess
#[must_use]
#[inline]
pub const fn op0_access(&self) -> OpAccess {
self.op_accesses[0]
}

/// Gets operand #1's OpAccess
#[must_use]
#[inline]
pub const fn op1_access(&self) -> OpAccess {
self.op_accesses[1]
}

/// Gets operand #2's OpAccess
#[must_use]
#[inline]
pub const fn op2_access(&self) -> OpAccess {
self.op_accesses[2]
}

/// Gets operand #3's OpAccess
#[must_use]
#[inline]
pub const fn op3_access(&self) -> OpAccess {
self.op_accesses[3]
}

/// Gets operand #4's OpAccess
#[must_use]
#[inline]
pub const fn op4_access(&self) -> OpAccess {
self.op_accesses[4]
}

/// Gets an operand's opaccess
///
/// # Arguments
///
/// * `operand`: Operand number, 0-4
#[must_use]
#[inline]
pub fn op_access(&self, operand: u32) -> OpAccess {
match self.op_accesses.get(operand as usize) {
Some(&op_access) => op_access,
None => {
debug_assert!(false, "Invalid operand: {}", operand);
OpAccess::None
}
}
}

#[inline]
#[allow(clippy::missing_inline_in_public_items)]
#[doc(hidden)]
pub fn try_op_access(&self, operand: u32) -> Result<OpAccess, IcedError> {
match self.op_accesses.get(operand as usize) {
Some(&op_access) => Ok(op_access),
None => Err(IcedError::new("Invalid operand")),
}
}

/// Gets all operand accesses
#[must_use]
#[inline]
pub fn op_accesses(&self) -> &[OpAccess] {
&self.op_accesses[0..self.op_count() as usize]
}
}


impl fmt::Display for OpCodeInfo {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down

0 comments on commit c1d5e8d

Please sign in to comment.