use crate::formatter::iced_constants::IcedConstants;
use crate::formatter::iced_error::IcedError;
use core::iter::{ExactSizeIterator, FusedIterator, Iterator};
use core::{fmt, mem};
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub struct SymbolFlags;
impl SymbolFlags {
pub const NONE: u32 = 0x0000_0000;
pub const RELATIVE: u32 = 0x0000_0001;
pub const SIGNED: u32 = 0x0000_0002;
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(not(feature = "exhaustive_enums"), non_exhaustive)]
pub enum FormatterTextKind {
Text = 0,
Directive = 1,
Prefix = 2,
Mnemonic = 3,
Keyword = 4,
Operator = 5,
Punctuation = 6,
Number = 7,
Register = 8,
Decorator = 9,
SelectorValue = 10,
LabelAddress = 11,
FunctionAddress = 12,
Data = 13,
Label = 14,
Function = 15,
}
#[rustfmt::skip]
static GEN_DEBUG_FORMATTER_TEXT_KIND: [&str; 16] = [
"Text",
"Directive",
"Prefix",
"Mnemonic",
"Keyword",
"Operator",
"Punctuation",
"Number",
"Register",
"Decorator",
"SelectorValue",
"LabelAddress",
"FunctionAddress",
"Data",
"Label",
"Function",
];
impl fmt::Debug for FormatterTextKind {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", GEN_DEBUG_FORMATTER_TEXT_KIND[*self as usize])
}
}
impl Default for FormatterTextKind {
#[must_use]
#[inline]
fn default() -> Self {
FormatterTextKind::Text
}
}
#[allow(non_camel_case_types)]
#[allow(dead_code)]
pub(crate) type FormatterTextKindUnderlyingType = u8;
#[rustfmt::skip]
impl FormatterTextKind {
#[inline]
pub fn values() -> impl Iterator<Item = FormatterTextKind> + DoubleEndedIterator + ExactSizeIterator + FusedIterator {
(0..IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT).map(|x| unsafe { mem::transmute::<u8, FormatterTextKind>(x as u8) })
}
}
#[test]
#[rustfmt::skip]
fn test_formattertextkind_values() {
let mut iter = FormatterTextKind::values();
assert_eq!(iter.size_hint(), (IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT, Some(IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT)));
assert_eq!(iter.len(), IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT);
assert!(iter.next().is_some());
assert_eq!(iter.size_hint(), (IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT - 1, Some(IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT - 1)));
assert_eq!(iter.len(), IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT - 1);
let values: Vec<FormatterTextKind> = FormatterTextKind::values().collect();
assert_eq!(values.len(), IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT);
for (i, value) in values.into_iter().enumerate() {
assert_eq!(i, value as usize);
}
let values1: Vec<FormatterTextKind> = FormatterTextKind::values().collect();
let mut values2: Vec<FormatterTextKind> = FormatterTextKind::values().rev().collect();
values2.reverse();
assert_eq!(values1, values2);
}
#[rustfmt::skip]
impl TryFrom<usize> for FormatterTextKind {
type Error = IcedError;
#[inline]
fn try_from(value: usize) -> Result<Self, Self::Error> {
if value < IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT {
Ok(unsafe { mem::transmute(value as u8) })
} else {
Err(IcedError::new("Invalid FormatterTextKind value"))
}
}
}
#[test]
#[rustfmt::skip]
fn test_formattertextkind_try_from_usize() {
for value in FormatterTextKind::values() {
let converted = <FormatterTextKind as TryFrom<usize>>::try_from(value as usize).unwrap();
assert_eq!(converted, value);
}
assert!(<FormatterTextKind as TryFrom<usize>>::try_from(IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT).is_err());
assert!(<FormatterTextKind as TryFrom<usize>>::try_from(core::usize::MAX).is_err());
}
#[cfg(feature = "serde")]
#[rustfmt::skip]
#[allow(clippy::zero_sized_map_values)]
const _: () = {
use core::marker::PhantomData;
use serde::de;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
type EnumType = FormatterTextKind;
impl Serialize for EnumType {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_u8(*self as u8)
}
}
impl<'de> Deserialize<'de> for EnumType {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct Visitor<'de> {
marker: PhantomData<EnumType>,
lifetime: PhantomData<&'de ()>,
}
impl<'de> de::Visitor<'de> for Visitor<'de> {
type Value = EnumType;
#[inline]
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("enum FormatterTextKind")
}
#[inline]
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
where
E: de::Error,
{
if let Ok(v) = <usize as TryFrom<_>>::try_from(v) {
if let Ok(value) = <EnumType as TryFrom<_>>::try_from(v) {
return Ok(value);
}
}
Err(de::Error::invalid_value(de::Unexpected::Unsigned(v), &"a valid FormatterTextKind variant value"))
}
}
deserializer.deserialize_u8(Visitor { marker: PhantomData::<EnumType>, lifetime: PhantomData })
}
}
};
#[derive(Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
#[allow(dead_code)]
pub(crate) enum PseudoOpsKind {
cmpps,
vcmpps,
cmppd,
vcmppd,
cmpss,
vcmpss,
cmpsd,
vcmpsd,
pclmulqdq,
vpclmulqdq,
vpcomb,
vpcomw,
vpcomd,
vpcomq,
vpcomub,
vpcomuw,
vpcomud,
vpcomuq,
vpcmpb,
vpcmpw,
vpcmpd,
vpcmpq,
vpcmpub,
vpcmpuw,
vpcmpud,
vpcmpuq,
vcmpph,
vcmpsh,
vcmpps8,
vcmppd8,
vpcmpd6,
vpcmpud6,
}
#[rustfmt::skip]
static GEN_DEBUG_PSEUDO_OPS_KIND: [&str; 32] = [
"cmpps",
"vcmpps",
"cmppd",
"vcmppd",
"cmpss",
"vcmpss",
"cmpsd",
"vcmpsd",
"pclmulqdq",
"vpclmulqdq",
"vpcomb",
"vpcomw",
"vpcomd",
"vpcomq",
"vpcomub",
"vpcomuw",
"vpcomud",
"vpcomuq",
"vpcmpb",
"vpcmpw",
"vpcmpd",
"vpcmpq",
"vpcmpub",
"vpcmpuw",
"vpcmpud",
"vpcmpuq",
"vcmpph",
"vcmpsh",
"vcmpps8",
"vcmppd8",
"vpcmpd6",
"vpcmpud6",
];
impl fmt::Debug for PseudoOpsKind {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", GEN_DEBUG_PSEUDO_OPS_KIND[*self as usize])
}
}
impl Default for PseudoOpsKind {
#[must_use]
#[inline]
fn default() -> Self {
PseudoOpsKind::cmpps
}
}
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum MemorySizeOptions {
Default = 0,
Always = 1,
Minimal = 2,
Never = 3,
}
#[rustfmt::skip]
static GEN_DEBUG_MEMORY_SIZE_OPTIONS: [&str; 4] = [
"Default",
"Always",
"Minimal",
"Never",
];
impl fmt::Debug for MemorySizeOptions {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", GEN_DEBUG_MEMORY_SIZE_OPTIONS[*self as usize])
}
}
impl Default for MemorySizeOptions {
#[must_use]
#[inline]
fn default() -> Self {
MemorySizeOptions::Default
}
}
#[allow(non_camel_case_types)]
#[allow(dead_code)]
pub(crate) type MemorySizeOptionsUnderlyingType = u8;
#[rustfmt::skip]
impl MemorySizeOptions {
#[inline]
pub fn values() -> impl Iterator<Item = MemorySizeOptions> + DoubleEndedIterator + ExactSizeIterator + FusedIterator {
(0..IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT).map(|x| unsafe { mem::transmute::<u8, MemorySizeOptions>(x as u8) })
}
}
#[test]
#[rustfmt::skip]
fn test_memorysizeoptions_values() {
let mut iter = MemorySizeOptions::values();
assert_eq!(iter.size_hint(), (IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT, Some(IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT)));
assert_eq!(iter.len(), IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT);
assert!(iter.next().is_some());
assert_eq!(iter.size_hint(), (IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT - 1, Some(IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT - 1)));
assert_eq!(iter.len(), IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT - 1);
let values: Vec<MemorySizeOptions> = MemorySizeOptions::values().collect();
assert_eq!(values.len(), IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT);
for (i, value) in values.into_iter().enumerate() {
assert_eq!(i, value as usize);
}
let values1: Vec<MemorySizeOptions> = MemorySizeOptions::values().collect();
let mut values2: Vec<MemorySizeOptions> = MemorySizeOptions::values().rev().collect();
values2.reverse();
assert_eq!(values1, values2);
}
#[rustfmt::skip]
impl TryFrom<usize> for MemorySizeOptions {
type Error = IcedError;
#[inline]
fn try_from(value: usize) -> Result<Self, Self::Error> {
if value < IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT {
Ok(unsafe { mem::transmute(value as u8) })
} else {
Err(IcedError::new("Invalid MemorySizeOptions value"))
}
}
}
#[test]
#[rustfmt::skip]
fn test_memorysizeoptions_try_from_usize() {
for value in MemorySizeOptions::values() {
let converted = <MemorySizeOptions as TryFrom<usize>>::try_from(value as usize).unwrap();
assert_eq!(converted, value);
}
assert!(<MemorySizeOptions as TryFrom<usize>>::try_from(IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT).is_err());
assert!(<MemorySizeOptions as TryFrom<usize>>::try_from(core::usize::MAX).is_err());
}
#[cfg(feature = "serde")]
#[rustfmt::skip]
#[allow(clippy::zero_sized_map_values)]
const _: () = {
use core::marker::PhantomData;
use serde::de;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
type EnumType = MemorySizeOptions;
impl Serialize for EnumType {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_u8(*self as u8)
}
}
impl<'de> Deserialize<'de> for EnumType {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct Visitor<'de> {
marker: PhantomData<EnumType>,
lifetime: PhantomData<&'de ()>,
}
impl<'de> de::Visitor<'de> for Visitor<'de> {
type Value = EnumType;
#[inline]
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("enum MemorySizeOptions")
}
#[inline]
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
where
E: de::Error,
{
if let Ok(v) = <usize as TryFrom<_>>::try_from(v) {
if let Ok(value) = <EnumType as TryFrom<_>>::try_from(v) {
return Ok(value);
}
}
Err(de::Error::invalid_value(de::Unexpected::Unsigned(v), &"a valid MemorySizeOptions variant value"))
}
}
deserializer.deserialize_u8(Visitor { marker: PhantomData::<EnumType>, lifetime: PhantomData })
}
}
};