osom_encoders_x86_64/encoders/encoding_funcs/
mnemonics_gen.rs

1//! # Auto-generated
2//!
3//! This file was generated by a build script.
4//!
5//! The build script monitors this file and regenerates it on changes.
6//! Manual modifications will be lost.
7#![allow(non_camel_case_types)]
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub struct InvalidMnemonicError;
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13#[repr(u8)]
14#[must_use]
15pub enum Mnemonic {
16    nop = 1,
17    lock = 2,
18    cpuid = 3,
19    ret = 4,
20    mov = 5,
21    push = 6,
22    pop = 7,
23    lea = 8,
24    add = 9,
25    sub = 10,
26    xor = 11,
27    cmp = 12,
28    jmp = 13,
29    jcc = 14,
30    call = 15,
31    int = 16,
32    sysenter = 17,
33    syscall = 18,
34}
35
36impl Mnemonic {
37    #[inline]
38    #[must_use]
39    pub const fn as_str(self) -> &'static str {
40        match self {
41            Self::nop => "nop",
42            Self::lock => "lock",
43            Self::cpuid => "cpuid",
44            Self::ret => "ret",
45            Self::mov => "mov",
46            Self::push => "push",
47            Self::pop => "pop",
48            Self::lea => "lea",
49            Self::add => "add",
50            Self::sub => "sub",
51            Self::xor => "xor",
52            Self::cmp => "cmp",
53            Self::jmp => "jmp",
54            Self::jcc => "jcc",
55            Self::call => "call",
56            Self::int => "int",
57            Self::sysenter => "sysenter",
58            Self::syscall => "syscall",
59        }
60    }
61
62    #[inline]
63    pub fn from_str(text: &str) -> Result<Self, InvalidMnemonicError> {
64        match text {
65            "nop" => Ok(Self::nop),
66            "lock" => Ok(Self::lock),
67            "cpuid" => Ok(Self::cpuid),
68            "ret" => Ok(Self::ret),
69            "mov" => Ok(Self::mov),
70            "push" => Ok(Self::push),
71            "pop" => Ok(Self::pop),
72            "lea" => Ok(Self::lea),
73            "add" => Ok(Self::add),
74            "sub" => Ok(Self::sub),
75            "xor" => Ok(Self::xor),
76            "cmp" => Ok(Self::cmp),
77            "jmp" => Ok(Self::jmp),
78            "jcc" => Ok(Self::jcc),
79            "call" => Ok(Self::call),
80            "int" => Ok(Self::int),
81            "sysenter" => Ok(Self::sysenter),
82            "syscall" => Ok(Self::syscall),
83
84            _ => Err(InvalidMnemonicError),
85        }
86    }
87}
88
89const _: () = const {
90    assert!(
91        size_of::<InvalidMnemonicError>() == 0,
92        "InvalidMnemonicError must be 0 bytes."
93    );
94    assert!(size_of::<Mnemonic>() == 1, "Mnemonic must be 1 byte.");
95    assert!(size_of::<Option<Mnemonic>>() == 1, "Option<Mnemonic> must be 1 byte.");
96};