1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pub mod inst_dump_buf;
#[cfg(target_arch = "x86")]
pub mod x86_64;
#[cfg(target_arch = "x86_64")]
pub mod x86_64;

#[derive(Debug, Clone, Copy)]
pub enum ImmByte {
    Bit8,
    Bit16,
    Bit32,
    Bit64,
}

impl ImmByte {
    pub fn encode(self, imm: u64) -> Vec<u8> {
        if let ImmByte::Bit8 = self {
            (imm as u8).to_ne_bytes().to_vec()
        } else if let ImmByte::Bit16 = self {
            (imm as u16).to_ne_bytes().to_vec()
        } else if let ImmByte::Bit32 = self {
            (imm as u32).to_ne_bytes().to_vec()
        } else {
            imm.to_ne_bytes().to_vec()
        }
    }
}