Skip to content

Commit

Permalink
Use a macro to init handler locals
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Mar 16, 2021
1 parent 325690f commit 85d6143
Showing 1 changed file with 21 additions and 41 deletions.
62 changes: 21 additions & 41 deletions src/rust/iced-x86/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,6 @@ impl<'a> Decoder<'a> {
}
_ => return Err(IcedError::new("Invalid bitness")),
}
fn get_handlers(handlers: &'static [&'static OpCodeHandler]) -> *const &'static OpCodeHandler {
debug_assert_eq!(handlers.len(), 0x100);
handlers.as_ptr()
}
let data_ptr_end = data.as_ptr() as usize + data.len();
if data_ptr_end < data.as_ptr() as usize || {
// Verify that max_data_ptr can never overflow and that data_ptr.add(N) can't overflow.
Expand All @@ -739,43 +735,27 @@ impl<'a> Decoder<'a> {

let tables = &*TABLES;

#[cfg(not(feature = "no_vex"))]
let handlers_vex_0fxx = get_handlers(&tables.handlers_vex_0fxx);
#[cfg(not(feature = "no_vex"))]
let handlers_vex_0f38xx = get_handlers(&tables.handlers_vex_0f38xx);
#[cfg(not(feature = "no_vex"))]
let handlers_vex_0f3axx = get_handlers(&tables.handlers_vex_0f3axx);
#[cfg(not(feature = "no_evex"))]
let handlers_evex_0fxx = get_handlers(&tables.handlers_evex_0fxx);
#[cfg(not(feature = "no_evex"))]
let handlers_evex_0f38xx = get_handlers(&tables.handlers_evex_0f38xx);
#[cfg(not(feature = "no_evex"))]
let handlers_evex_0f3axx = get_handlers(&tables.handlers_evex_0f3axx);
#[cfg(not(feature = "no_xop"))]
let handlers_xop8 = get_handlers(&tables.handlers_xop8);
#[cfg(not(feature = "no_xop"))]
let handlers_xop9 = get_handlers(&tables.handlers_xop9);
#[cfg(not(feature = "no_xop"))]
let handlers_xopa = get_handlers(&tables.handlers_xopa);

#[cfg(feature = "no_vex")]
let handlers_vex_0fxx = ();
#[cfg(feature = "no_vex")]
let handlers_vex_0f38xx = ();
#[cfg(feature = "no_vex")]
let handlers_vex_0f3axx = ();
#[cfg(feature = "no_evex")]
let handlers_evex_0fxx = ();
#[cfg(feature = "no_evex")]
let handlers_evex_0f38xx = ();
#[cfg(feature = "no_evex")]
let handlers_evex_0f3axx = ();
#[cfg(feature = "no_xop")]
let handlers_xop8 = ();
#[cfg(feature = "no_xop")]
let handlers_xop9 = ();
#[cfg(feature = "no_xop")]
let handlers_xopa = ();
fn get_handlers(handlers: &'static [&'static OpCodeHandler]) -> *const &'static OpCodeHandler {
debug_assert_eq!(handlers.len(), 0x100);
handlers.as_ptr()
}
macro_rules! mk_handlers_local {
($name:ident, $feature:literal) => {
#[cfg(not(feature = $feature))]
let $name = get_handlers(&tables.$name);
#[cfg(feature = $feature)]
let $name = ();
};
}
mk_handlers_local!(handlers_vex_0fxx, "no_vex");
mk_handlers_local!(handlers_vex_0f38xx, "no_vex");
mk_handlers_local!(handlers_vex_0f3axx, "no_vex");
mk_handlers_local!(handlers_evex_0fxx, "no_evex");
mk_handlers_local!(handlers_evex_0f38xx, "no_evex");
mk_handlers_local!(handlers_evex_0f3axx, "no_evex");
mk_handlers_local!(handlers_xop8, "no_xop");
mk_handlers_local!(handlers_xop9, "no_xop");
mk_handlers_local!(handlers_xopa, "no_xop");

debug_assert_eq!(prefixes.len() * mem::size_of_val(&prefixes[0]) * 8, 256);
Ok(Decoder {
Expand Down

0 comments on commit 85d6143

Please sign in to comment.