1use std::collections::HashMap;
3
4use getset::Getters;
5use scroll::Pread;
6
7use crate::{
8 code::Code,
9 method::{self},
10 region::Region,
11 string::ABCString,
12};
13
14#[derive(Debug, Clone)]
17pub enum FormatUnit {
18 Opcode,
19 PrefixOpcode,
20 RR,
22 RRRR,
23 V4V4,
25 V8,
26 V16,
27 Imm4Imm4,
29 IMM8,
30 IMM16,
31 IMM32,
32 IMM64,
33 LiteralID,
35 StringID,
36 MethodID,
37}
38
39#[derive(Debug, Clone, Getters)]
40#[get = "pub"]
41pub struct ByteCodeFormat {
42 name: String,
43 formats: Vec<FormatUnit>,
44 instruction: Vec<u8>,
45}
46
47impl ByteCodeFormat {
48 pub fn new(name: String, formats: Vec<FormatUnit>) -> Self {
49 Self {
50 name,
51 formats,
52 instruction: vec![],
53 }
54 }
55
56 pub fn set_instruction(&mut self, instruction: Vec<u8>) {
57 self.instruction = instruction;
58 }
59
60 pub fn get_size(&self) -> usize {
61 let mut size = 0;
62 for unit in &self.formats {
63 match unit {
64 FormatUnit::Opcode => size += 1,
65 FormatUnit::PrefixOpcode => size += 2,
66 FormatUnit::V4V4 => size += 1,
67 FormatUnit::V8 => size += 1,
68 FormatUnit::V16 => size += 2,
69 FormatUnit::LiteralID => size += 2,
70 FormatUnit::StringID => size += 2,
71 FormatUnit::MethodID => size += 2,
72 FormatUnit::Imm4Imm4 => size += 1,
73 FormatUnit::IMM8 => size += 1,
74 FormatUnit::IMM16 => size += 2,
75 FormatUnit::IMM32 => size += 4,
76 FormatUnit::IMM64 => size += 8,
77 FormatUnit::RR => size += 1,
78 FormatUnit::RRRR => size += 2,
79 }
80 }
81
82 size
83 }
84
85 pub fn parse(
86 &self,
87 instructions: &Vec<u8>,
88 offset: usize,
89 region: &Region,
90 source: &[u8],
91 literal_array_map: &HashMap<usize, String>,
92 ) -> usize {
93 let mut offset = offset;
94 let opcode_name = self.name.split_whitespace().collect::<Vec<&str>>()[0];
95 let mut strx = format!("{} ", opcode_name);
96 let mut raw = String::from("0x");
97
98 for unit in &self.formats {
99 match unit {
100 FormatUnit::Opcode => {
101 let data = instructions.pread::<u8>(offset).unwrap();
102 offset += 1;
103 raw += &format!("{:02X}", data);
104 }
105 FormatUnit::PrefixOpcode => {
106 let data = instructions.pread_with::<u16>(offset, scroll::BE).unwrap();
108 offset += 2;
109 raw += &format!("{:04X}", data);
110 }
111
112 FormatUnit::V4V4 => {
113 let data = instructions.pread::<u8>(offset).unwrap();
114 raw += &format!("{:02X}", data);
115 offset += 1;
116 let high_nibble = (data >> 4) & 0b1111;
117 let low_nibble = data & 0b1111;
118 strx += &format!("v{} v{}", low_nibble, high_nibble);
119 }
120 FormatUnit::V8 => {
121 let data = instructions.pread::<u8>(offset).unwrap();
122 raw += &format!("{:02X}", data);
123 offset += 1;
124 strx += &format!("v{} ", data);
125 }
126 FormatUnit::V16 => {
127 let data = instructions.pread::<u16>(offset).unwrap();
128 raw += &format!("{:04X}", data);
129 offset += 2;
130 strx += &format!("v{} ", data);
131 }
132 FormatUnit::LiteralID => {
134 let data = instructions.pread_with::<u16>(offset, scroll::LE).unwrap();
135 raw += &format!("{:04X}", data);
136 offset += 2;
137
138 let array_off = *region.get_msl_offset(data as usize);
139 let array_off = array_off as usize;
140 let x = literal_array_map.get(&array_off).unwrap();
141 strx += &format!("{{ {} }}", x);
142 }
143 FormatUnit::StringID => {
144 let data = instructions.pread_with::<u16>(offset, scroll::LE).unwrap();
145 raw += &format!("{:04X}", data);
146 offset += 2;
147
148 let string_offset = region.get_msl_offset(data as usize);
149 let x = source
150 .as_ref()
151 .pread::<ABCString>(*string_offset as usize)
152 .unwrap()
153 .str();
154 strx += &format!("\"{}\" ", x);
155 }
156 FormatUnit::MethodID => {
157 let data = instructions.pread_with::<u16>(offset, scroll::LE).unwrap();
158 raw += &format!("{:04X}", data);
159 offset += 2;
160 let method_offset = region.get_msl_offset(data as usize);
161
162 let method_sign =
163 method::get_method_sign(source, *method_offset as usize, region);
164
165 strx += &method_sign.to_string();
166 strx += " ";
167 }
168 FormatUnit::Imm4Imm4 => {
169 let data = instructions.pread::<u8>(offset).unwrap();
170 raw += &format!("{:02X}", data);
171 offset += 1;
172 strx += "Imm4Imm4";
173 strx += &format!("+{} ", data);
174 }
175 FormatUnit::IMM8 => {
176 let data = instructions.pread::<u8>(offset).unwrap();
177 raw += &format!("{:02X}", data);
178 offset += 1;
179 strx += &format!("+{} ", data);
180 }
181 FormatUnit::IMM16 => {
182 let data = instructions.pread::<u16>(offset).unwrap();
183 raw += &format!("{:04X}", data);
184 offset += 2;
185 strx += &format!("+{} ", data);
186 }
187 FormatUnit::IMM32 => {
188 let data = instructions.pread::<u32>(offset).unwrap();
189 raw += &format!("{:08X}", data);
190 offset += 4;
191 strx += "IMM32";
192 strx += &format!("+{} ", data);
193 }
194 FormatUnit::IMM64 => {
195 let data = instructions.pread::<u64>(offset).unwrap();
196 raw += &format!("{:16X}", data);
197 offset += 8;
198 strx += "IMM64";
199 strx += &format!("+{} ", data);
200 }
201 FormatUnit::RR => {
202 let _ = instructions.pread::<u8>(offset).unwrap();
203 offset += 1;
204 }
205 FormatUnit::RRRR => {
206 let _ = instructions.pread::<u16>(offset).unwrap();
207 offset += 2;
208 }
209 }
210 }
211
212 println!("{} : {}", raw, strx);
214
215 offset
216 }
217}
218
219pub struct BytecodeParser {
221 pub opcode_table: HashMap<u16, ByteCodeFormat>,
223 pub prefix_opcode_table: HashMap<u16, ByteCodeFormat>,
225}
226
227fn init_opcode_map() -> HashMap<u16, ByteCodeFormat> {
228 let opcode_vec = vec![
229 (
231 0x0,
232 ByteCodeFormat::new("ldundefined".to_owned(), vec![FormatUnit::Opcode]),
233 ),
234 (
236 0x1,
237 ByteCodeFormat::new("ldnull".to_owned(), vec![FormatUnit::Opcode]),
238 ),
239 (
241 0x2,
242 ByteCodeFormat::new("ldtrue".to_owned(), vec![FormatUnit::Opcode]),
243 ),
244 (
246 0x3,
247 ByteCodeFormat::new("ldfalse".to_owned(), vec![FormatUnit::Opcode]),
248 ),
249 (
251 0x4,
252 ByteCodeFormat::new("createemptyobject".to_owned(), vec![FormatUnit::Opcode]),
253 ),
254 (
256 0x5,
257 ByteCodeFormat::new(
258 "createemptyarray".to_owned(),
259 vec![FormatUnit::Opcode, FormatUnit::RR],
260 ),
261 ),
262 (
264 0x6,
265 ByteCodeFormat::new(
266 "createarraywithbuffer".to_owned(),
267 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::LiteralID],
268 ),
269 ),
270 (
272 0x07,
273 ByteCodeFormat::new(
274 "createobjectwithbuffer".to_owned(),
275 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::LiteralID],
276 ),
277 ),
278 (
280 0x08,
281 ByteCodeFormat::new(
282 "newobjrange RR, +AA, vBB".to_owned(),
283 vec![
284 FormatUnit::Opcode,
285 FormatUnit::RR,
286 FormatUnit::IMM8,
287 FormatUnit::V8,
288 ],
289 ),
290 ),
291 (
293 0x09,
294 ByteCodeFormat::new(
295 "newlexenv".to_owned(),
296 vec![FormatUnit::Opcode, FormatUnit::IMM8],
297 ),
298 ),
299 (
301 0x0a,
302 ByteCodeFormat::new(
303 "add2 RR, vAA".to_owned(),
304 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
305 ),
306 ),
307 (
309 0x0b,
310 ByteCodeFormat::new(
311 "sub2 RR, vAA".to_owned(),
312 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
313 ),
314 ),
315 (
317 0x0c,
318 ByteCodeFormat::new(
319 "mul2 RR, vAA".to_owned(),
320 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
321 ),
322 ),
323 (
325 0x0d,
326 ByteCodeFormat::new(
327 "div2 RR, vAA".to_owned(),
328 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
329 ),
330 ),
331 (
333 0x0e,
334 ByteCodeFormat::new(
335 "mod2 RR, vAA".to_owned(),
336 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
337 ),
338 ),
339 (
341 0x0f,
342 ByteCodeFormat::new(
343 "eq RR, vAA".to_owned(),
344 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
345 ),
346 ),
347 (
349 0x10,
350 ByteCodeFormat::new(
351 "noteq RR, vAA".to_owned(),
352 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
353 ),
354 ),
355 (
357 0x11,
358 ByteCodeFormat::new(
359 "less RR, vAA".to_owned(),
360 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
361 ),
362 ),
363 (
365 0x12,
366 ByteCodeFormat::new(
367 "lesseq RR, vAA".to_owned(),
368 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
369 ),
370 ),
371 (
373 0x13,
374 ByteCodeFormat::new(
375 "greater RR, vAA".to_owned(),
376 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
377 ),
378 ),
379 (
381 0x13,
382 ByteCodeFormat::new(
383 "greatereq RR, vAA".to_owned(),
384 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
385 ),
386 ),
387 (
389 0x15,
390 ByteCodeFormat::new(
391 "shl2 RR, vAA".to_owned(),
392 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
393 ),
394 ),
395 (
397 0x16,
398 ByteCodeFormat::new(
399 "shr2 RR, vAA".to_owned(),
400 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
401 ),
402 ),
403 (
405 0x17,
406 ByteCodeFormat::new(
407 "ashr2 RR, vAA".to_owned(),
408 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
409 ),
410 ),
411 (
413 0x18,
414 ByteCodeFormat::new(
415 "and2 RR, vAA".to_owned(),
416 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
417 ),
418 ),
419 (
421 0x19,
422 ByteCodeFormat::new(
423 "or2 RR, vAA".to_owned(),
424 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
425 ),
426 ),
427 (
429 0x1a,
430 ByteCodeFormat::new(
431 "xor2 RR, vAA".to_owned(),
432 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
433 ),
434 ),
435 (
437 0x1b,
438 ByteCodeFormat::new(
439 "exp RR, vAA".to_owned(),
440 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
441 ),
442 ),
443 (
445 0x1c,
446 ByteCodeFormat::new(
447 "typeof RR".to_owned(),
448 vec![FormatUnit::Opcode, FormatUnit::RR],
449 ),
450 ),
451 (
453 0x1d,
454 ByteCodeFormat::new(
455 "tonumber RR".to_owned(),
456 vec![FormatUnit::Opcode, FormatUnit::RR],
457 ),
458 ),
459 (
461 0x1e,
462 ByteCodeFormat::new(
463 "tonumeric RR".to_owned(),
464 vec![FormatUnit::Opcode, FormatUnit::RR],
465 ),
466 ),
467 (
469 0x1f,
470 ByteCodeFormat::new(
471 "neg RR".to_owned(),
472 vec![FormatUnit::Opcode, FormatUnit::RR],
473 ),
474 ),
475 (
477 0x20,
478 ByteCodeFormat::new(
479 "not RR".to_owned(),
480 vec![FormatUnit::Opcode, FormatUnit::RR],
481 ),
482 ),
483 (
485 0x21,
486 ByteCodeFormat::new(
487 "inc RR".to_owned(),
488 vec![FormatUnit::Opcode, FormatUnit::RR],
489 ),
490 ),
491 (
493 0x22,
494 ByteCodeFormat::new(
495 "dec RR".to_owned(),
496 vec![FormatUnit::Opcode, FormatUnit::RR],
497 ),
498 ),
499 (
501 0x23,
502 ByteCodeFormat::new(
503 "istrue".to_owned(),
504 vec![FormatUnit::Opcode, FormatUnit::RR],
505 ),
506 ),
507 (
509 0x24,
510 ByteCodeFormat::new(
511 "isfalse".to_owned(),
512 vec![FormatUnit::Opcode, FormatUnit::RR],
513 ),
514 ),
515 (
517 0x25,
518 ByteCodeFormat::new(
519 "isin RR, vAA".to_owned(),
520 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
521 ),
522 ),
523 (
525 0x26,
526 ByteCodeFormat::new(
527 "instanceof RR, vAA".to_owned(),
528 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
529 ),
530 ),
531 (
533 0x27,
534 ByteCodeFormat::new(
535 "strictnoteq RR, vAA".to_owned(),
536 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
537 ),
538 ),
539 (
541 0x28,
542 ByteCodeFormat::new(
543 "stricteq RR, vAA".to_owned(),
544 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
545 ),
546 ),
547 (
549 0x29,
550 ByteCodeFormat::new(
551 "callarg0 RR".to_owned(),
552 vec![FormatUnit::Opcode, FormatUnit::RR],
553 ),
554 ),
555 (
557 0x2a,
558 ByteCodeFormat::new(
559 "callarg1 RR, vAA".to_owned(),
560 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
561 ),
562 ),
563 (
565 0x2b,
566 ByteCodeFormat::new(
567 "callargs2 RR, vAA, vBB".to_owned(),
568 vec![
569 FormatUnit::Opcode,
570 FormatUnit::RR,
571 FormatUnit::V8,
572 FormatUnit::V8,
573 ],
574 ),
575 ),
576 (
578 0x2c,
579 ByteCodeFormat::new(
580 "callargs3 RR, vAA, vBB, vCC".to_owned(),
581 vec![
582 FormatUnit::Opcode,
583 FormatUnit::RR,
584 FormatUnit::V8,
585 FormatUnit::V8,
586 FormatUnit::V8,
587 ],
588 ),
589 ),
590 (
592 0x2d,
593 ByteCodeFormat::new(
594 "callthis0 RR, vAA".to_owned(),
595 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
596 ),
597 ),
598 (
600 0x2e,
601 ByteCodeFormat::new(
602 "callthis1 RR, vAA, vBB".to_owned(),
603 vec![
604 FormatUnit::Opcode,
605 FormatUnit::RR,
606 FormatUnit::V8,
607 FormatUnit::V8,
608 ],
609 ),
610 ),
611 (
613 0x2f,
614 ByteCodeFormat::new(
615 "callthis2 RR, vAA, vBB, vCC".to_owned(),
616 vec![
617 FormatUnit::Opcode,
618 FormatUnit::RR,
619 FormatUnit::V8,
620 FormatUnit::V8,
621 FormatUnit::V8,
622 ],
623 ),
624 ),
625 (
627 0x30,
628 ByteCodeFormat::new(
629 "callthis3 RR, vAA, vBB, vCC, vDD".to_owned(),
630 vec![
631 FormatUnit::Opcode,
632 FormatUnit::RR,
633 FormatUnit::V8,
634 FormatUnit::V8,
635 FormatUnit::V8,
636 FormatUnit::V8,
637 ],
638 ),
639 ),
640 (
642 0x31,
643 ByteCodeFormat::new(
644 "callthisrange RR, +AA, vBB".to_owned(),
645 vec![
646 FormatUnit::Opcode,
647 FormatUnit::RR,
648 FormatUnit::IMM8,
649 FormatUnit::V8,
650 ],
651 ),
652 ),
653 (
655 0x32,
656 ByteCodeFormat::new(
657 "supercallthisrange RR, +AA, vBB".to_owned(),
658 vec![
659 FormatUnit::Opcode,
660 FormatUnit::RR,
661 FormatUnit::IMM8,
662 FormatUnit::V8,
663 ],
664 ),
665 ),
666 (
668 0x33,
669 ByteCodeFormat::new(
670 "definefunc RR, @AAAA, +BB".to_owned(),
671 vec![
672 FormatUnit::Opcode,
673 FormatUnit::RR,
674 FormatUnit::MethodID,
675 FormatUnit::IMM8,
676 ],
677 ),
678 ),
679 (
681 0x34,
682 ByteCodeFormat::new(
683 "definemethod RR, @AAAA, +BB".to_owned(),
684 vec![
685 FormatUnit::Opcode,
686 FormatUnit::RR,
687 FormatUnit::MethodID,
688 FormatUnit::IMM8,
689 ],
690 ),
691 ),
692 (
694 0x35,
695 ByteCodeFormat::new(
696 "defineclasswithbuffer RR, @AAAA, @BBBB, +CCCC, vDD".to_owned(),
697 vec![
698 FormatUnit::Opcode,
699 FormatUnit::RR,
700 FormatUnit::MethodID,
701 FormatUnit::LiteralID,
702 FormatUnit::IMM16,
703 FormatUnit::V8,
704 ],
705 ),
706 ),
707 (
709 0x36,
710 ByteCodeFormat::new(
711 "getnextpropname".to_owned(),
712 vec![FormatUnit::Opcode, FormatUnit::V8],
713 ),
714 ),
715 (
717 0x37,
718 ByteCodeFormat::new(
719 "ldobjbyvalue RR, vAA".to_owned(),
720 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
721 ),
722 ),
723 (
725 0x38,
726 ByteCodeFormat::new(
727 "stobjbyvalue RR, vAA, vBB".to_owned(),
728 vec![
729 FormatUnit::Opcode,
730 FormatUnit::RR,
731 FormatUnit::V8,
732 FormatUnit::V8,
733 ],
734 ),
735 ),
736 (
738 0x39,
739 ByteCodeFormat::new(
740 "ldsuperbyvalue RR, vAA".to_owned(),
741 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
742 ),
743 ),
744 (
746 0x3a,
747 ByteCodeFormat::new(
748 "ldobjbyindex RR, +AAAA".to_owned(),
749 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::IMM16],
750 ),
751 ),
752 (
754 0x3b,
755 ByteCodeFormat::new(
756 "stobjbyindex RR, vAA, +BBBB".to_owned(),
757 vec![
758 FormatUnit::Opcode,
759 FormatUnit::RR,
760 FormatUnit::V8,
761 FormatUnit::IMM16,
762 ],
763 ),
764 ),
765 (
767 0x3c,
768 ByteCodeFormat::new(
769 "ldlexvar +A, +B".to_owned(),
770 vec![FormatUnit::Opcode, FormatUnit::Imm4Imm4],
771 ),
772 ),
773 (
775 0x3d,
776 ByteCodeFormat::new(
777 "stlexvar +A, +B".to_owned(),
778 vec![FormatUnit::Opcode, FormatUnit::Imm4Imm4],
779 ),
780 ),
781 (
783 0x3e,
784 ByteCodeFormat::new(
785 "lda.str @AAAA".to_owned(),
786 vec![FormatUnit::Opcode, FormatUnit::StringID],
787 ),
788 ),
789 (
791 0x3f,
792 ByteCodeFormat::new(
793 "tryldglobalbyname RR, @AAAA".to_owned(),
794 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
795 ),
796 ),
797 (
799 0x40,
800 ByteCodeFormat::new(
801 "trystglobalbyname RR, @AAAA".to_owned(),
802 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
803 ),
804 ),
805 (
807 0x41,
808 ByteCodeFormat::new(
809 "ldglobalvar RRRR, @AAAA".to_owned(),
810 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::StringID],
811 ),
812 ),
813 (
815 0x42,
816 ByteCodeFormat::new(
817 "ldobjbyname RR, @AAAA".to_owned(),
818 vec![FormatUnit::Opcode, FormatUnit::IMM8, FormatUnit::StringID],
819 ),
820 ),
821 (
823 0x43,
824 ByteCodeFormat::new(
825 "stobjbyname RR, @AAAA, vBB".to_owned(),
826 vec![
827 FormatUnit::Opcode,
828 FormatUnit::RR,
829 FormatUnit::StringID,
830 FormatUnit::V8,
831 ],
832 ),
833 ),
834 (
836 0x44,
837 ByteCodeFormat::new(
838 "mov vA, vB".to_owned(),
839 vec![FormatUnit::Opcode, FormatUnit::V4V4],
840 ),
841 ),
842 (
844 0x45,
845 ByteCodeFormat::new(
846 "mov vAA, vBB".to_owned(),
847 vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::V8],
848 ),
849 ),
850 (
852 0x46,
853 ByteCodeFormat::new(
854 "ldsuperbyname RR, @AAAA".to_owned(),
855 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
856 ),
857 ),
858 (
860 0x47,
861 ByteCodeFormat::new(
862 "stconsttoglobalrecord RRRR, @AAAA".to_owned(),
863 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::StringID],
864 ),
865 ),
866 (
868 0x48,
869 ByteCodeFormat::new(
870 "stconsttoglobalrecord RRRR, @AAAA".to_owned(),
871 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::StringID],
872 ),
873 ),
874 (
876 0x49,
877 ByteCodeFormat::new(
878 "ldthisbyname RR, @AAAA".to_owned(),
879 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
880 ),
881 ),
882 (
884 0x4a,
885 ByteCodeFormat::new(
886 "stthisbyname RR, @AAAA".to_owned(),
887 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
888 ),
889 ),
890 (
892 0x4b,
893 ByteCodeFormat::new(
894 "ldthisbyvalue RR".to_owned(),
895 vec![FormatUnit::Opcode, FormatUnit::RR],
896 ),
897 ),
898 (
900 0x4c,
901 ByteCodeFormat::new(
902 "stthisbyvalue RR, vAA".to_owned(),
903 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
904 ),
905 ),
906 (
908 0x4d,
909 ByteCodeFormat::new(
910 "jmp +AA".to_owned(),
911 vec![FormatUnit::Opcode, FormatUnit::IMM8],
912 ),
913 ),
914 (
916 0x4e,
917 ByteCodeFormat::new(
918 "jmp +AAAA".to_owned(),
919 vec![FormatUnit::Opcode, FormatUnit::IMM16],
920 ),
921 ),
922 (
924 0x4f,
925 ByteCodeFormat::new(
926 "jeqz +AA".to_owned(),
927 vec![FormatUnit::Opcode, FormatUnit::IMM8],
928 ),
929 ),
930 (
932 0x50,
933 ByteCodeFormat::new(
934 "jeqz +AAAA".to_owned(),
935 vec![FormatUnit::Opcode, FormatUnit::IMM16],
936 ),
937 ),
938 (
940 0x51,
941 ByteCodeFormat::new(
942 "jnez +AA".to_owned(),
943 vec![FormatUnit::Opcode, FormatUnit::IMM8],
944 ),
945 ),
946 (
948 0x52,
949 ByteCodeFormat::new(
950 "jstricteqz +AA".to_owned(),
951 vec![FormatUnit::Opcode, FormatUnit::IMM8],
952 ),
953 ),
954 (
956 0x53,
957 ByteCodeFormat::new(
958 "jnstricteqz +AA".to_owned(),
959 vec![FormatUnit::Opcode, FormatUnit::IMM8],
960 ),
961 ),
962 (
964 0x54,
965 ByteCodeFormat::new(
966 "jeqnull +AA".to_owned(),
967 vec![FormatUnit::Opcode, FormatUnit::IMM8],
968 ),
969 ),
970 (
972 0x55,
973 ByteCodeFormat::new(
974 "jnenull +AA".to_owned(),
975 vec![FormatUnit::Opcode, FormatUnit::IMM8],
976 ),
977 ),
978 (
980 0x56,
981 ByteCodeFormat::new(
982 "jstricteqnull +AA".to_owned(),
983 vec![FormatUnit::Opcode, FormatUnit::IMM8],
984 ),
985 ),
986 (
988 0x57,
989 ByteCodeFormat::new(
990 "jnstricteqnull +AA".to_owned(),
991 vec![FormatUnit::Opcode, FormatUnit::IMM8],
992 ),
993 ),
994 (
996 0x58,
997 ByteCodeFormat::new(
998 "jequndefined +AA".to_owned(),
999 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1000 ),
1001 ),
1002 (
1004 0x59,
1005 ByteCodeFormat::new(
1006 "jneundefined +AA".to_owned(),
1007 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1008 ),
1009 ),
1010 (
1012 0x5a,
1013 ByteCodeFormat::new(
1014 "jstrictequndefined +AA".to_owned(),
1015 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1016 ),
1017 ),
1018 (
1020 0x5b,
1021 ByteCodeFormat::new(
1022 "jnstrictequndefined +AA".to_owned(),
1023 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1024 ),
1025 ),
1026 (
1028 0x5c,
1029 ByteCodeFormat::new(
1030 "jeq vAA, +BB".to_owned(),
1031 vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::IMM8],
1032 ),
1033 ),
1034 (
1036 0x5d,
1037 ByteCodeFormat::new(
1038 "jne vAA, +BB".to_owned(),
1039 vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::IMM8],
1040 ),
1041 ),
1042 (
1044 0x5e,
1045 ByteCodeFormat::new(
1046 "jstricteq vAA, +BB".to_owned(),
1047 vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::IMM8],
1048 ),
1049 ),
1050 (
1052 0x5f,
1053 ByteCodeFormat::new(
1054 "jnstricteq vAA, +BB".to_owned(),
1055 vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::IMM8],
1056 ),
1057 ),
1058 (
1060 0x60,
1061 ByteCodeFormat::new(
1062 "lda vAA".to_owned(),
1063 vec![FormatUnit::Opcode, FormatUnit::V8],
1064 ),
1065 ),
1066 (
1068 0x61,
1069 ByteCodeFormat::new(
1070 "sta vAA".to_owned(),
1071 vec![FormatUnit::Opcode, FormatUnit::V8],
1072 ),
1073 ),
1074 (
1076 0x62,
1077 ByteCodeFormat::new(
1078 "ldai".to_owned(),
1079 vec![FormatUnit::Opcode, FormatUnit::IMM32],
1080 ),
1081 ),
1082 (
1084 0x63,
1085 ByteCodeFormat::new(
1086 "fldai".to_owned(),
1087 vec![FormatUnit::Opcode, FormatUnit::IMM64],
1088 ),
1089 ),
1090 (
1092 0x64,
1093 ByteCodeFormat::new("return".to_owned(), vec![FormatUnit::Opcode]),
1094 ),
1095 (
1097 0x65,
1098 ByteCodeFormat::new("returnundefined".to_owned(), vec![FormatUnit::Opcode]),
1099 ),
1100 (
1102 0x66,
1103 ByteCodeFormat::new("getpropiterator".to_owned(), vec![FormatUnit::Opcode]),
1104 ),
1105 (
1107 0x67,
1108 ByteCodeFormat::new(
1109 "getiterator".to_owned(),
1110 vec![FormatUnit::Opcode, FormatUnit::RR],
1111 ),
1112 ),
1113 (
1115 0x68,
1116 ByteCodeFormat::new(
1117 "closeiterator".to_owned(),
1118 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
1119 ),
1120 ),
1121 (
1123 0x69,
1124 ByteCodeFormat::new("poplexenv".to_owned(), vec![FormatUnit::Opcode]),
1125 ),
1126 (
1128 0x6a,
1129 ByteCodeFormat::new("ldnan".to_owned(), vec![FormatUnit::Opcode]),
1130 ),
1131 (
1133 0x6b,
1134 ByteCodeFormat::new("ldinfinity".to_owned(), vec![FormatUnit::Opcode]),
1135 ),
1136 (
1138 0x6c,
1139 ByteCodeFormat::new("getunmappedargs".to_owned(), vec![FormatUnit::Opcode]),
1140 ),
1141 (
1143 0x6d,
1144 ByteCodeFormat::new("ldglobal".to_owned(), vec![FormatUnit::Opcode]),
1145 ),
1146 (
1148 0x6e,
1149 ByteCodeFormat::new("ldnewtarget".to_owned(), vec![FormatUnit::Opcode]),
1150 ),
1151 (
1153 0x6f,
1154 ByteCodeFormat::new("ldthis".to_owned(), vec![FormatUnit::Opcode]),
1155 ),
1156 (
1158 0x70,
1159 ByteCodeFormat::new("ldhole".to_owned(), vec![FormatUnit::Opcode]),
1160 ),
1161 (
1163 0x71,
1164 ByteCodeFormat::new(
1165 "createregexpwithliteral".to_owned(),
1166 vec![
1167 FormatUnit::Opcode,
1168 FormatUnit::RR,
1169 FormatUnit::MethodID,
1170 FormatUnit::IMM8,
1171 ],
1172 ),
1173 ),
1174 (
1176 0x72,
1177 ByteCodeFormat::new(
1178 "createregexpwithliteral".to_owned(),
1179 vec![
1180 FormatUnit::Opcode,
1181 FormatUnit::RRRR,
1182 FormatUnit::StringID,
1183 FormatUnit::IMM8,
1184 ],
1185 ),
1186 ),
1187 (
1189 0x73,
1190 ByteCodeFormat::new(
1191 "callrange".to_owned(),
1192 vec![
1193 FormatUnit::Opcode,
1194 FormatUnit::RR,
1195 FormatUnit::IMM8,
1196 FormatUnit::V8,
1197 ],
1198 ),
1199 ),
1200 (
1202 0x74,
1203 ByteCodeFormat::new(
1204 "definefunc".to_owned(),
1205 vec![
1206 FormatUnit::Opcode,
1207 FormatUnit::RRRR,
1208 FormatUnit::MethodID,
1209 FormatUnit::IMM8,
1210 ],
1211 ),
1212 ),
1213 (
1215 0x75,
1216 ByteCodeFormat::new(
1217 "defineclasswithbuffer".to_owned(),
1218 vec![
1219 FormatUnit::Opcode,
1220 FormatUnit::RRRR,
1221 FormatUnit::MethodID,
1222 FormatUnit::LiteralID,
1223 FormatUnit::IMM16,
1224 FormatUnit::V8,
1225 ],
1226 ),
1227 ),
1228 (
1230 0x76,
1231 ByteCodeFormat::new(
1232 "gettemplateobject".to_owned(),
1233 vec![FormatUnit::Opcode, FormatUnit::RR],
1234 ),
1235 ),
1236 (
1238 0x77,
1239 ByteCodeFormat::new(
1240 "setobjectwithproto".to_owned(),
1241 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
1242 ),
1243 ),
1244 (
1246 0x78,
1247 ByteCodeFormat::new(
1248 "stownbyvalue".to_owned(),
1249 vec![
1250 FormatUnit::Opcode,
1251 FormatUnit::RR,
1252 FormatUnit::V8,
1253 FormatUnit::V8,
1254 ],
1255 ),
1256 ),
1257 (
1259 0x79,
1260 ByteCodeFormat::new(
1261 "stownbyindex".to_owned(),
1262 vec![
1263 FormatUnit::Opcode,
1264 FormatUnit::RR,
1265 FormatUnit::V8,
1266 FormatUnit::IMM16,
1267 ],
1268 ),
1269 ),
1270 (
1272 0x7a,
1273 ByteCodeFormat::new(
1274 "stownbyname".to_owned(),
1275 vec![
1276 FormatUnit::Opcode,
1277 FormatUnit::RR,
1278 FormatUnit::StringID,
1279 FormatUnit::V8,
1280 ],
1281 ),
1282 ),
1283 (
1285 0x7b,
1286 ByteCodeFormat::new(
1287 "getmodulenamespace".to_owned(),
1288 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1289 ),
1290 ),
1291 (
1293 0x7c,
1294 ByteCodeFormat::new(
1295 "stmodulevar".to_owned(),
1296 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1297 ),
1298 ),
1299 (
1301 0x7d,
1302 ByteCodeFormat::new(
1303 "ldlocalmodulevar".to_owned(),
1304 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1305 ),
1306 ),
1307 (
1309 0x7e,
1310 ByteCodeFormat::new(
1311 "ldexternalmodulevar +AA".to_owned(),
1312 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1313 ),
1314 ),
1315 (
1317 0x7f,
1318 ByteCodeFormat::new(
1319 "stglobalvar".to_owned(),
1320 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::StringID],
1321 ),
1322 ),
1323 (
1325 0x80,
1326 ByteCodeFormat::new(
1327 "createemptyarray".to_owned(),
1328 vec![FormatUnit::Opcode, FormatUnit::RRRR],
1329 ),
1330 ),
1331 (
1333 0x81,
1334 ByteCodeFormat::new(
1335 "createarraywithbuffer".to_owned(),
1336 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::LiteralID],
1337 ),
1338 ),
1339 (
1341 0x82,
1342 ByteCodeFormat::new(
1343 "createobjectwithbuffer".to_owned(),
1344 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::LiteralID],
1345 ),
1346 ),
1347 (
1349 0x83,
1350 ByteCodeFormat::new(
1351 "newobjrange".to_owned(),
1352 vec![
1353 FormatUnit::Opcode,
1354 FormatUnit::RRRR,
1355 FormatUnit::IMM8,
1356 FormatUnit::V8,
1357 ],
1358 ),
1359 ),
1360 (
1362 0x84,
1363 ByteCodeFormat::new(
1364 "typeof".to_owned(),
1365 vec![FormatUnit::Opcode, FormatUnit::RRRR],
1366 ),
1367 ),
1368 (
1370 0x85,
1371 ByteCodeFormat::new(
1372 "ldobjbyvalue".to_owned(),
1373 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::V8],
1374 ),
1375 ),
1376 (
1378 0x86,
1379 ByteCodeFormat::new(
1380 "stobjbyvalue".to_owned(),
1381 vec![
1382 FormatUnit::Opcode,
1383 FormatUnit::RRRR,
1384 FormatUnit::V8,
1385 FormatUnit::V8,
1386 ],
1387 ),
1388 ),
1389 (
1391 0x87,
1392 ByteCodeFormat::new(
1393 "ldsuperbyvalue".to_owned(),
1394 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::V8],
1395 ),
1396 ),
1397 (
1437 0xad,
1438 ByteCodeFormat::new("ldsymbol".to_owned(), vec![FormatUnit::Opcode]),
1439 ),
1440 (
1442 0xae,
1443 ByteCodeFormat::new("asyncfunctionenter".to_owned(), vec![FormatUnit::Opcode]),
1444 ),
1445 (
1447 0xaf,
1448 ByteCodeFormat::new("ldfunction".to_owned(), vec![FormatUnit::Opcode]),
1449 ),
1450 (
1452 0xb0,
1453 ByteCodeFormat::new("debugger".to_owned(), vec![FormatUnit::Opcode]),
1454 ),
1455 (
1457 0xb1,
1458 ByteCodeFormat::new(
1459 "creategeneratorobj vAA".to_owned(),
1460 vec![FormatUnit::Opcode, FormatUnit::V8],
1461 ),
1462 ),
1463 (
1465 0xb2,
1466 ByteCodeFormat::new(
1467 "createiterresultobj vAA, vBB".to_owned(),
1468 vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::V8],
1469 ),
1470 ),
1471 (
1473 0xb3,
1474 ByteCodeFormat::new(
1475 "createobjectwithexcludedkeys +AA, vBB, vCC".to_owned(),
1476 vec![
1477 FormatUnit::Opcode,
1478 FormatUnit::IMM8,
1479 FormatUnit::V8,
1480 FormatUnit::V8,
1481 ],
1482 ),
1483 ),
1484 (
1486 0xb4,
1487 ByteCodeFormat::new(
1488 "newobjapply RR, vAA".to_owned(),
1489 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
1490 ),
1491 ),
1492 (
1494 0xb5,
1495 ByteCodeFormat::new(
1496 "newobjapply RRRR, vAA".to_owned(),
1497 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::V8],
1498 ),
1499 ),
1500 (
1502 0xb6,
1503 ByteCodeFormat::new(
1504 "newlexenvwithname".to_owned(),
1505 vec![FormatUnit::Opcode, FormatUnit::IMM8, FormatUnit::LiteralID],
1506 ),
1507 ),
1508 (
1510 0xb7,
1511 ByteCodeFormat::new(
1512 "createasyncgeneratorobj vAA".to_owned(),
1513 vec![FormatUnit::Opcode, FormatUnit::V8],
1514 ),
1515 ),
1516 (
1518 0xb8,
1519 ByteCodeFormat::new(
1520 "asyncgeneratorresolve".to_owned(),
1521 vec![
1522 FormatUnit::Opcode,
1523 FormatUnit::V8,
1524 FormatUnit::V8,
1525 FormatUnit::V8,
1526 ],
1527 ),
1528 ),
1529 (
1531 0xb9,
1532 ByteCodeFormat::new(
1533 "supercallspread RR, vAA".to_owned(),
1534 vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
1535 ),
1536 ),
1537 (
1539 0xba,
1540 ByteCodeFormat::new(
1541 "applyspread RR, vAA, vBB".to_owned(),
1542 vec![
1543 FormatUnit::Opcode,
1544 FormatUnit::RR,
1545 FormatUnit::V8,
1546 FormatUnit::V8,
1547 ],
1548 ),
1549 ),
1550 (
1552 0xba,
1553 ByteCodeFormat::new(
1554 "apply RR, vAA, vBB".to_owned(),
1555 vec![
1556 FormatUnit::Opcode,
1557 FormatUnit::RR,
1558 FormatUnit::V8,
1559 FormatUnit::V8,
1560 ],
1561 ),
1562 ),
1563 (
1565 0xbb,
1566 ByteCodeFormat::new(
1567 "supercallarrowrange".to_owned(),
1568 vec![
1569 FormatUnit::Opcode,
1570 FormatUnit::RR,
1571 FormatUnit::IMM8,
1572 FormatUnit::V8,
1573 ],
1574 ),
1575 ),
1576 (
1578 0xbc,
1579 ByteCodeFormat::new(
1580 "definegettersetterbyvalue".to_owned(),
1581 vec![
1582 FormatUnit::Opcode,
1583 FormatUnit::V8,
1584 FormatUnit::V8,
1585 FormatUnit::V8,
1586 FormatUnit::V8,
1587 ],
1588 ),
1589 ),
1590 (
1592 0xbd,
1593 ByteCodeFormat::new("dynamicimport".to_owned(), vec![FormatUnit::Opcode]),
1594 ),
1595 (
1597 0xbe,
1598 ByteCodeFormat::new(
1599 "definemethod RRRR, @AAAA, +BB".to_owned(),
1600 vec![
1601 FormatUnit::Opcode,
1602 FormatUnit::RRRR,
1603 FormatUnit::MethodID,
1604 FormatUnit::IMM8,
1605 ],
1606 ),
1607 ),
1608 (
1610 0xbf,
1611 ByteCodeFormat::new("resumegenerator".to_owned(), vec![FormatUnit::Opcode]),
1612 ),
1613 (
1615 0xc0,
1616 ByteCodeFormat::new("getresumemode".to_owned(), vec![FormatUnit::Opcode]),
1617 ),
1618 (
1620 0xc1,
1621 ByteCodeFormat::new(
1622 "gettemplateobject RRRR".to_owned(),
1623 vec![FormatUnit::Opcode, FormatUnit::RRRR],
1624 ),
1625 ),
1626 (
1628 0xc2,
1629 ByteCodeFormat::new(
1630 "delobjprop vAA".to_owned(),
1631 vec![FormatUnit::Opcode, FormatUnit::V8],
1632 ),
1633 ),
1634 (
1636 0xc3,
1637 ByteCodeFormat::new(
1638 "suspendgenerator vAA".to_owned(),
1639 vec![FormatUnit::Opcode, FormatUnit::V8],
1640 ),
1641 ),
1642 (
1644 0xc4,
1645 ByteCodeFormat::new(
1646 "asyncfunctionawaituncaught vAA".to_owned(),
1647 vec![FormatUnit::Opcode, FormatUnit::V8],
1648 ),
1649 ),
1650 (
1652 0xc5,
1653 ByteCodeFormat::new(
1654 "copydataproperties vAA".to_owned(),
1655 vec![FormatUnit::Opcode, FormatUnit::V8],
1656 ),
1657 ),
1658 (
1660 0xc6,
1661 ByteCodeFormat::new(
1662 "starrayspread vAA, vBB".to_owned(),
1663 vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::V8],
1664 ),
1665 ),
1666 (
1668 0xc7,
1669 ByteCodeFormat::new(
1670 "setobjectwithproto RRRR, vAA".to_owned(),
1671 vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::V8],
1672 ),
1673 ),
1674 (
1676 0xc8,
1677 ByteCodeFormat::new(
1678 "stownbyvalue RRRR, vAA, vBB".to_owned(),
1679 vec![
1680 FormatUnit::Opcode,
1681 FormatUnit::RRRR,
1682 FormatUnit::V8,
1683 FormatUnit::V8,
1684 ],
1685 ),
1686 ),
1687 (
1689 0xc9,
1690 ByteCodeFormat::new(
1691 "stsuperbyvalue RR, vAA, vBB".to_owned(),
1692 vec![
1693 FormatUnit::Opcode,
1694 FormatUnit::IMM8,
1695 FormatUnit::V8,
1696 FormatUnit::V8,
1697 ],
1698 ),
1699 ),
1700 (
1702 0xca,
1703 ByteCodeFormat::new(
1704 "stsuperbyvalue RRRR, vAA, vBB".to_owned(),
1705 vec![
1706 FormatUnit::Opcode,
1707 FormatUnit::RRRR,
1708 FormatUnit::V8,
1709 FormatUnit::V8,
1710 ],
1711 ),
1712 ),
1713 (
1715 0xcb,
1716 ByteCodeFormat::new(
1717 "stownbyindex RRRR, vAA, +BBBB".to_owned(),
1718 vec![
1719 FormatUnit::Opcode,
1720 FormatUnit::RRRR,
1721 FormatUnit::V8,
1722 FormatUnit::IMM16,
1723 ],
1724 ),
1725 ),
1726 (
1728 0xcc,
1729 ByteCodeFormat::new(
1730 "stownbyname RRRR, @AAAA, vBB".to_owned(),
1731 vec![
1732 FormatUnit::Opcode,
1733 FormatUnit::RRRR,
1734 FormatUnit::StringID,
1735 FormatUnit::V8,
1736 ],
1737 ),
1738 ),
1739 (
1741 0xcd,
1742 ByteCodeFormat::new("asyncfunctionresolve".to_owned(), vec![FormatUnit::Opcode]),
1743 ),
1744 (
1746 0xce,
1747 ByteCodeFormat::new("asyncfunctionreject".to_owned(), vec![FormatUnit::Opcode]),
1748 ),
1749 (
1751 0xcf,
1752 ByteCodeFormat::new(
1753 "copyrestargs".to_owned(),
1754 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1755 ),
1756 ),
1757 (
1759 0xd0,
1760 ByteCodeFormat::new(
1761 "stsuperbyname".to_owned(),
1762 vec![
1763 FormatUnit::Opcode,
1764 FormatUnit::RR,
1765 FormatUnit::StringID,
1766 FormatUnit::V8,
1767 ],
1768 ),
1769 ),
1770 (
1772 0xd1,
1773 ByteCodeFormat::new(
1774 "stsuperbyname".to_owned(),
1775 vec![
1776 FormatUnit::Opcode,
1777 FormatUnit::RRRR,
1778 FormatUnit::StringID,
1779 FormatUnit::V8,
1780 ],
1781 ),
1782 ),
1783 (
1785 0xd2,
1786 ByteCodeFormat::new(
1787 "stownbyvaluewithnameset".to_owned(),
1788 vec![
1789 FormatUnit::Opcode,
1790 FormatUnit::RRRR,
1791 FormatUnit::V8,
1792 FormatUnit::V8,
1793 ],
1794 ),
1795 ),
1796 (
1798 0xd3,
1799 ByteCodeFormat::new(
1800 "ldbigint".to_owned(),
1801 vec![FormatUnit::Opcode, FormatUnit::StringID],
1802 ),
1803 ),
1804 (
1806 0xd4,
1807 ByteCodeFormat::new(
1808 "stownbynamewithnameset".to_owned(),
1809 vec![
1810 FormatUnit::Opcode,
1811 FormatUnit::RRRR,
1812 FormatUnit::StringID,
1813 FormatUnit::V8,
1814 ],
1815 ),
1816 ),
1817 (
1819 0xd5,
1820 ByteCodeFormat::new("nop".to_owned(), vec![FormatUnit::Opcode]),
1821 ),
1822 (
1824 0xd6,
1825 ByteCodeFormat::new(
1826 "setgeneratorstate".to_owned(),
1827 vec![FormatUnit::Opcode, FormatUnit::IMM8],
1828 ),
1829 ),
1830 (
1832 0xd7,
1833 ByteCodeFormat::new(
1834 "getasynciterator".to_owned(),
1835 vec![FormatUnit::Opcode, FormatUnit::RR],
1836 ),
1837 ),
1838 (
1840 0xd8,
1841 ByteCodeFormat::new(
1842 "ldprivateproperty".to_owned(),
1843 vec![
1844 FormatUnit::Opcode,
1845 FormatUnit::RR,
1846 FormatUnit::IMM16,
1847 FormatUnit::IMM16,
1848 ],
1849 ),
1850 ),
1851 (
1853 0xd9,
1854 ByteCodeFormat::new(
1855 "stprivateproperty".to_owned(),
1856 vec![
1857 FormatUnit::Opcode,
1858 FormatUnit::RR,
1859 FormatUnit::IMM16,
1860 FormatUnit::IMM16,
1861 FormatUnit::V8,
1862 ],
1863 ),
1864 ),
1865 (
1867 0xda,
1868 ByteCodeFormat::new(
1869 "testin".to_owned(),
1870 vec![
1871 FormatUnit::Opcode,
1872 FormatUnit::RR,
1873 FormatUnit::IMM16,
1874 FormatUnit::IMM16,
1875 ],
1876 ),
1877 ),
1878 (
1880 0xdb,
1881 ByteCodeFormat::new(
1882 "definefieldbyname".to_owned(),
1883 vec![
1884 FormatUnit::Opcode,
1885 FormatUnit::RR,
1886 FormatUnit::StringID,
1887 FormatUnit::V8,
1888 ],
1889 ),
1890 ),
1891 (
1893 0xfb,
1894 ByteCodeFormat::new(
1895 "callruntime.notifyconcurrentresult".to_owned(),
1896 vec![FormatUnit::PrefixOpcode],
1897 ),
1898 ),
1899 (
1901 0xfd,
1902 ByteCodeFormat::new(
1903 "wide.createobjectwithexcludedkeys".to_owned(),
1904 vec![
1905 FormatUnit::PrefixOpcode,
1906 FormatUnit::IMM16,
1907 FormatUnit::V8,
1908 FormatUnit::V8,
1909 ],
1910 ),
1911 ),
1912 (
1914 0xfe,
1915 ByteCodeFormat::new("thrown".to_owned(), vec![FormatUnit::PrefixOpcode]),
1916 ),
1917 ];
1918
1919 let mut map = HashMap::new();
1920 for team in &opcode_vec {
1921 map.insert(team.0, team.1.clone());
1922 }
1923 map
1924}
1925
1926fn init_prefix_opcode_map() -> HashMap<u16, ByteCodeFormat> {
1927 let prefix_opcode_vec = vec![
1928 (
1929 0x01fb,
1930 ByteCodeFormat::new(
1931 "callruntime.definefieldbyvalue RR, vAA, vBB".to_owned(),
1932 vec![
1933 FormatUnit::PrefixOpcode,
1934 FormatUnit::RR,
1935 FormatUnit::V8,
1936 FormatUnit::V8,
1937 ],
1938 ),
1939 ),
1940 (
1941 0x01fd,
1942 ByteCodeFormat::new(
1943 "wide.newobjrange +AAAA, vBB".to_owned(),
1944 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
1945 ),
1946 ),
1947 (
1948 0x01fe,
1949 ByteCodeFormat::new("throw.notexists".to_owned(), vec![FormatUnit::PrefixOpcode]),
1950 ),
1951 (
1952 0x02fb,
1953 ByteCodeFormat::new(
1954 "callruntime.definefieldbyindex RR, +AAAAAAAA, vBB".to_owned(),
1955 vec![
1956 FormatUnit::PrefixOpcode,
1957 FormatUnit::RR,
1958 FormatUnit::IMM32,
1959 FormatUnit::V8,
1960 ],
1961 ),
1962 ),
1963 (
1964 0x02fd,
1965 ByteCodeFormat::new(
1966 "wide.newlexenv +AAAA".to_owned(),
1967 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
1968 ),
1969 ),
1970 (
1971 0x02fe,
1972 ByteCodeFormat::new(
1973 "throw.patternnoncoercible".to_owned(),
1974 vec![FormatUnit::PrefixOpcode],
1975 ),
1976 ),
1977 (
1978 0x03fb,
1979 ByteCodeFormat::new(
1980 "wide.newlexenvwithname +AAAA, @BBBB".to_owned(),
1981 vec![
1982 FormatUnit::PrefixOpcode,
1983 FormatUnit::IMM16,
1984 FormatUnit::LiteralID,
1985 ],
1986 ),
1987 ),
1988 (
1989 0x03fe,
1990 ByteCodeFormat::new(
1991 "throw.deletesuperproperty".to_owned(),
1992 vec![FormatUnit::PrefixOpcode],
1993 ),
1994 ),
1995 (
1996 0x04fb,
1997 ByteCodeFormat::new(
1998 "callruntime.createprivateproperty +AAAA, @BBBB".to_owned(),
1999 vec![
2000 FormatUnit::PrefixOpcode,
2001 FormatUnit::IMM16,
2002 FormatUnit::LiteralID,
2003 ],
2004 ),
2005 ),
2006 (
2007 0x04fd,
2008 ByteCodeFormat::new(
2009 "wide.callrange +AAAA, vBB".to_owned(),
2010 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2011 ),
2012 ),
2013 (
2015 0x04fe,
2016 ByteCodeFormat::new(
2017 "throw.constassignment".to_owned(),
2018 vec![FormatUnit::PrefixOpcode, FormatUnit::V8],
2019 ),
2020 ),
2021 (
2023 0x05fb,
2024 ByteCodeFormat::new(
2025 "callruntime.defineprivateproperty".to_owned(),
2026 vec![
2027 FormatUnit::PrefixOpcode,
2028 FormatUnit::RR,
2029 FormatUnit::IMM16,
2030 FormatUnit::IMM16,
2031 FormatUnit::V8,
2032 ],
2033 ),
2034 ),
2035 (
2037 0x05fd,
2038 ByteCodeFormat::new(
2039 "wide.callthisrange".to_owned(),
2040 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2041 ),
2042 ),
2043 (
2045 0x05fe,
2046 ByteCodeFormat::new(
2047 "throw.ifnotobject".to_owned(),
2048 vec![
2049 FormatUnit::PrefixOpcode,
2050 FormatUnit::RR,
2051 FormatUnit::IMM16,
2052 FormatUnit::IMM16,
2053 FormatUnit::V8,
2054 ],
2055 ),
2056 ),
2057 (
2059 0x05fd,
2060 ByteCodeFormat::new(
2061 "wide.callthisrange".to_owned(),
2062 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2063 ),
2064 ),
2065 (
2067 0x05fe,
2068 ByteCodeFormat::new(
2069 "throw.ifnotobject".to_owned(),
2070 vec![FormatUnit::PrefixOpcode, FormatUnit::V8],
2071 ),
2072 ),
2073 (
2075 0x06fb,
2076 ByteCodeFormat::new(
2077 "callruntime.callinit".to_owned(),
2078 vec![FormatUnit::PrefixOpcode, FormatUnit::RR, FormatUnit::V8],
2079 ),
2080 ),
2081 (
2083 0x06fd,
2084 ByteCodeFormat::new(
2085 "wide.supercallthisrange".to_owned(),
2086 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2087 ),
2088 ),
2089 (
2091 0x06fe,
2092 ByteCodeFormat::new(
2093 "throw.undefinedifhole".to_owned(),
2094 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2095 ),
2096 ),
2097 (
2099 0x06fe,
2100 ByteCodeFormat::new(
2101 "throw.undefinedifhole".to_owned(),
2102 vec![FormatUnit::PrefixOpcode, FormatUnit::V8, FormatUnit::V8],
2103 ),
2104 ),
2105 (
2107 0x07fb,
2108 ByteCodeFormat::new(
2109 "callruntime.definesendableclass".to_owned(),
2110 vec![
2111 FormatUnit::PrefixOpcode,
2112 FormatUnit::RRRR,
2113 FormatUnit::MethodID,
2114 FormatUnit::LiteralID,
2115 FormatUnit::IMM16,
2116 FormatUnit::V8,
2117 ],
2118 ),
2119 ),
2120 (
2122 0x07fd,
2123 ByteCodeFormat::new(
2124 "wide.supercallarrowrange".to_owned(),
2125 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2126 ),
2127 ),
2128 (
2130 0x07fe,
2131 ByteCodeFormat::new(
2132 "throw.ifsupernotcorrectcall".to_owned(),
2133 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM8],
2134 ),
2135 ),
2136 (
2138 0x08fb,
2139 ByteCodeFormat::new(
2140 "callruntime.ldsendableclass".to_owned(),
2141 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2142 ),
2143 ),
2144 (
2146 0x08fd,
2147 ByteCodeFormat::new(
2148 "wide.ldobjbyindex".to_owned(),
2149 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM32],
2150 ),
2151 ),
2152 (
2154 0x08fe,
2155 ByteCodeFormat::new(
2156 "throw.ifsupernotcorrectcall".to_owned(),
2157 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2158 ),
2159 ),
2160 (
2162 0x09fd,
2163 ByteCodeFormat::new(
2164 "wide.stobjbyindex".to_owned(),
2165 vec![FormatUnit::PrefixOpcode, FormatUnit::V8, FormatUnit::IMM32],
2166 ),
2167 ),
2168 (
2170 0x09fe,
2171 ByteCodeFormat::new(
2172 "throw.undefinedifholewithname".to_owned(),
2173 vec![FormatUnit::PrefixOpcode, FormatUnit::StringID],
2174 ),
2175 ),
2176 (
2178 0x0afd,
2179 ByteCodeFormat::new(
2180 "wide.stownbyindex vAA, +BBBBBBBB".to_owned(),
2181 vec![FormatUnit::PrefixOpcode, FormatUnit::V8, FormatUnit::IMM32],
2182 ),
2183 ),
2184 (
2186 0x0bfd,
2187 ByteCodeFormat::new(
2188 "wide.copyrestargs +AAAA".to_owned(),
2189 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2190 ),
2191 ),
2192 (
2194 0x0cfd,
2195 ByteCodeFormat::new(
2196 "wide.ldlexvar +AAAA, +BBBB".to_owned(),
2197 vec![
2198 FormatUnit::PrefixOpcode,
2199 FormatUnit::IMM16,
2200 FormatUnit::IMM16,
2201 ],
2202 ),
2203 ),
2204 (
2206 0x0dfd,
2207 ByteCodeFormat::new(
2208 "wide.stlexvar +AAAA, +BBBB".to_owned(),
2209 vec![
2210 FormatUnit::PrefixOpcode,
2211 FormatUnit::IMM16,
2212 FormatUnit::IMM16,
2213 ],
2214 ),
2215 ),
2216 (
2218 0x0efd,
2219 ByteCodeFormat::new(
2220 "wide.getmodulenamespace +AAAA".to_owned(),
2221 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2222 ),
2223 ),
2224 (
2226 0x0ffd,
2227 ByteCodeFormat::new(
2228 "wide.stmodulevar +AAAA".to_owned(),
2229 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2230 ),
2231 ),
2232 (
2234 0x10fd,
2235 ByteCodeFormat::new(
2236 "wide.ldlocalmodulevar +AAAA".to_owned(),
2237 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2238 ),
2239 ),
2240 (
2242 0x11fd,
2243 ByteCodeFormat::new(
2244 "wide.ldexternalmodulevar +AAAA".to_owned(),
2245 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2246 ),
2247 ),
2248 (
2250 0x12fd,
2251 ByteCodeFormat::new(
2252 "wide.ldpatchvar +AAAA".to_owned(),
2253 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2254 ),
2255 ),
2256 (
2258 0x13fd,
2259 ByteCodeFormat::new(
2260 "wide.stpatchvar +AAAA".to_owned(),
2261 vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2262 ),
2263 ),
2264 ];
2265
2266 let mut ok = HashMap::new();
2267 for team in &prefix_opcode_vec {
2268 ok.insert(team.0, team.1.clone());
2269 }
2270 ok
2271}
2272
2273impl BytecodeParser {
2274 pub fn new() -> Self {
2275 let opcode_table = init_opcode_map();
2276 let prefix_opcode_table = init_prefix_opcode_map();
2277
2278 Self {
2279 opcode_table,
2280 prefix_opcode_table,
2281 }
2282 }
2283
2284 fn get_opcode(&self, opcode: u16) -> &ByteCodeFormat {
2285 self.opcode_table.get(&opcode).unwrap()
2286 }
2287
2288 fn get_prefix_opcode(&self, opcode: u16) -> Option<&ByteCodeFormat> {
2289 self.prefix_opcode_table.get(&opcode)
2290 }
2291
2292 pub fn parse(
2293 &self,
2294 code: &Code,
2295 region: &Region,
2296 source: &[u8],
2297 literal_array_map: &HashMap<usize, String>,
2298 ) {
2299 let instructions = code.instructions();
2300 let mut offset = 0;
2301 let size = instructions.len();
2302 loop {
2303 let pref_opcode = instructions.pread::<u16>(offset).unwrap();
2304 let bcf = self.get_prefix_opcode(pref_opcode);
2305
2306 if bcf.is_none() {
2307 let opcode = instructions.pread::<u8>(offset).unwrap();
2308 let bcf = self.get_opcode(opcode as u16);
2309 offset = bcf.parse(instructions, offset, region, source, literal_array_map);
2310 } else {
2311 offset =
2312 bcf.unwrap()
2313 .parse(instructions, offset, region, source, literal_array_map);
2314 }
2315
2316 if offset >= size {
2317 break;
2318 }
2319
2320 if offset + 1 == size {
2322 let opcode = instructions.pread::<u8>(offset).unwrap();
2323 let bcf = self.get_opcode(opcode as u16);
2324 bcf.parse(instructions, offset, region, source, literal_array_map);
2325 break;
2326 }
2327 }
2328 }
2329}
2330
2331impl Default for BytecodeParser {
2332 fn default() -> Self {
2333 Self::new()
2334 }
2335}