1use crate::formatter::iced_constants::IcedConstants;
5use crate::formatter::iced_error::IcedError;
6use core::iter::{ExactSizeIterator, FusedIterator, Iterator};
7use core::{fmt, mem};
8
9#[allow(missing_copy_implementations)]
13#[allow(missing_debug_implementations)]
14pub struct SymbolFlags;
15impl SymbolFlags {
16 pub const NONE: u32 = 0x0000_0000;
18 pub const RELATIVE: u32 = 0x0000_0001;
20 pub const SIGNED: u32 = 0x0000_0002;
22}
23#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
29#[cfg_attr(not(feature = "exhaustive_enums"), non_exhaustive)]
30pub enum FormatterTextKind {
31 Text = 0,
33 Directive = 1,
35 Prefix = 2,
37 Mnemonic = 3,
39 Keyword = 4,
41 Operator = 5,
43 Punctuation = 6,
45 Number = 7,
47 Register = 8,
49 Decorator = 9,
51 SelectorValue = 10,
53 LabelAddress = 11,
55 FunctionAddress = 12,
57 Data = 13,
59 Label = 14,
61 Function = 15,
63}
64#[rustfmt::skip]
65static GEN_DEBUG_FORMATTER_TEXT_KIND: [&str; 16] = [
66 "Text",
67 "Directive",
68 "Prefix",
69 "Mnemonic",
70 "Keyword",
71 "Operator",
72 "Punctuation",
73 "Number",
74 "Register",
75 "Decorator",
76 "SelectorValue",
77 "LabelAddress",
78 "FunctionAddress",
79 "Data",
80 "Label",
81 "Function",
82];
83impl fmt::Debug for FormatterTextKind {
84 #[inline]
85 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
86 write!(f, "{}", GEN_DEBUG_FORMATTER_TEXT_KIND[*self as usize])
87 }
88}
89impl Default for FormatterTextKind {
90 #[must_use]
91 #[inline]
92 fn default() -> Self {
93 FormatterTextKind::Text
94 }
95}
96#[allow(non_camel_case_types)]
97#[allow(dead_code)]
98pub(crate) type FormatterTextKindUnderlyingType = u8;
99#[rustfmt::skip]
100impl FormatterTextKind {
101 #[inline]
103 pub fn values() -> impl Iterator<Item = FormatterTextKind> + DoubleEndedIterator + ExactSizeIterator + FusedIterator {
104 (0..IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT).map(|x| unsafe { mem::transmute::<u8, FormatterTextKind>(x as u8) })
106 }
107}
108#[test]
109#[rustfmt::skip]
110fn test_formattertextkind_values() {
111 let mut iter = FormatterTextKind::values();
112 assert_eq!(iter.size_hint(), (IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT, Some(IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT)));
113 assert_eq!(iter.len(), IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT);
114 assert!(iter.next().is_some());
115 assert_eq!(iter.size_hint(), (IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT - 1, Some(IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT - 1)));
116 assert_eq!(iter.len(), IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT - 1);
117
118 let values: Vec<FormatterTextKind> = FormatterTextKind::values().collect();
119 assert_eq!(values.len(), IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT);
120 for (i, value) in values.into_iter().enumerate() {
121 assert_eq!(i, value as usize);
122 }
123
124 let values1: Vec<FormatterTextKind> = FormatterTextKind::values().collect();
125 let mut values2: Vec<FormatterTextKind> = FormatterTextKind::values().rev().collect();
126 values2.reverse();
127 assert_eq!(values1, values2);
128}
129#[rustfmt::skip]
130impl TryFrom<usize> for FormatterTextKind {
131 type Error = IcedError;
132 #[inline]
133 fn try_from(value: usize) -> Result<Self, Self::Error> {
134 if value < IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT {
135 Ok(unsafe { mem::transmute(value as u8) })
137 } else {
138 Err(IcedError::new("Invalid FormatterTextKind value"))
139 }
140 }
141}
142#[test]
143#[rustfmt::skip]
144fn test_formattertextkind_try_from_usize() {
145 for value in FormatterTextKind::values() {
146 let converted = <FormatterTextKind as TryFrom<usize>>::try_from(value as usize).unwrap();
147 assert_eq!(converted, value);
148 }
149 assert!(<FormatterTextKind as TryFrom<usize>>::try_from(IcedConstants::FORMATTER_TEXT_KIND_ENUM_COUNT).is_err());
150 assert!(<FormatterTextKind as TryFrom<usize>>::try_from(core::usize::MAX).is_err());
151}
152#[cfg(feature = "serde")]
153#[rustfmt::skip]
154#[allow(clippy::zero_sized_map_values)]
155const _: () = {
156 use core::marker::PhantomData;
157 use serde::de;
158 use serde::{Deserialize, Deserializer, Serialize, Serializer};
159 type EnumType = FormatterTextKind;
160 impl Serialize for EnumType {
161 #[inline]
162 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
163 where
164 S: Serializer,
165 {
166 serializer.serialize_u8(*self as u8)
167 }
168 }
169 impl<'de> Deserialize<'de> for EnumType {
170 #[inline]
171 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
172 where
173 D: Deserializer<'de>,
174 {
175 struct Visitor<'de> {
176 marker: PhantomData<EnumType>,
177 lifetime: PhantomData<&'de ()>,
178 }
179 impl<'de> de::Visitor<'de> for Visitor<'de> {
180 type Value = EnumType;
181 #[inline]
182 fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
183 formatter.write_str("enum FormatterTextKind")
184 }
185 #[inline]
186 fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
187 where
188 E: de::Error,
189 {
190 if let Ok(v) = <usize as TryFrom<_>>::try_from(v) {
191 if let Ok(value) = <EnumType as TryFrom<_>>::try_from(v) {
192 return Ok(value);
193 }
194 }
195 Err(de::Error::invalid_value(de::Unexpected::Unsigned(v), &"a valid FormatterTextKind variant value"))
196 }
197 }
198 deserializer.deserialize_u8(Visitor { marker: PhantomData::<EnumType>, lifetime: PhantomData })
199 }
200 }
201};
202#[derive(Copy, Clone, Eq, PartialEq)]
207#[allow(non_camel_case_types)]
208#[allow(dead_code)]
209pub(crate) enum PseudoOpsKind {
210 cmpps,
211 vcmpps,
212 cmppd,
213 vcmppd,
214 cmpss,
215 vcmpss,
216 cmpsd,
217 vcmpsd,
218 pclmulqdq,
219 vpclmulqdq,
220 vpcomb,
221 vpcomw,
222 vpcomd,
223 vpcomq,
224 vpcomub,
225 vpcomuw,
226 vpcomud,
227 vpcomuq,
228 vpcmpb,
229 vpcmpw,
230 vpcmpd,
231 vpcmpq,
232 vpcmpub,
233 vpcmpuw,
234 vpcmpud,
235 vpcmpuq,
236 vcmpph,
237 vcmpsh,
238 vcmpps8,
239 vcmppd8,
240 vpcmpd6,
241 vpcmpud6,
242}
243#[rustfmt::skip]
244static GEN_DEBUG_PSEUDO_OPS_KIND: [&str; 32] = [
245 "cmpps",
246 "vcmpps",
247 "cmppd",
248 "vcmppd",
249 "cmpss",
250 "vcmpss",
251 "cmpsd",
252 "vcmpsd",
253 "pclmulqdq",
254 "vpclmulqdq",
255 "vpcomb",
256 "vpcomw",
257 "vpcomd",
258 "vpcomq",
259 "vpcomub",
260 "vpcomuw",
261 "vpcomud",
262 "vpcomuq",
263 "vpcmpb",
264 "vpcmpw",
265 "vpcmpd",
266 "vpcmpq",
267 "vpcmpub",
268 "vpcmpuw",
269 "vpcmpud",
270 "vpcmpuq",
271 "vcmpph",
272 "vcmpsh",
273 "vcmpps8",
274 "vcmppd8",
275 "vpcmpd6",
276 "vpcmpud6",
277];
278impl fmt::Debug for PseudoOpsKind {
279 #[inline]
280 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
281 write!(f, "{}", GEN_DEBUG_PSEUDO_OPS_KIND[*self as usize])
282 }
283}
284impl Default for PseudoOpsKind {
285 #[must_use]
286 #[inline]
287 fn default() -> Self {
288 PseudoOpsKind::cmpps
289 }
290}
291#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
297pub enum MemorySizeOptions {
298 Default = 0,
300 Always = 1,
302 Minimal = 2,
304 Never = 3,
306}
307#[rustfmt::skip]
308static GEN_DEBUG_MEMORY_SIZE_OPTIONS: [&str; 4] = [
309 "Default",
310 "Always",
311 "Minimal",
312 "Never",
313];
314impl fmt::Debug for MemorySizeOptions {
315 #[inline]
316 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
317 write!(f, "{}", GEN_DEBUG_MEMORY_SIZE_OPTIONS[*self as usize])
318 }
319}
320impl Default for MemorySizeOptions {
321 #[must_use]
322 #[inline]
323 fn default() -> Self {
324 MemorySizeOptions::Default
325 }
326}
327#[allow(non_camel_case_types)]
328#[allow(dead_code)]
329pub(crate) type MemorySizeOptionsUnderlyingType = u8;
330#[rustfmt::skip]
331impl MemorySizeOptions {
332 #[inline]
334 pub fn values() -> impl Iterator<Item = MemorySizeOptions> + DoubleEndedIterator + ExactSizeIterator + FusedIterator {
335 (0..IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT).map(|x| unsafe { mem::transmute::<u8, MemorySizeOptions>(x as u8) })
337 }
338}
339#[test]
340#[rustfmt::skip]
341fn test_memorysizeoptions_values() {
342 let mut iter = MemorySizeOptions::values();
343 assert_eq!(iter.size_hint(), (IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT, Some(IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT)));
344 assert_eq!(iter.len(), IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT);
345 assert!(iter.next().is_some());
346 assert_eq!(iter.size_hint(), (IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT - 1, Some(IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT - 1)));
347 assert_eq!(iter.len(), IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT - 1);
348
349 let values: Vec<MemorySizeOptions> = MemorySizeOptions::values().collect();
350 assert_eq!(values.len(), IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT);
351 for (i, value) in values.into_iter().enumerate() {
352 assert_eq!(i, value as usize);
353 }
354
355 let values1: Vec<MemorySizeOptions> = MemorySizeOptions::values().collect();
356 let mut values2: Vec<MemorySizeOptions> = MemorySizeOptions::values().rev().collect();
357 values2.reverse();
358 assert_eq!(values1, values2);
359}
360#[rustfmt::skip]
361impl TryFrom<usize> for MemorySizeOptions {
362 type Error = IcedError;
363 #[inline]
364 fn try_from(value: usize) -> Result<Self, Self::Error> {
365 if value < IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT {
366 Ok(unsafe { mem::transmute(value as u8) })
368 } else {
369 Err(IcedError::new("Invalid MemorySizeOptions value"))
370 }
371 }
372}
373#[test]
374#[rustfmt::skip]
375fn test_memorysizeoptions_try_from_usize() {
376 for value in MemorySizeOptions::values() {
377 let converted = <MemorySizeOptions as TryFrom<usize>>::try_from(value as usize).unwrap();
378 assert_eq!(converted, value);
379 }
380 assert!(<MemorySizeOptions as TryFrom<usize>>::try_from(IcedConstants::MEMORY_SIZE_OPTIONS_ENUM_COUNT).is_err());
381 assert!(<MemorySizeOptions as TryFrom<usize>>::try_from(core::usize::MAX).is_err());
382}
383#[cfg(feature = "serde")]
384#[rustfmt::skip]
385#[allow(clippy::zero_sized_map_values)]
386const _: () = {
387 use core::marker::PhantomData;
388 use serde::de;
389 use serde::{Deserialize, Deserializer, Serialize, Serializer};
390 type EnumType = MemorySizeOptions;
391 impl Serialize for EnumType {
392 #[inline]
393 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
394 where
395 S: Serializer,
396 {
397 serializer.serialize_u8(*self as u8)
398 }
399 }
400 impl<'de> Deserialize<'de> for EnumType {
401 #[inline]
402 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
403 where
404 D: Deserializer<'de>,
405 {
406 struct Visitor<'de> {
407 marker: PhantomData<EnumType>,
408 lifetime: PhantomData<&'de ()>,
409 }
410 impl<'de> de::Visitor<'de> for Visitor<'de> {
411 type Value = EnumType;
412 #[inline]
413 fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
414 formatter.write_str("enum MemorySizeOptions")
415 }
416 #[inline]
417 fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
418 where
419 E: de::Error,
420 {
421 if let Ok(v) = <usize as TryFrom<_>>::try_from(v) {
422 if let Ok(value) = <EnumType as TryFrom<_>>::try_from(v) {
423 return Ok(value);
424 }
425 }
426 Err(de::Error::invalid_value(de::Unexpected::Unsigned(v), &"a valid MemorySizeOptions variant value"))
427 }
428 }
429 deserializer.deserialize_u8(Visitor { marker: PhantomData::<EnumType>, lifetime: PhantomData })
430 }
431 }
432};
433