-
-
Notifications
You must be signed in to change notification settings - Fork 990
Expand file tree
/
Copy pathop.rs
More file actions
428 lines (414 loc) · 8.87 KB
/
op.rs
File metadata and controls
428 lines (414 loc) · 8.87 KB
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
use crate::avm2::class::Class;
use crate::avm2::method::{Method, NativeMethodImpl};
use crate::avm2::multiname::Multiname;
use crate::avm2::namespace::Namespace;
use crate::avm2::script::Script;
use crate::string::AvmAtom;
use gc_arena::{Collect, Gc};
use std::cell::Cell;
#[derive(Clone, Collect, Copy, Debug)]
#[collect(no_drop)]
pub enum Op<'gc> {
Add,
AddI,
ApplyType {
num_types: u32,
},
AsType {
class: Class<'gc>,
},
AsTypeLate,
BitAnd,
BitNot,
BitOr,
BitXor,
Bkpt,
BkptLine {
line_num: u32,
},
Call {
num_args: u32,
},
CallMethod {
index: usize,
num_args: u32,
push_return_value: bool,
},
CallNative {
#[collect(require_static)]
method: NativeMethodImpl,
num_args: u32,
push_return_value: bool,
},
CallProperty {
multiname: Gc<'gc, Multiname<'gc>>,
num_args: u32,
},
CallPropLex {
multiname: Gc<'gc, Multiname<'gc>>,
num_args: u32,
},
CallPropVoid {
multiname: Gc<'gc, Multiname<'gc>>,
num_args: u32,
},
CallStatic {
method: Method<'gc>,
num_args: u32,
},
CallSuper {
multiname: Gc<'gc, Multiname<'gc>>,
num_args: u32,
},
CheckFilter,
Coerce {
class: Class<'gc>,
},
CoerceSwapPop {
class: Class<'gc>,
},
CoerceA,
CoerceB,
CoerceD,
CoerceDSwapPop,
CoerceI,
CoerceISwapPop,
CoerceO,
CoerceS,
CoerceU,
CoerceUSwapPop,
Construct {
num_args: u32,
},
ConstructProp {
multiname: Gc<'gc, Multiname<'gc>>,
num_args: u32,
},
ConstructSlot {
index: usize,
num_args: u32,
},
ConstructSuper {
num_args: u32,
},
ConvertO,
ConvertS,
Debug {
is_local_register: bool,
register_name: AvmAtom<'gc>,
register: u8,
},
DebugFile {
file_name: AvmAtom<'gc>,
},
DebugLine {
line_num: u32,
},
DecLocal {
index: u32,
},
DecLocalI {
index: u32,
},
Decrement,
DecrementI,
DeleteProperty {
multiname: Gc<'gc, Multiname<'gc>>,
},
Divide,
Dup,
Dxns {
string: AvmAtom<'gc>,
},
DxnsLate,
Equals,
EscXAttr,
EscXElem,
FindDef {
multiname: Gc<'gc, Multiname<'gc>>,
},
FindProperty {
multiname: Gc<'gc, Multiname<'gc>>,
},
FindPropStrict {
multiname: Gc<'gc, Multiname<'gc>>,
},
GetDescendants {
multiname: Gc<'gc, Multiname<'gc>>,
},
GetLocal {
index: u32,
},
GetOuterScope {
index: usize,
},
// The GetProperty op is specialized into three different ops depending on the multiname.
// - If the multiname is fully static, the verifier emits GetPropertyStatic.
// - If the multiname has a lazy name, a static namespace, contains the
// the public namespace, and is not an attribute multiname, the verifier
// emits GetPropertyFast.
// - If neither condition is met (i.e. the multiname has a lazy namespace),
// the verifier emits GetPropertySlow.
GetPropertyStatic {
multiname: Gc<'gc, Multiname<'gc>>,
},
GetPropertyFast {
multiname: Gc<'gc, Multiname<'gc>>,
},
GetPropertySlow {
multiname: Gc<'gc, Multiname<'gc>>,
},
GetScopeObject {
index: usize,
},
GetScriptGlobals {
script: Script<'gc>,
},
GetSlot {
// note: 0-indexed, as opposed to FP.
index: usize,
},
GetSuper {
multiname: Gc<'gc, Multiname<'gc>>,
},
GreaterEquals,
GreaterThan,
HasNext,
HasNext2 {
object_register: u32,
index_register: u32,
},
IfFalse {
offset: usize,
},
IfTrue {
offset: usize,
},
In,
IncLocal {
index: u32,
},
IncLocalI {
index: u32,
},
Increment,
IncrementI,
InitProperty {
multiname: Gc<'gc, Multiname<'gc>>,
},
InstanceOf,
IsType {
class: Class<'gc>,
},
IsTypeLate,
Jump {
offset: usize,
},
Kill {
index: u32,
},
LessEquals,
LessThan,
Lf32,
Lf64,
Li16,
Li32,
Li8,
LookupSwitch(Gc<'gc, LookupSwitch>),
LShift,
Modulo,
Multiply,
MultiplyI,
Negate,
NegateI,
NewActivation {
activation_class: Class<'gc>,
},
NewArray {
num_args: u32,
},
NewCatch {
index: usize,
},
NewClass {
class: Class<'gc>,
},
NewFunction {
method: Method<'gc>,
},
NewObject {
num_args: u32,
},
NextName,
NextValue,
Nop,
Not,
Pop,
PopJump {
offset: usize,
},
PopScope,
PushDouble {
value: f64,
},
PushFalse,
PushInt {
value: i32,
},
PushNamespace {
namespace: Namespace<'gc>,
},
PushNull,
PushScope,
PushShort {
value: i16,
},
PushString {
string: AvmAtom<'gc>,
},
PushTrue,
PushUint {
value: u32,
},
PushUndefined,
PushWith,
ReturnValue {
return_type: Option<Class<'gc>>,
},
ReturnVoid {
return_type: Option<Class<'gc>>,
},
RShift,
SetGlobalSlot {
// note: 0-indexed, as opposed to FP.
index: usize,
},
SetLocal {
index: u32,
},
// See the comments on the GetProperty op
SetPropertyStatic {
multiname: Gc<'gc, Multiname<'gc>>,
},
SetPropertyFast {
multiname: Gc<'gc, Multiname<'gc>>,
},
SetPropertySlow {
multiname: Gc<'gc, Multiname<'gc>>,
},
SetSlot {
// note: 0-indexed, as opposed to FP.
index: usize,
},
SetSlotCoerceI {
// note: 0-indexed, as opposed to FP.
index: usize,
},
SetSlotNoCoerce {
// note: 0-indexed, as opposed to FP.
index: usize,
},
SetSuper {
multiname: Gc<'gc, Multiname<'gc>>,
},
Sf32,
Sf64,
Si16,
Si32,
Si8,
StrictEquals,
StoreLocal {
index: u32,
},
Subtract,
SubtractI,
Swap,
Sxi1,
Sxi16,
Sxi8,
Throw,
TypeOf,
Timestamp,
URShift,
}
impl Op<'_> {
pub fn can_throw_error(&self) -> bool {
!matches!(
self,
Op::AsType { .. }
| Op::Bkpt
| Op::BkptLine { .. }
| Op::CoerceO
| Op::Dup
| Op::GetScopeObject { .. }
| Op::GetOuterScope { .. }
| Op::GetLocal { .. }
| Op::IfTrue { .. }
| Op::IfFalse { .. }
| Op::IsType { .. }
| Op::Jump { .. }
| Op::Kill { .. }
| Op::LookupSwitch { .. }
| Op::Nop
| Op::Not
| Op::Pop
| Op::PopJump { .. }
| Op::PopScope
| Op::PushDouble { .. }
| Op::PushFalse
| Op::PushInt { .. }
| Op::PushNamespace { .. }
| Op::PushNull
| Op::PushShort { .. }
| Op::PushString { .. }
| Op::PushTrue
| Op::PushUint { .. }
| Op::PushUndefined
| Op::SetLocal { .. }
| Op::StrictEquals
| Op::StoreLocal { .. }
| Op::Swap
| Op::Timestamp
| Op::TypeOf
| Op::ReturnVoid { .. }
)
}
pub fn is_nop(&self) -> bool {
if cfg!(feature = "avm_debug") {
matches!(self, Op::Nop)
} else {
matches!(
self,
Op::Nop | Op::Debug { .. } | Op::DebugFile { .. } | Op::DebugLine { .. }
)
}
}
/// Whether all this op does is push a single value to the stack, possibly
/// reading from stack or locals, but never, e.g., throwing an error or
/// calling a method.
pub fn is_pure_push(&self) -> bool {
matches!(
self,
Op::PushTrue
| Op::PushFalse
| Op::PushUndefined
| Op::PushNull
| Op::PushDouble { .. }
| Op::PushInt { .. }
| Op::PushShort { .. }
| Op::PushUint { .. }
| Op::GetLocal { .. }
| Op::Dup
)
}
}
// This has interior mutability so that we can rewrite switch offsets from the
// optimizer when we need to
#[derive(Collect, Debug)]
#[collect(require_static)]
pub struct LookupSwitch {
pub default_offset: Cell<usize>,
pub case_offsets: Box<[Cell<usize>]>,
}
#[cfg(target_pointer_width = "64")]
const _: () = assert!(std::mem::size_of::<Op>() == 16);