diff options
author | iximeow <me@iximeow.net> | 2022-07-23 18:23:25 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2023-01-02 08:50:23 -0800 |
commit | d5eafcbc374357a66794297a60c3a7a2b035bff3 (patch) | |
tree | c9fb30c6f07c5d446faa0f7a0d89620f5fc9c86a /src/generated/opcode.rs | |
parent | e6e7fabfc907eaf016520d9c2a2e128b0d28f019 (diff) |
codegen `Colorized` impl and normalize `name()` implementation
unfortunately because of the layout of instruction information this
*adds* lines rather than removes them..
Diffstat (limited to 'src/generated/opcode.rs')
-rw-r--r-- | src/generated/opcode.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/generated/opcode.rs b/src/generated/opcode.rs index cc573f1..5fa5892 100644 --- a/src/generated/opcode.rs +++ b/src/generated/opcode.rs @@ -1,3 +1,5 @@ +use crate::safer_unchecked::GetSaferUnchecked; + #[allow(non_camel_case_types)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] #[non_exhaustive] @@ -2874,6 +2876,16 @@ pub(crate) const MNEMONICS: &'static [&'static str] = &[ "xtest", ]; +impl Opcode { + pub(crate) fn name(&self) -> &'static str { + // safety: `MNEMONICS` and `Opcode` are generated together, where every entry in `Opcode` guarantees + // a corresponding entry in `MNEMONICS`. + unsafe { + MNEMONICS.get_kinda_unchecked(*self as usize) + } + } +} + pub(crate) mod real_mode { #[allow(non_camel_case_types)] #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -4312,6 +4324,18 @@ pub(crate) mod real_mode { XSUSLDTRK = super::Opcode::XSUSLDTRK as u16, XTEST = super::Opcode::XTEST as u16, } + + impl Opcode { + pub fn to_generic(&self) -> super::Opcode { + // safety: each item in `Self` is defined with the same value in `super::Opcode`. `Self` is + // a subset of `super::Opcode` so casting to the more generic form is well-defined. + unsafe { core::mem::transmute::<Self, super::Opcode>(*self) } + } + + fn nane(&self) -> &'static str { + self.to_generic().name() + } + } } pub(crate) mod protected_mode { @@ -5752,6 +5776,18 @@ pub(crate) mod protected_mode { XSUSLDTRK = super::Opcode::XSUSLDTRK as u16, XTEST = super::Opcode::XTEST as u16, } + + impl Opcode { + pub fn to_generic(&self) -> super::Opcode { + // safety: each item in `Self` is defined with the same value in `super::Opcode`. `Self` is + // a subset of `super::Opcode` so casting to the more generic form is well-defined. + unsafe { core::mem::transmute::<Self, super::Opcode>(*self) } + } + + fn nane(&self) -> &'static str { + self.to_generic().name() + } + } } pub(crate) mod long_mode { @@ -7182,5 +7218,17 @@ pub(crate) mod long_mode { XSUSLDTRK = super::Opcode::XSUSLDTRK as u16, XTEST = super::Opcode::XTEST as u16, } + + impl Opcode { + pub fn to_generic(&self) -> super::Opcode { + // safety: each item in `Self` is defined with the same value in `super::Opcode`. `Self` is + // a subset of `super::Opcode` so casting to the more generic form is well-defined. + unsafe { core::mem::transmute::<Self, super::Opcode>(*self) } + } + + fn nane(&self) -> &'static str { + self.to_generic().name() + } + } } |