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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#[derive(Debug)]
pub enum IrError {
FunctionLocalClobbered(String, String),
InvalidMetadatum(String),
InvalidPhi,
MisplacedTerminator(String),
MissingBlock(String),
MissingTerminator(String),
ParseFailure(String, String),
RemoveMissingBlock(String),
ValueNotFound(String),
VerifyAccessElementInconsistentTypes,
VerifyAccessElementOnNonArray,
VerifyAccessElementNonIntIndex,
VerifyAccessValueInconsistentTypes,
VerifyAccessValueInvalidIndices,
VerifyAccessValueOnNonStruct,
VerifyArgumentValueIsNotArgument(String),
VerifyAddrOfUnknownSourceType,
VerifyAddrOfCopyType,
VerifyBitcastUnknownSourceType,
VerifyBitcastFromNonCopyType(String),
VerifyBitcastToNonCopyType(String),
VerifyBitcastBetweenInvalidTypes(String, String),
VerifyBranchToMissingBlock(String),
VerifyCallArgTypeMismatch(String),
VerifyCallToMissingFunction(String),
VerifyCmpBadTypes(String, String),
VerifyCmpTypeMismatch(String, String),
VerifyCmpUnknownTypes,
VerifyConditionExprNotABool,
VerifyContractCallBadTypes(String),
VerifyGetNonExistentPointer,
VerifyInsertElementOfIncorrectType,
VerifyInsertValueOfIncorrectType,
VerifyIntToPtrFromNonIntegerType(String),
VerifyIntToPtrToCopyType(String),
VerifyIntToPtrUnknownSourceType,
VerifyLoadFromNonPointer,
VerifyMismatchedReturnTypes(String),
VerifyPhiFromMissingBlock(String),
VerifyPhiInconsistentTypes,
VerifyPhiNonUniqueLabels,
VerifyPtrCastFromNonPointer,
VerifyStateKeyBadType,
VerifyStateDestBadType(String),
VerifyStoreMismatchedTypes,
VerifyStoreNonExistentPointer,
VerifyStoreToNonPointer,
VerifyUntypedValuePassedToFunction,
VerifyInvalidGtfIndexType,
}
impl std::error::Error for IrError {}
use std::fmt;
impl fmt::Display for IrError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self {
IrError::FunctionLocalClobbered(fn_str, var_str) => write!(
f,
"Local storage for function {fn_str} already has an entry for variable {var_str}."
),
IrError::InvalidMetadatum(why_str) => {
write!(f, "Unable to convert from invalid metadatum: {why_str}.")
}
IrError::InvalidPhi => write!(
f,
"Phi instruction has invalid block or value reference list."
),
IrError::MisplacedTerminator(blk_str) => {
write!(f, "Block {blk_str} has a misplaced terminator.")
}
IrError::MissingBlock(blk_str) => write!(f, "Unable to find block {blk_str}."),
IrError::MissingTerminator(blk_str) => {
write!(f, "Block {blk_str} is missing its terminator.")
}
IrError::ParseFailure(expecting, found) => {
write!(
f,
"Parse failure: expecting '{expecting}', found '{found}'."
)
}
IrError::RemoveMissingBlock(blk_str) => {
write!(f, "Unable to remove block {blk_str}; not found.")
}
IrError::ValueNotFound(reason) => {
write!(f, "Invalid value: {reason}.")
}
IrError::VerifyAccessElementNonIntIndex => {
write!(
f,
"Verification failed: Array index is not an integral type."
)
}
IrError::VerifyAccessElementInconsistentTypes => {
write!(
f,
"Verification failed: Array type mismatch in when accessing array element."
)
}
IrError::VerifyAccessElementOnNonArray => {
write!(
f,
"Verification failed: Attempt to access an element from a non array."
)
}
IrError::VerifyAccessValueInconsistentTypes => {
write!(f, "Verification failed: Struct field type mismatch.")
}
IrError::VerifyAccessValueInvalidIndices => {
write!(
f,
"Verification failed: Struct index to non-existent field."
)
}
IrError::VerifyAccessValueOnNonStruct => {
write!(
f,
"Verification failed: Attempt to access a field from a non struct."
)
}
IrError::VerifyArgumentValueIsNotArgument(callee) => write!(
f,
"Verification failed: Argument specifier for function '{callee}' is not an \
argument value."
),
IrError::VerifyAddrOfUnknownSourceType => write!(
f,
"Verification failed: addr_of unable to determine source type."
),
IrError::VerifyAddrOfCopyType => write!(
f,
"Verification failed: addr_of argument must be non-copy (memory) type."
),
IrError::VerifyBitcastUnknownSourceType => write!(
f,
"Verification failed: Bitcast unable to determine source type."
),
IrError::VerifyBitcastFromNonCopyType(ty) => {
write!(f, "Verification failed: Bitcast cannot be from a {ty}.")
}
IrError::VerifyBitcastToNonCopyType(ty) => {
write!(f, "Verification failed: Bitcast cannot be to a {ty}.")
}
IrError::VerifyBitcastBetweenInvalidTypes(from_ty, to_ty) => write!(
f,
"Verification failed: Bitcast not allowed from a {from_ty} to a {to_ty}."
),
IrError::VerifyBranchToMissingBlock(label) => {
write!(
f,
"Verification failed: Branch to block '{label}' is not a block in the current \
function."
)
}
IrError::VerifyCallArgTypeMismatch(callee) => {
write!(
f,
"Verification failed: Type mismatch found for call to '{callee}'."
)
}
IrError::VerifyCallToMissingFunction(callee) => {
write!(
f,
"Verification failed: Call to invalid function '{callee}'."
)
}
IrError::VerifyCmpBadTypes(lhs_ty, rhs_ty) => {
write!(
f,
"Verification failed: Cannot compare non-integer types {lhs_ty} and {rhs_ty}."
)
}
IrError::VerifyCmpTypeMismatch(lhs_ty, rhs_ty) => {
write!(
f,
"Verification failed: Cannot compare values with different widths of {lhs_ty} \
and {rhs_ty}."
)
}
IrError::VerifyCmpUnknownTypes => {
write!(
f,
"Verification failed: Unable to determine type(s) of compared value(s)."
)
}
IrError::VerifyConditionExprNotABool => {
write!(
f,
"Verification failed: Expression used for conditional is not a boolean."
)
}
IrError::VerifyContractCallBadTypes(arg_name) => {
write!(
f,
"Verification failed: Argument {arg_name} passed to contract call has the \
incorrect type."
)
}
IrError::VerifyGetNonExistentPointer => {
write!(
f,
"Verification failed: Attempt to get pointer not found in function locals."
)
}
IrError::VerifyInsertElementOfIncorrectType => {
write!(
f,
"Verification failed: Attempt to insert value of incorrect type into an array."
)
}
IrError::VerifyInsertValueOfIncorrectType => {
write!(
f,
"Verification failed: Attempt to insert value of incorrect type into a struct."
)
}
IrError::VerifyIntToPtrFromNonIntegerType(ty) => {
write!(f, "Verification failed: int_to_ptr cannot be from a {ty}.")
}
IrError::VerifyIntToPtrToCopyType(ty) => {
write!(f, "Verification failed: int_to_ptr cannot be to a {ty}.")
}
IrError::VerifyIntToPtrUnknownSourceType => write!(
f,
"Verification failed: int_to_ptr unable to determine source type."
),
IrError::VerifyLoadFromNonPointer => {
write!(f, "Verification failed: Load must be from a pointer.")
}
IrError::VerifyMismatchedReturnTypes(fn_str) => write!(
f,
"Verification failed: Function {fn_str} return type must match its RET \
instructions."
),
IrError::VerifyPhiFromMissingBlock(label) => {
write!(
f,
"Verification failed: PHI has a block '{label}'not from the current function."
)
}
IrError::VerifyPhiInconsistentTypes => {
write!(f, "Verification failed: PHI has inconsistent types.")
}
IrError::VerifyPhiNonUniqueLabels => {
write!(f, "Verification failed: PHI must have unique block labels.")
}
IrError::VerifyPtrCastFromNonPointer => {
write!(
f,
"Verification failed: Pointer cast from non pointer value."
)
}
IrError::VerifyStateKeyBadType => {
write!(
f,
"Verification failed: State load or store key must be a b256 pointer."
)
}
IrError::VerifyStateDestBadType(ty) => {
write!(
f,
"Verification failed: State access operation must be to a {ty} pointer."
)
}
IrError::VerifyStoreMismatchedTypes => {
write!(
f,
"Verification failed: Store value and pointer type mismatch."
)
}
IrError::VerifyStoreNonExistentPointer => write!(
f,
"Verification failed: Attempt to store to a pointer not found in function locals."
),
IrError::VerifyStoreToNonPointer => write!(f, "Store must be to a pointer."),
IrError::VerifyUntypedValuePassedToFunction => write!(
f,
"Verification failed: An untyped/void value has been passed to a function call."
),
IrError::VerifyInvalidGtfIndexType => write!(
f,
"Verification failed: An non-integer value has been passed to a 'gtf' instruction."
),
}
}
}