aboutsummaryrefslogtreecommitdiff
path: root/src/generated/opcode.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2022-07-23 18:23:25 -0700
committeriximeow <me@iximeow.net>2023-01-02 08:50:23 -0800
commitd5eafcbc374357a66794297a60c3a7a2b035bff3 (patch)
treec9fb30c6f07c5d446faa0f7a0d89620f5fc9c86a /src/generated/opcode.rs
parente6e7fabfc907eaf016520d9c2a2e128b0d28f019 (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.rs48
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()
+ }
+ }
}