unicorn/
macros.rs

1macro_rules! implement_register {
2    ($reg_arch:ty) => {
3        impl Register for $reg_arch {
4            fn to_i32(&self) -> i32 {
5                *self as i32
6            }
7        }
8    };
9}
10
11macro_rules! implement_emulator {
12    ($emu_type_doc:meta, $emu_instance_doc:meta, $cpu:ident, $arch:expr, $reg:ty) => {
13        #[$emu_type_doc]
14        pub struct $cpu {
15            emu: Box<Unicorn>,
16        }
17
18        impl $cpu {
19            #[$emu_instance_doc]
20            pub fn new(mode: Mode) -> Result<Self> {
21                let emu = Unicorn::new($arch, mode);
22                match emu {
23                    Ok(x) => Ok(Self { emu: x }),
24                    Err(x) => Err(x),
25                }
26            }
27        }
28
29        impl Cpu for $cpu {
30            type Reg = $reg;
31
32            fn emu(&self) -> &Unicorn {
33                &self.emu
34            }
35
36            fn mut_emu(&mut self) -> &mut Unicorn {
37                &mut self.emu
38            }
39        }
40    };
41}
42
43macro_rules! destructure_hook {
44    ($hook_type:path, $hook:ident) => {{
45        let $hook_type {
46            unicorn,
47            ref mut callback,
48        } = unsafe { &mut *$hook };
49        (unsafe { &**unicorn }, callback)
50    }};
51}