From d5eafcbc374357a66794297a60c3a7a2b035bff3 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 23 Jul 2022 18:23:25 -0700 Subject: codegen `Colorized` impl and normalize `name()` implementation unfortunately because of the layout of instruction information this *adds* lines rather than removes them.. --- src/generated/opcode.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/generated/opcode.rs') 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) } + } + + 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) } + } + + 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) } + } + + fn nane(&self) -> &'static str { + self.to_generic().name() + } + } } -- cgit v1.1