1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
use crate::block_enc::iced_constants::IcedConstants;
use crate::block_enc::iced_error::IcedError;
use core::fmt;
use core::iter::{ExactSizeIterator, FusedIterator, Iterator};
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(not(feature = "exhaustive_enums"), non_exhaustive)]
pub enum RelocKind {
Offset64 = 0,
}
#[rustfmt::skip]
static GEN_DEBUG_RELOC_KIND: [&str; 1] = [
"Offset64",
];
impl fmt::Debug for RelocKind {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", GEN_DEBUG_RELOC_KIND[*self as usize])
}
}
impl Default for RelocKind {
#[must_use]
#[inline]
fn default() -> Self {
RelocKind::Offset64
}
}
#[allow(non_camel_case_types)]
#[allow(dead_code)]
pub(crate) type RelocKindUnderlyingType = ();
#[rustfmt::skip]
impl RelocKind {
#[inline]
pub fn values() -> impl Iterator<Item = RelocKind> + DoubleEndedIterator + ExactSizeIterator + FusedIterator {
static VALUES: [RelocKind; 1] = [RelocKind::Offset64];
VALUES.iter().copied()
}
}
#[test]
#[rustfmt::skip]
fn test_relockind_values() {
let mut iter = RelocKind::values();
assert_eq!(iter.size_hint(), (IcedConstants::RELOC_KIND_ENUM_COUNT, Some(IcedConstants::RELOC_KIND_ENUM_COUNT)));
assert_eq!(iter.len(), IcedConstants::RELOC_KIND_ENUM_COUNT);
assert!(iter.next().is_some());
assert_eq!(iter.size_hint(), (IcedConstants::RELOC_KIND_ENUM_COUNT - 1, Some(IcedConstants::RELOC_KIND_ENUM_COUNT - 1)));
assert_eq!(iter.len(), IcedConstants::RELOC_KIND_ENUM_COUNT - 1);
let values: Vec<RelocKind> = RelocKind::values().collect();
assert_eq!(values.len(), IcedConstants::RELOC_KIND_ENUM_COUNT);
for (i, value) in values.into_iter().enumerate() {
assert_eq!(i, value as usize);
}
let values1: Vec<RelocKind> = RelocKind::values().collect();
let mut values2: Vec<RelocKind> = RelocKind::values().rev().collect();
values2.reverse();
assert_eq!(values1, values2);
}
#[rustfmt::skip]
impl TryFrom<usize> for RelocKind {
type Error = IcedError;
#[inline]
fn try_from(value: usize) -> Result<Self, Self::Error> {
if value < IcedConstants::RELOC_KIND_ENUM_COUNT {
Ok(RelocKind::Offset64)
} else {
Err(IcedError::new("Invalid RelocKind value"))
}
}
}
#[test]
#[rustfmt::skip]
fn test_relockind_try_from_usize() {
for value in RelocKind::values() {
let converted = <RelocKind as TryFrom<usize>>::try_from(value as usize).unwrap();
assert_eq!(converted, value);
}
assert!(<RelocKind as TryFrom<usize>>::try_from(IcedConstants::RELOC_KIND_ENUM_COUNT).is_err());
assert!(<RelocKind as TryFrom<usize>>::try_from(core::usize::MAX).is_err());
}
#[cfg(feature = "serde")]
#[rustfmt::skip]
#[allow(clippy::zero_sized_map_values)]
const _: () = {
use alloc::string::String;
use core::marker::PhantomData;
use serde::de::{self, VariantAccess};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
type EnumType = RelocKind;
impl Serialize for EnumType {
#[inline]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_unit_variant("RelocKind", *self as u32, GEN_DEBUG_RELOC_KIND[*self as usize])
}
}
impl<'de> Deserialize<'de> for EnumType {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
struct EnumValue(EnumType);
struct EnumValueVisitor;
impl<'de> de::Visitor<'de> for EnumValueVisitor {
type Value = EnumValue;
#[inline]
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("variant identifier")
}
#[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(EnumValue(value));
}
}
Err(de::Error::invalid_value(de::Unexpected::Unsigned(v), &"a valid RelocKind variant value"))
}
#[inline]
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
EnumValueVisitor::deserialize_name(v.as_bytes())
}
#[inline]
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
where
E: de::Error,
{
EnumValueVisitor::deserialize_name(v)
}
}
impl EnumValueVisitor {
#[inline]
fn deserialize_name<E>(v: &[u8]) -> Result<EnumValue, E>
where
E: de::Error,
{
for (&name, value) in GEN_DEBUG_RELOC_KIND.iter().zip(EnumType::values()) {
if name.as_bytes() == v {
return Ok(EnumValue(value));
}
}
Err(de::Error::unknown_variant(&String::from_utf8_lossy(v), &["RelocKind enum variants"][..]))
}
}
impl<'de> Deserialize<'de> for EnumValue {
#[inline]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_identifier(EnumValueVisitor)
}
}
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 RelocKind")
}
#[inline]
fn visit_enum<A>(self, data: A) -> Result<Self::Value, A::Error>
where
A: de::EnumAccess<'de>,
{
let (field, variant): (EnumValue, _) = data.variant()?;
match variant.unit_variant() {
Ok(_) => Ok(field.0),
Err(err) => Err(err),
}
}
}
deserializer.deserialize_enum("RelocKind", &GEN_DEBUG_RELOC_KIND[..], Visitor { marker: PhantomData::<EnumType>, lifetime: PhantomData })
}
}
};
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub struct BlockEncoderOptions;
impl BlockEncoderOptions {
pub const NONE: u32 = 0x0000_0000;
pub const DONT_FIX_BRANCHES: u32 = 0x0000_0001;
pub const RETURN_RELOC_INFOS: u32 = 0x0000_0002;
pub const RETURN_NEW_INSTRUCTION_OFFSETS: u32 = 0x0000_0004;
pub const RETURN_CONSTANT_OFFSETS: u32 = 0x0000_0008;
}