Skip to main content

rustpython_compiler_core/bytecode/
opcode_metadata.rs

1// This file is generated by tools/opcode_metadata/generate_rs_opcode_metadata.py
2// Do not edit!
3
4use crate::{bytecode::instruction::StackEffect, marshal::MarshalError};
5
6impl super::Opcode {
7    /// Returns [`Self`] as [`u8`].
8    #[must_use]
9    #[inline]
10    pub const fn as_u8(self) -> u8 {
11        self.as_numeric()
12    }
13
14    #[must_use]
15    #[inline]
16    pub const fn cache_entries(self) -> usize {
17        const CACHE_ENTRIES: [u8; 256] = [
18            0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
19            0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 1, 1,
20            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0,
21            0, 0, 0, 0, 0, 4, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 0, 0,
22            0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3,
23            3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
24            1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 4, 4, 1, 1, 0, 1, 4, 4, 4, 1, 1,
25            3, 3, 3, 3, 3, 3, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
26            0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 3, 3, 0, 1, 0, 0,
27        ];
28
29        CACHE_ENTRIES[self.as_numeric() as usize] as usize
30    }
31
32    #[must_use]
33    #[inline]
34    pub const fn deopt(self) -> Option<Self> {
35        const DEOPT: [Option<super::Opcode>; 256] = [
36            None,
37            None,
38            None,
39            Some(super::Opcode::BinaryOp),
40            None,
41            None,
42            None,
43            None,
44            None,
45            None,
46            None,
47            None,
48            None,
49            None,
50            None,
51            None,
52            None,
53            None,
54            None,
55            None,
56            None,
57            None,
58            None,
59            None,
60            None,
61            None,
62            None,
63            None,
64            None,
65            None,
66            None,
67            None,
68            None,
69            None,
70            None,
71            None,
72            None,
73            None,
74            None,
75            None,
76            None,
77            None,
78            None,
79            None,
80            None,
81            None,
82            None,
83            None,
84            None,
85            None,
86            None,
87            None,
88            None,
89            None,
90            None,
91            None,
92            None,
93            None,
94            None,
95            None,
96            None,
97            None,
98            None,
99            None,
100            None,
101            None,
102            None,
103            None,
104            None,
105            None,
106            None,
107            None,
108            None,
109            None,
110            None,
111            None,
112            None,
113            None,
114            None,
115            None,
116            None,
117            None,
118            None,
119            None,
120            None,
121            None,
122            None,
123            None,
124            None,
125            None,
126            None,
127            None,
128            None,
129            None,
130            None,
131            None,
132            None,
133            None,
134            None,
135            None,
136            None,
137            None,
138            None,
139            None,
140            None,
141            None,
142            None,
143            None,
144            None,
145            None,
146            None,
147            None,
148            None,
149            None,
150            None,
151            None,
152            None,
153            None,
154            None,
155            None,
156            None,
157            None,
158            None,
159            None,
160            None,
161            None,
162            None,
163            None,
164            None,
165            Some(super::Opcode::BinaryOp),
166            Some(super::Opcode::BinaryOp),
167            Some(super::Opcode::BinaryOp),
168            Some(super::Opcode::BinaryOp),
169            Some(super::Opcode::BinaryOp),
170            Some(super::Opcode::BinaryOp),
171            Some(super::Opcode::BinaryOp),
172            Some(super::Opcode::BinaryOp),
173            Some(super::Opcode::BinaryOp),
174            Some(super::Opcode::BinaryOp),
175            Some(super::Opcode::BinaryOp),
176            Some(super::Opcode::BinaryOp),
177            Some(super::Opcode::BinaryOp),
178            Some(super::Opcode::BinaryOp),
179            Some(super::Opcode::Call),
180            Some(super::Opcode::Call),
181            Some(super::Opcode::Call),
182            Some(super::Opcode::Call),
183            Some(super::Opcode::Call),
184            Some(super::Opcode::Call),
185            Some(super::Opcode::Call),
186            Some(super::Opcode::Call),
187            Some(super::Opcode::CallKw),
188            Some(super::Opcode::CallKw),
189            Some(super::Opcode::CallKw),
190            Some(super::Opcode::Call),
191            Some(super::Opcode::Call),
192            Some(super::Opcode::Call),
193            Some(super::Opcode::Call),
194            Some(super::Opcode::Call),
195            Some(super::Opcode::Call),
196            Some(super::Opcode::Call),
197            Some(super::Opcode::Call),
198            Some(super::Opcode::Call),
199            Some(super::Opcode::Call),
200            Some(super::Opcode::Call),
201            Some(super::Opcode::Call),
202            Some(super::Opcode::CompareOp),
203            Some(super::Opcode::CompareOp),
204            Some(super::Opcode::CompareOp),
205            Some(super::Opcode::ContainsOp),
206            Some(super::Opcode::ContainsOp),
207            Some(super::Opcode::ForIter),
208            Some(super::Opcode::ForIter),
209            Some(super::Opcode::ForIter),
210            Some(super::Opcode::ForIter),
211            Some(super::Opcode::JumpBackward),
212            Some(super::Opcode::JumpBackward),
213            Some(super::Opcode::LoadAttr),
214            Some(super::Opcode::LoadAttr),
215            Some(super::Opcode::LoadAttr),
216            Some(super::Opcode::LoadAttr),
217            Some(super::Opcode::LoadAttr),
218            Some(super::Opcode::LoadAttr),
219            Some(super::Opcode::LoadAttr),
220            Some(super::Opcode::LoadAttr),
221            Some(super::Opcode::LoadAttr),
222            Some(super::Opcode::LoadAttr),
223            Some(super::Opcode::LoadAttr),
224            Some(super::Opcode::LoadAttr),
225            Some(super::Opcode::LoadAttr),
226            Some(super::Opcode::LoadConst),
227            Some(super::Opcode::LoadConst),
228            Some(super::Opcode::LoadGlobal),
229            Some(super::Opcode::LoadGlobal),
230            Some(super::Opcode::LoadSuperAttr),
231            Some(super::Opcode::LoadSuperAttr),
232            Some(super::Opcode::Resume),
233            Some(super::Opcode::Send),
234            Some(super::Opcode::StoreAttr),
235            Some(super::Opcode::StoreAttr),
236            Some(super::Opcode::StoreAttr),
237            Some(super::Opcode::StoreSubscr),
238            Some(super::Opcode::StoreSubscr),
239            Some(super::Opcode::ToBool),
240            Some(super::Opcode::ToBool),
241            Some(super::Opcode::ToBool),
242            Some(super::Opcode::ToBool),
243            Some(super::Opcode::ToBool),
244            Some(super::Opcode::ToBool),
245            Some(super::Opcode::UnpackSequence),
246            Some(super::Opcode::UnpackSequence),
247            Some(super::Opcode::UnpackSequence),
248            None,
249            None,
250            None,
251            None,
252            None,
253            None,
254            None,
255            None,
256            None,
257            None,
258            None,
259            None,
260            None,
261            None,
262            None,
263            None,
264            None,
265            None,
266            None,
267            None,
268            None,
269            None,
270            None,
271            None,
272            None,
273            None,
274            None,
275            None,
276            None,
277            None,
278            None,
279            None,
280            None,
281            None,
282            None,
283            None,
284            None,
285            None,
286            None,
287            None,
288            None,
289            None,
290            None,
291            None,
292        ];
293
294        DEOPT[self.as_numeric() as usize]
295    }
296
297    /// Does this opcode have 'HAS_ARG_FLAG' set.
298    #[must_use]
299    pub const fn has_arg(self) -> bool {
300        matches!(
301            self,
302            Self::BinaryOp
303                | Self::BuildInterpolation
304                | Self::BuildList
305                | Self::BuildMap
306                | Self::BuildSet
307                | Self::BuildSlice
308                | Self::BuildString
309                | Self::BuildTuple
310                | Self::Call
311                | Self::CallIntrinsic1
312                | Self::CallIntrinsic2
313                | Self::CallKw
314                | Self::CompareOp
315                | Self::ContainsOp
316                | Self::ConvertValue
317                | Self::Copy
318                | Self::CopyFreeVars
319                | Self::DeleteAttr
320                | Self::DeleteDeref
321                | Self::DeleteFast
322                | Self::DeleteGlobal
323                | Self::DeleteName
324                | Self::DictMerge
325                | Self::DictUpdate
326                | Self::EndAsyncFor
327                | Self::ExtendedArg
328                | Self::ForIter
329                | Self::GetAwaitable
330                | Self::ImportFrom
331                | Self::ImportName
332                | Self::IsOp
333                | Self::JumpBackward
334                | Self::JumpBackwardNoInterrupt
335                | Self::JumpForward
336                | Self::ListAppend
337                | Self::ListExtend
338                | Self::LoadAttr
339                | Self::LoadCommonConstant
340                | Self::LoadConst
341                | Self::LoadDeref
342                | Self::LoadFast
343                | Self::LoadFastAndClear
344                | Self::LoadFastBorrow
345                | Self::LoadFastBorrowLoadFastBorrow
346                | Self::LoadFastCheck
347                | Self::LoadFastLoadFast
348                | Self::LoadFromDictOrDeref
349                | Self::LoadFromDictOrGlobals
350                | Self::LoadGlobal
351                | Self::LoadName
352                | Self::LoadSmallInt
353                | Self::LoadSpecial
354                | Self::LoadSuperAttr
355                | Self::MakeCell
356                | Self::MapAdd
357                | Self::MatchClass
358                | Self::PopJumpIfFalse
359                | Self::PopJumpIfNone
360                | Self::PopJumpIfNotNone
361                | Self::PopJumpIfTrue
362                | Self::RaiseVarargs
363                | Self::Reraise
364                | Self::Send
365                | Self::SetAdd
366                | Self::SetFunctionAttribute
367                | Self::SetUpdate
368                | Self::StoreAttr
369                | Self::StoreDeref
370                | Self::StoreFast
371                | Self::StoreFastLoadFast
372                | Self::StoreFastStoreFast
373                | Self::StoreGlobal
374                | Self::StoreName
375                | Self::Swap
376                | Self::UnpackEx
377                | Self::UnpackSequence
378                | Self::YieldValue
379                | Self::Resume
380                | Self::CallAllocAndEnterInit
381                | Self::CallBoundMethodExactArgs
382                | Self::CallBoundMethodGeneral
383                | Self::CallBuiltinClass
384                | Self::CallBuiltinFast
385                | Self::CallBuiltinFastWithKeywords
386                | Self::CallBuiltinO
387                | Self::CallIsinstance
388                | Self::CallKwBoundMethod
389                | Self::CallKwNonPy
390                | Self::CallKwPy
391                | Self::CallListAppend
392                | Self::CallMethodDescriptorFast
393                | Self::CallMethodDescriptorFastWithKeywords
394                | Self::CallMethodDescriptorNoargs
395                | Self::CallMethodDescriptorO
396                | Self::CallNonPyGeneral
397                | Self::CallPyExactArgs
398                | Self::CallPyGeneral
399                | Self::CallStr1
400                | Self::CallTuple1
401                | Self::CallType1
402                | Self::CompareOpFloat
403                | Self::CompareOpInt
404                | Self::CompareOpStr
405                | Self::ContainsOpDict
406                | Self::ContainsOpSet
407                | Self::ForIterGen
408                | Self::ForIterList
409                | Self::ForIterRange
410                | Self::ForIterTuple
411                | Self::JumpBackwardJit
412                | Self::JumpBackwardNoJit
413                | Self::LoadAttrClass
414                | Self::LoadAttrClassWithMetaclassCheck
415                | Self::LoadAttrGetattributeOverridden
416                | Self::LoadAttrInstanceValue
417                | Self::LoadAttrMethodLazyDict
418                | Self::LoadAttrMethodNoDict
419                | Self::LoadAttrMethodWithValues
420                | Self::LoadAttrModule
421                | Self::LoadAttrNondescriptorNoDict
422                | Self::LoadAttrNondescriptorWithValues
423                | Self::LoadAttrProperty
424                | Self::LoadAttrSlot
425                | Self::LoadAttrWithHint
426                | Self::LoadConstImmortal
427                | Self::LoadConstMortal
428                | Self::LoadGlobalBuiltin
429                | Self::LoadGlobalModule
430                | Self::LoadSuperAttrAttr
431                | Self::LoadSuperAttrMethod
432                | Self::SendGen
433                | Self::StoreAttrWithHint
434                | Self::UnpackSequenceList
435                | Self::UnpackSequenceTuple
436                | Self::UnpackSequenceTwoTuple
437                | Self::InstrumentedForIter
438                | Self::InstrumentedJumpForward
439                | Self::InstrumentedPopJumpIfTrue
440                | Self::InstrumentedPopJumpIfFalse
441                | Self::InstrumentedPopJumpIfNone
442                | Self::InstrumentedPopJumpIfNotNone
443                | Self::InstrumentedResume
444                | Self::InstrumentedYieldValue
445                | Self::InstrumentedEndAsyncFor
446                | Self::InstrumentedLoadSuperAttr
447                | Self::InstrumentedCall
448                | Self::InstrumentedCallKw
449                | Self::InstrumentedJumpBackward
450                | Self::EnterExecutor
451        )
452    }
453
454    /// Does this opcode have 'HAS_CONST_FLAG' set.
455    #[must_use]
456    pub const fn has_const(self) -> bool {
457        matches!(
458            self,
459            Self::LoadConst | Self::LoadConstImmortal | Self::LoadConstMortal
460        )
461    }
462
463    /// Does this opcode have 'HAS_EVAL_BREAK_FLAG' set.
464    #[must_use]
465    pub const fn has_eval_break(self) -> bool {
466        matches!(
467            self,
468            Self::CallFunctionEx
469                | Self::Call
470                | Self::JumpBackward
471                | Self::Resume
472                | Self::CallBuiltinClass
473                | Self::CallBuiltinFast
474                | Self::CallBuiltinFastWithKeywords
475                | Self::CallBuiltinO
476                | Self::CallKwNonPy
477                | Self::CallMethodDescriptorFast
478                | Self::CallMethodDescriptorFastWithKeywords
479                | Self::CallMethodDescriptorNoargs
480                | Self::CallMethodDescriptorO
481                | Self::CallNonPyGeneral
482                | Self::CallStr1
483                | Self::CallTuple1
484                | Self::JumpBackwardJit
485                | Self::JumpBackwardNoJit
486                | Self::InstrumentedResume
487                | Self::InstrumentedCall
488                | Self::InstrumentedCallFunctionEx
489                | Self::InstrumentedJumpBackward
490        )
491    }
492
493    /// Does this opcode have 'HAS_FREE_FLAG' set.
494    #[must_use]
495    pub const fn has_free(self) -> bool {
496        matches!(
497            self,
498            Self::DeleteDeref | Self::LoadFromDictOrDeref | Self::MakeCell | Self::StoreDeref
499        )
500    }
501
502    /// Does this opcode have 'HAS_JUMP_FLAG' set.
503    #[must_use]
504    pub const fn has_jump(self) -> bool {
505        matches!(
506            self,
507            Self::EndAsyncFor
508                | Self::ForIter
509                | Self::JumpBackward
510                | Self::JumpBackwardNoInterrupt
511                | Self::JumpForward
512                | Self::PopJumpIfFalse
513                | Self::PopJumpIfNone
514                | Self::PopJumpIfNotNone
515                | Self::PopJumpIfTrue
516                | Self::Send
517                | Self::ForIterList
518                | Self::ForIterRange
519                | Self::ForIterTuple
520                | Self::JumpBackwardJit
521                | Self::JumpBackwardNoJit
522                | Self::InstrumentedForIter
523                | Self::InstrumentedEndAsyncFor
524        )
525    }
526
527    /// Does this opcode have 'HAS_LOCAL_FLAG' set.
528    #[must_use]
529    pub const fn has_local(self) -> bool {
530        matches!(
531            self,
532            Self::BinaryOpInplaceAddUnicode
533                | Self::DeleteFast
534                | Self::LoadDeref
535                | Self::LoadFast
536                | Self::LoadFastAndClear
537                | Self::LoadFastBorrow
538                | Self::LoadFastBorrowLoadFastBorrow
539                | Self::LoadFastCheck
540                | Self::LoadFastLoadFast
541                | Self::StoreFast
542                | Self::StoreFastLoadFast
543                | Self::StoreFastStoreFast
544        )
545    }
546
547    /// Does this opcode have 'HAS_NAME_FLAG' set.
548    #[must_use]
549    pub const fn has_name(self) -> bool {
550        matches!(
551            self,
552            Self::DeleteAttr
553                | Self::DeleteGlobal
554                | Self::DeleteName
555                | Self::ImportFrom
556                | Self::ImportName
557                | Self::LoadAttr
558                | Self::LoadFromDictOrGlobals
559                | Self::LoadGlobal
560                | Self::LoadName
561                | Self::LoadSuperAttr
562                | Self::StoreAttr
563                | Self::StoreGlobal
564                | Self::StoreName
565                | Self::LoadAttrGetattributeOverridden
566                | Self::LoadAttrWithHint
567                | Self::LoadSuperAttrAttr
568                | Self::LoadSuperAttrMethod
569                | Self::StoreAttrWithHint
570                | Self::InstrumentedLoadSuperAttr
571        )
572    }
573
574    #[must_use]
575    pub const fn is_instrumented(self) -> bool {
576        matches!(
577            self,
578            Self::InstrumentedEndFor
579                | Self::InstrumentedPopIter
580                | Self::InstrumentedEndSend
581                | Self::InstrumentedForIter
582                | Self::InstrumentedInstruction
583                | Self::InstrumentedJumpForward
584                | Self::InstrumentedNotTaken
585                | Self::InstrumentedPopJumpIfTrue
586                | Self::InstrumentedPopJumpIfFalse
587                | Self::InstrumentedPopJumpIfNone
588                | Self::InstrumentedPopJumpIfNotNone
589                | Self::InstrumentedResume
590                | Self::InstrumentedReturnValue
591                | Self::InstrumentedYieldValue
592                | Self::InstrumentedEndAsyncFor
593                | Self::InstrumentedLoadSuperAttr
594                | Self::InstrumentedCall
595                | Self::InstrumentedCallKw
596                | Self::InstrumentedCallFunctionEx
597                | Self::InstrumentedJumpBackward
598                | Self::InstrumentedLine
599        )
600    }
601
602    #[must_use]
603    pub fn stack_effect_info(&self, oparg: u32) -> StackEffect {
604        // Reason for converting oparg to i32 is because of expressions like `1 + (oparg -1)`
605        // that causes underflow errors.
606        let oparg = i32::try_from(oparg).expect("oparg does not fit in an `i32`");
607
608        let (pushed, popped) = match self {
609            Self::Cache => (0, 0),
610            Self::BinarySlice => (1, 3),
611            Self::BuildTemplate => (1, 2),
612            Self::BinaryOpInplaceAddUnicode => (0, 2),
613            Self::CallFunctionEx => (1, 4),
614            Self::CheckEgMatch => (2, 2),
615            Self::CheckExcMatch => (2, 2),
616            Self::CleanupThrow => (2, 3),
617            Self::DeleteSubscr => (0, 2),
618            Self::EndFor => (0, 1),
619            Self::EndSend => (1, 2),
620            Self::ExitInitCheck => (0, 1),
621            Self::FormatSimple => (1, 1),
622            Self::FormatWithSpec => (1, 2),
623            Self::GetAiter => (1, 1),
624            Self::GetAnext => (2, 1),
625            Self::GetIter => (1, 1),
626            Self::Reserved => (0, 0),
627            Self::GetLen => (2, 1),
628            Self::GetYieldFromIter => (1, 1),
629            Self::InterpreterExit => (0, 1),
630            Self::LoadBuildClass => (1, 0),
631            Self::LoadLocals => (1, 0),
632            Self::MakeFunction => (1, 1),
633            Self::MatchKeys => (3, 2),
634            Self::MatchMapping => (2, 1),
635            Self::MatchSequence => (2, 1),
636            Self::Nop => (0, 0),
637            Self::NotTaken => (0, 0),
638            Self::PopExcept => (0, 1),
639            Self::PopIter => (0, 1),
640            Self::PopTop => (0, 1),
641            Self::PushExcInfo => (2, 1),
642            Self::PushNull => (1, 0),
643            Self::ReturnGenerator => (1, 0),
644            Self::ReturnValue => (1, 1),
645            Self::SetupAnnotations => (0, 0),
646            Self::StoreSlice => (0, 4),
647            Self::StoreSubscr => (0, 3),
648            Self::ToBool => (1, 1),
649            Self::UnaryInvert => (1, 1),
650            Self::UnaryNegative => (1, 1),
651            Self::UnaryNot => (1, 1),
652            Self::WithExceptStart => (6, 5),
653            Self::BinaryOp => (1, 2),
654            Self::BuildInterpolation => (1, 2 + (oparg & 1)),
655            Self::BuildList => (1, oparg),
656            Self::BuildMap => (1, oparg * 2),
657            Self::BuildSet => (1, oparg),
658            Self::BuildSlice => (1, oparg),
659            Self::BuildString => (1, oparg),
660            Self::BuildTuple => (1, oparg),
661            Self::Call => (1, 2 + oparg),
662            Self::CallIntrinsic1 => (1, 1),
663            Self::CallIntrinsic2 => (1, 2),
664            Self::CallKw => (1, 3 + oparg),
665            Self::CompareOp => (1, 2),
666            Self::ContainsOp => (1, 2),
667            Self::ConvertValue => (1, 1),
668            Self::Copy => (2 + (oparg - 1), 1 + (oparg - 1)),
669            Self::CopyFreeVars => (0, 0),
670            Self::DeleteAttr => (0, 1),
671            Self::DeleteDeref => (0, 0),
672            Self::DeleteFast => (0, 0),
673            Self::DeleteGlobal => (0, 0),
674            Self::DeleteName => (0, 0),
675            Self::DictMerge => (4 + (oparg - 1), 5 + (oparg - 1)),
676            Self::DictUpdate => (1 + (oparg - 1), 2 + (oparg - 1)),
677            Self::EndAsyncFor => (0, 2),
678            Self::ExtendedArg => (0, 0),
679            Self::ForIter => (2, 1),
680            Self::GetAwaitable => (1, 1),
681            Self::ImportFrom => (2, 1),
682            Self::ImportName => (1, 2),
683            Self::IsOp => (1, 2),
684            Self::JumpBackward => (0, 0),
685            Self::JumpBackwardNoInterrupt => (0, 0),
686            Self::JumpForward => (0, 0),
687            Self::ListAppend => (1 + (oparg - 1), 2 + (oparg - 1)),
688            Self::ListExtend => (1 + (oparg - 1), 2 + (oparg - 1)),
689            Self::LoadAttr => (1 + (oparg & 1), 1),
690            Self::LoadCommonConstant => (1, 0),
691            Self::LoadConst => (1, 0),
692            Self::LoadDeref => (1, 0),
693            Self::LoadFast => (1, 0),
694            Self::LoadFastAndClear => (1, 0),
695            Self::LoadFastBorrow => (1, 0),
696            Self::LoadFastBorrowLoadFastBorrow => (2, 0),
697            Self::LoadFastCheck => (1, 0),
698            Self::LoadFastLoadFast => (2, 0),
699            Self::LoadFromDictOrDeref => (1, 1),
700            Self::LoadFromDictOrGlobals => (1, 1),
701            Self::LoadGlobal => (1 + (oparg & 1), 0),
702            Self::LoadName => (1, 0),
703            Self::LoadSmallInt => (1, 0),
704            Self::LoadSpecial => (2, 1),
705            Self::LoadSuperAttr => (1 + (oparg & 1), 3),
706            Self::MakeCell => (0, 0),
707            Self::MapAdd => (1 + (oparg - 1), 3 + (oparg - 1)),
708            Self::MatchClass => (1, 3),
709            Self::PopJumpIfFalse => (0, 1),
710            Self::PopJumpIfNone => (0, 1),
711            Self::PopJumpIfNotNone => (0, 1),
712            Self::PopJumpIfTrue => (0, 1),
713            Self::RaiseVarargs => (0, oparg),
714            Self::Reraise => (oparg, 1 + oparg),
715            Self::Send => (2, 2),
716            Self::SetAdd => (1 + (oparg - 1), 2 + (oparg - 1)),
717            Self::SetFunctionAttribute => (1, 2),
718            Self::SetUpdate => (1 + (oparg - 1), 2 + (oparg - 1)),
719            Self::StoreAttr => (0, 2),
720            Self::StoreDeref => (0, 1),
721            Self::StoreFast => (0, 1),
722            Self::StoreFastLoadFast => (1, 1),
723            Self::StoreFastStoreFast => (0, 2),
724            Self::StoreGlobal => (0, 1),
725            Self::StoreName => (0, 1),
726            Self::Swap => (2 + (oparg - 2), 2 + (oparg - 2)),
727            Self::UnpackEx => (1 + (oparg & 0xFF) + (oparg >> 8), 1),
728            Self::UnpackSequence => (oparg, 1),
729            Self::YieldValue => (1, 1),
730            Self::Resume => (0, 0),
731            Self::BinaryOpAddFloat => (1, 2),
732            Self::BinaryOpAddInt => (1, 2),
733            Self::BinaryOpAddUnicode => (1, 2),
734            Self::BinaryOpExtend => (1, 2),
735            Self::BinaryOpMultiplyFloat => (1, 2),
736            Self::BinaryOpMultiplyInt => (1, 2),
737            Self::BinaryOpSubscrDict => (1, 2),
738            Self::BinaryOpSubscrGetitem => (0, 2),
739            Self::BinaryOpSubscrListInt => (1, 2),
740            Self::BinaryOpSubscrListSlice => (1, 2),
741            Self::BinaryOpSubscrStrInt => (1, 2),
742            Self::BinaryOpSubscrTupleInt => (1, 2),
743            Self::BinaryOpSubtractFloat => (1, 2),
744            Self::BinaryOpSubtractInt => (1, 2),
745            Self::CallAllocAndEnterInit => (0, 2 + oparg),
746            Self::CallBoundMethodExactArgs => (0, 2 + oparg),
747            Self::CallBoundMethodGeneral => (0, 2 + oparg),
748            Self::CallBuiltinClass => (1, 2 + oparg),
749            Self::CallBuiltinFast => (1, 2 + oparg),
750            Self::CallBuiltinFastWithKeywords => (1, 2 + oparg),
751            Self::CallBuiltinO => (1, 2 + oparg),
752            Self::CallIsinstance => (1, 2 + oparg),
753            Self::CallKwBoundMethod => (0, 3 + oparg),
754            Self::CallKwNonPy => (1, 3 + oparg),
755            Self::CallKwPy => (0, 3 + oparg),
756            Self::CallLen => (1, 3),
757            Self::CallListAppend => (0, 3),
758            Self::CallMethodDescriptorFast => (1, 2 + oparg),
759            Self::CallMethodDescriptorFastWithKeywords => (1, 2 + oparg),
760            Self::CallMethodDescriptorNoargs => (1, 2 + oparg),
761            Self::CallMethodDescriptorO => (1, 2 + oparg),
762            Self::CallNonPyGeneral => (1, 2 + oparg),
763            Self::CallPyExactArgs => (0, 2 + oparg),
764            Self::CallPyGeneral => (0, 2 + oparg),
765            Self::CallStr1 => (1, 3),
766            Self::CallTuple1 => (1, 3),
767            Self::CallType1 => (1, 3),
768            Self::CompareOpFloat => (1, 2),
769            Self::CompareOpInt => (1, 2),
770            Self::CompareOpStr => (1, 2),
771            Self::ContainsOpDict => (1, 2),
772            Self::ContainsOpSet => (1, 2),
773            Self::ForIterGen => (1, 1),
774            Self::ForIterList => (2, 1),
775            Self::ForIterRange => (2, 1),
776            Self::ForIterTuple => (2, 1),
777            Self::JumpBackwardJit => (0, 0),
778            Self::JumpBackwardNoJit => (0, 0),
779            Self::LoadAttrClass => (1 + (oparg & 1), 1),
780            Self::LoadAttrClassWithMetaclassCheck => (1 + (oparg & 1), 1),
781            Self::LoadAttrGetattributeOverridden => (1, 1),
782            Self::LoadAttrInstanceValue => (1 + (oparg & 1), 1),
783            Self::LoadAttrMethodLazyDict => (2, 1),
784            Self::LoadAttrMethodNoDict => (2, 1),
785            Self::LoadAttrMethodWithValues => (2, 1),
786            Self::LoadAttrModule => (1 + (oparg & 1), 1),
787            Self::LoadAttrNondescriptorNoDict => (1, 1),
788            Self::LoadAttrNondescriptorWithValues => (1, 1),
789            Self::LoadAttrProperty => (0, 1),
790            Self::LoadAttrSlot => (1 + (oparg & 1), 1),
791            Self::LoadAttrWithHint => (1 + (oparg & 1), 1),
792            Self::LoadConstImmortal => (1, 0),
793            Self::LoadConstMortal => (1, 0),
794            Self::LoadGlobalBuiltin => (1 + (oparg & 1), 0),
795            Self::LoadGlobalModule => (1 + (oparg & 1), 0),
796            Self::LoadSuperAttrAttr => (1, 3),
797            Self::LoadSuperAttrMethod => (2, 3),
798            Self::ResumeCheck => (0, 0),
799            Self::SendGen => (1, 2),
800            Self::StoreAttrInstanceValue => (0, 2),
801            Self::StoreAttrSlot => (0, 2),
802            Self::StoreAttrWithHint => (0, 2),
803            Self::StoreSubscrDict => (0, 3),
804            Self::StoreSubscrListInt => (0, 3),
805            Self::ToBoolAlwaysTrue => (1, 1),
806            Self::ToBoolBool => (1, 1),
807            Self::ToBoolInt => (1, 1),
808            Self::ToBoolList => (1, 1),
809            Self::ToBoolNone => (1, 1),
810            Self::ToBoolStr => (1, 1),
811            Self::UnpackSequenceList => (oparg, 1),
812            Self::UnpackSequenceTuple => (oparg, 1),
813            Self::UnpackSequenceTwoTuple => (2, 1),
814            Self::InstrumentedEndFor => (1, 2),
815            Self::InstrumentedPopIter => (0, 1),
816            Self::InstrumentedEndSend => (1, 2),
817            Self::InstrumentedForIter => (2, 1),
818            Self::InstrumentedInstruction => (0, 0),
819            Self::InstrumentedJumpForward => (0, 0),
820            Self::InstrumentedNotTaken => (0, 0),
821            Self::InstrumentedPopJumpIfTrue => (0, 1),
822            Self::InstrumentedPopJumpIfFalse => (0, 1),
823            Self::InstrumentedPopJumpIfNone => (0, 1),
824            Self::InstrumentedPopJumpIfNotNone => (0, 1),
825            Self::InstrumentedResume => (0, 0),
826            Self::InstrumentedReturnValue => (1, 1),
827            Self::InstrumentedYieldValue => (1, 1),
828            Self::InstrumentedEndAsyncFor => (0, 2),
829            Self::InstrumentedLoadSuperAttr => (1 + (oparg & 1), 3),
830            Self::InstrumentedCall => (1, 2 + oparg),
831            Self::InstrumentedCallKw => (1, 3 + oparg),
832            Self::InstrumentedCallFunctionEx => (1, 4),
833            Self::InstrumentedJumpBackward => (0, 0),
834            Self::InstrumentedLine => (0, 0),
835            Self::EnterExecutor => (0, 0),
836        };
837
838        debug_assert!(u32::try_from(pushed).is_ok());
839        debug_assert!(u32::try_from(popped).is_ok());
840
841        StackEffect::new(pushed as u32, popped as u32)
842    }
843
844    #[must_use]
845    #[inline]
846    pub const fn to_base(self) -> Option<Self> {
847        Some(match self {
848            Self::InstrumentedCall => Self::Call,
849            Self::InstrumentedCallFunctionEx => Self::CallFunctionEx,
850            Self::InstrumentedCallKw => Self::CallKw,
851            Self::InstrumentedEndAsyncFor => Self::EndAsyncFor,
852            Self::InstrumentedEndFor => Self::EndFor,
853            Self::InstrumentedEndSend => Self::EndSend,
854            Self::InstrumentedForIter => Self::ForIter,
855            Self::InstrumentedJumpBackward => Self::JumpBackward,
856            Self::InstrumentedJumpForward => Self::JumpForward,
857            Self::InstrumentedLoadSuperAttr => Self::LoadSuperAttr,
858            Self::InstrumentedNotTaken => Self::NotTaken,
859            Self::InstrumentedPopIter => Self::PopIter,
860            Self::InstrumentedPopJumpIfFalse => Self::PopJumpIfFalse,
861            Self::InstrumentedPopJumpIfNone => Self::PopJumpIfNone,
862            Self::InstrumentedPopJumpIfNotNone => Self::PopJumpIfNotNone,
863            Self::InstrumentedPopJumpIfTrue => Self::PopJumpIfTrue,
864            Self::InstrumentedResume => Self::Resume,
865            Self::InstrumentedReturnValue => Self::ReturnValue,
866            Self::InstrumentedYieldValue => Self::YieldValue,
867            _ => return None,
868        })
869    }
870
871    #[must_use]
872    pub const fn to_instrumented(self) -> Option<Self> {
873        Some(match self {
874            Self::Call => Self::InstrumentedCall,
875            Self::CallFunctionEx => Self::InstrumentedCallFunctionEx,
876            Self::CallKw => Self::InstrumentedCallKw,
877            Self::EndAsyncFor => Self::InstrumentedEndAsyncFor,
878            Self::EndFor => Self::InstrumentedEndFor,
879            Self::EndSend => Self::InstrumentedEndSend,
880            Self::ForIter => Self::InstrumentedForIter,
881            Self::JumpBackward => Self::InstrumentedJumpBackward,
882            Self::JumpForward => Self::InstrumentedJumpForward,
883            Self::LoadSuperAttr => Self::InstrumentedLoadSuperAttr,
884            Self::NotTaken => Self::InstrumentedNotTaken,
885            Self::PopIter => Self::InstrumentedPopIter,
886            Self::PopJumpIfFalse => Self::InstrumentedPopJumpIfFalse,
887            Self::PopJumpIfNone => Self::InstrumentedPopJumpIfNone,
888            Self::PopJumpIfNotNone => Self::InstrumentedPopJumpIfNotNone,
889            Self::PopJumpIfTrue => Self::InstrumentedPopJumpIfTrue,
890            Self::Resume => Self::InstrumentedResume,
891            Self::ReturnValue => Self::InstrumentedReturnValue,
892            Self::YieldValue => Self::InstrumentedYieldValue,
893            _ => return None,
894        })
895    }
896
897    pub const fn try_from_u8(value: u8) -> Result<Self, MarshalError> {
898        Self::try_from_numeric(value)
899    }
900}
901
902impl super::PseudoOpcode {
903    /// Returns [`Self`] as [`u16`].
904    #[must_use]
905    #[inline]
906    pub const fn as_u16(self) -> u16 {
907        self.as_numeric()
908    }
909
910    #[must_use]
911    #[inline]
912    pub const fn cache_entries(self) -> usize {
913        0
914    }
915
916    #[must_use]
917    #[inline]
918    pub const fn deopt(self) -> Option<Self> {
919        None
920    }
921
922    /// Does this opcode have 'HAS_ARG_FLAG' set.
923    #[must_use]
924    pub const fn has_arg(self) -> bool {
925        matches!(
926            self,
927            Self::Jump
928                | Self::JumpIfFalse
929                | Self::JumpIfTrue
930                | Self::JumpNoInterrupt
931                | Self::LoadClosure
932                | Self::SetupCleanup
933                | Self::SetupFinally
934                | Self::SetupWith
935                | Self::StoreFastMaybeNull
936        )
937    }
938
939    /// Does this opcode have 'HAS_CONST_FLAG' set.
940    #[must_use]
941    pub const fn has_const(self) -> bool {
942        false
943    }
944
945    /// Does this opcode have 'HAS_EVAL_BREAK_FLAG' set.
946    #[must_use]
947    pub const fn has_eval_break(self) -> bool {
948        matches!(self, Self::Jump)
949    }
950
951    /// Does this opcode have 'HAS_FREE_FLAG' set.
952    #[must_use]
953    pub const fn has_free(self) -> bool {
954        false
955    }
956
957    /// Does this opcode have 'HAS_JUMP_FLAG' set.
958    #[must_use]
959    pub const fn has_jump(self) -> bool {
960        matches!(
961            self,
962            Self::Jump | Self::JumpIfFalse | Self::JumpIfTrue | Self::JumpNoInterrupt
963        )
964    }
965
966    /// Does this opcode have 'HAS_LOCAL_FLAG' set.
967    #[must_use]
968    pub const fn has_local(self) -> bool {
969        matches!(self, Self::LoadClosure | Self::StoreFastMaybeNull)
970    }
971
972    /// Does this opcode have 'HAS_NAME_FLAG' set.
973    #[must_use]
974    pub const fn has_name(self) -> bool {
975        false
976    }
977
978    #[must_use]
979    pub const fn is_instrumented(self) -> bool {
980        false
981    }
982
983    #[must_use]
984    pub fn stack_effect_info(&self, _oparg: u32) -> StackEffect {
985        let (pushed, popped) = match self {
986            Self::AnnotationsPlaceholder => (0, 0),
987            Self::Jump => (0, 0),
988            Self::JumpIfFalse => (1, 1),
989            Self::JumpIfTrue => (1, 1),
990            Self::JumpNoInterrupt => (0, 0),
991            Self::LoadClosure => (1, 0),
992            Self::PopBlock => (0, 0),
993            Self::SetupCleanup => (2, 0),
994            Self::SetupFinally => (1, 0),
995            Self::SetupWith => (1, 0),
996            Self::StoreFastMaybeNull => (0, 1),
997        };
998
999        debug_assert!(u32::try_from(pushed).is_ok());
1000        debug_assert!(u32::try_from(popped).is_ok());
1001
1002        StackEffect::new(pushed as u32, popped as u32)
1003    }
1004
1005    #[must_use]
1006    #[inline]
1007    pub const fn to_base(self) -> Option<Self> {
1008        None
1009    }
1010
1011    #[must_use]
1012    pub const fn to_instrumented(self) -> Option<Self> {
1013        None
1014    }
1015
1016    pub const fn try_from_u16(value: u16) -> Result<Self, MarshalError> {
1017        Self::try_from_numeric(value)
1018    }
1019}