osom_asm_x86_64/models/
gpr_kind.rs

1#![allow(non_upper_case_globals)]
2
3use super::Size;
4use osom_encoders_x86_64::models as enc_models;
5
6/// Represents the kind of a general purpose register.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8#[repr(transparent)]
9#[must_use]
10pub struct GPRKind {
11    value: enc_models::GPRKind,
12}
13
14impl GPRKind {
15    /// Represents AH, BH, CH and DH registers.
16    pub const Bit8High: Self = Self::new(enc_models::GPRKind::Bit8High);
17
18    /// Represents AL, CL, DL, BL, SPL, BPL, SIL, DIL, R8B, R9B, R10B, R11B, R12B, R13B, R14B and R15B registers.
19    pub const Bit8: Self = Self::new(enc_models::GPRKind::Bit8);
20
21    /// Represents AX, CX, DX, BX, SP, BP, SI, DI, R8W, R9W, R10W, R11W, R12W, R13W, R14W and R15W registers.
22    pub const Bit16: Self = Self::new(enc_models::GPRKind::Bit16);
23
24    /// Represents EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI, R8D, R9D, R10D, R11D, R12D, R13D, R14D and R15D registers.
25    pub const Bit32: Self = Self::new(enc_models::GPRKind::Bit32);
26
27    /// Represents RAX, RCX, RDX, RBX, RSP, RBP, RSI, RDI, R8, R9, R10, R11, R12, R13, R14 and R15 registers.
28    pub const Bit64: Self = Self::new(enc_models::GPRKind::Bit64);
29
30    #[inline(always)]
31    pub(crate) const fn new(gpr: enc_models::GPRKind) -> Self {
32        Self { value: gpr }
33    }
34
35    #[inline(always)]
36    pub const fn size(self) -> Size {
37        Size::new(self.value.size())
38    }
39
40    #[inline(always)]
41    #[must_use]
42    pub const fn equals(self, other: Self) -> bool {
43        self.value.equals(other.value)
44    }
45
46    #[inline(always)]
47    pub(crate) fn as_enc_gpr_kind(self) -> enc_models::GPRKind {
48        self.value
49    }
50}
51
52impl From<enc_models::GPRKind> for GPRKind {
53    #[inline(always)]
54    fn from(gpr: enc_models::GPRKind) -> Self {
55        Self { value: gpr }
56    }
57}
58
59impl From<GPRKind> for enc_models::GPRKind {
60    #[inline(always)]
61    fn from(gpr: GPRKind) -> Self {
62        gpr.value
63    }
64}