xabc_lib/
bytecode.rs

1/// 解析字节码
2use 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// https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-bytecode-fundamentals-V5#字节码格式说明
15/// 格式组成的基本单元
16#[derive(Debug, Clone)]
17pub enum FormatUnit {
18    Opcode,
19    PrefixOpcode,
20    /// 方舟运行时内部使用的8位保留数字,此处提及仅为完整展示指令格式,开发者无需关注。
21    RR,
22    RRRR,
23    /// 特殊的4位寄存器,2个一起出现
24    V4V4,
25    V8,
26    V16,
27    /// 4位立即数,2个一起出现
28    Imm4Imm4,
29    IMM8,
30    IMM16,
31    IMM32,
32    IMM64,
33    /// 16位ID, ID16,
34    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                    // 大小端互换
107                    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                // NOTE: 这个是索引,不是偏移
133                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, self.name, strx);
213        println!("{} : {}", raw, strx);
214
215        offset
216    }
217}
218
219/// 字节码解析器
220pub struct BytecodeParser {
221    // 存放字节码的字节码表
222    pub opcode_table: HashMap<u16, ByteCodeFormat>,
223    // 存放前缀字节码的字节码表
224    pub prefix_opcode_table: HashMap<u16, ByteCodeFormat>,
225}
226
227fn init_opcode_map() -> HashMap<u16, ByteCodeFormat> {
228    let opcode_vec = vec![
229        // 0x00 	NONE 	ldundefined
230        (
231            0x0,
232            ByteCodeFormat::new("ldundefined".to_owned(), vec![FormatUnit::Opcode]),
233        ),
234        // 0x01 	NONE 	ldnull
235        (
236            0x1,
237            ByteCodeFormat::new("ldnull".to_owned(), vec![FormatUnit::Opcode]),
238        ),
239        // 0x02 	NONE 	ldtrue
240        (
241            0x2,
242            ByteCodeFormat::new("ldtrue".to_owned(), vec![FormatUnit::Opcode]),
243        ),
244        // 0x03 	NONE 	ldfalse
245        (
246            0x3,
247            ByteCodeFormat::new("ldfalse".to_owned(), vec![FormatUnit::Opcode]),
248        ),
249        // 0x04 	NONE 	createemptyobject
250        (
251            0x4,
252            ByteCodeFormat::new("createemptyobject".to_owned(), vec![FormatUnit::Opcode]),
253        ),
254        // 0x05 	IMM8 	createemptyarray RR
255        (
256            0x5,
257            ByteCodeFormat::new(
258                "createemptyarray".to_owned(),
259                vec![FormatUnit::Opcode, FormatUnit::RR],
260            ),
261        ),
262        // 0x06 	IMM8_ID16 	createarraywithbuffer RR, @AAAA
263        (
264            0x6,
265            ByteCodeFormat::new(
266                "createarraywithbuffer".to_owned(),
267                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::LiteralID],
268            ),
269        ),
270        // 0x07 	IMM8_ID16 	createobjectwithbuffer RR, @AAAA
271        (
272            0x07,
273            ByteCodeFormat::new(
274                "createobjectwithbuffer".to_owned(),
275                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::LiteralID],
276            ),
277        ),
278        // 0x08 	IMM8_IMM8_V8 	newobjrange RR, +AA, vBB
279        (
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        // 0x09 	IMM8 	newlexenv +AA
292        (
293            0x09,
294            ByteCodeFormat::new(
295                "newlexenv".to_owned(),
296                vec![FormatUnit::Opcode, FormatUnit::IMM8],
297            ),
298        ),
299        // 0x0a 	IMM8_V8 	add2 RR, vAA
300        (
301            0x0a,
302            ByteCodeFormat::new(
303                "add2 RR, vAA".to_owned(),
304                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
305            ),
306        ),
307        // 0x0b 	IMM8_V8 	sub2 RR, vAA
308        (
309            0x0b,
310            ByteCodeFormat::new(
311                "sub2 RR, vAA".to_owned(),
312                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
313            ),
314        ),
315        // 0x0c 	IMM8_V8 	mul2 RR, vAA
316        (
317            0x0c,
318            ByteCodeFormat::new(
319                "mul2 RR, vAA".to_owned(),
320                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
321            ),
322        ),
323        // 0x0d 	IMM8_V8 	div2 RR, vAA
324        (
325            0x0d,
326            ByteCodeFormat::new(
327                "div2 RR, vAA".to_owned(),
328                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
329            ),
330        ),
331        // 0x0e 	IMM8_V8 	mod2 RR, vAA
332        (
333            0x0e,
334            ByteCodeFormat::new(
335                "mod2 RR, vAA".to_owned(),
336                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
337            ),
338        ),
339        // 0x0f 	IMM8_V8 	eq RR, vAA
340        (
341            0x0f,
342            ByteCodeFormat::new(
343                "eq RR, vAA".to_owned(),
344                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
345            ),
346        ),
347        // 0x10 	IMM8_V8 	noteq RR, vAA
348        (
349            0x10,
350            ByteCodeFormat::new(
351                "noteq RR, vAA".to_owned(),
352                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
353            ),
354        ),
355        // 0x11 	IMM8_V8 	less RR, vAA
356        (
357            0x11,
358            ByteCodeFormat::new(
359                "less RR, vAA".to_owned(),
360                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
361            ),
362        ),
363        // 0x12 	IMM8_V8 	lesseq RR, vAA
364        (
365            0x12,
366            ByteCodeFormat::new(
367                "lesseq RR, vAA".to_owned(),
368                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
369            ),
370        ),
371        // 0x13 	IMM8_V8 	greater RR, vAA
372        (
373            0x13,
374            ByteCodeFormat::new(
375                "greater RR, vAA".to_owned(),
376                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
377            ),
378        ),
379        // 0x14 	IMM8_V8 	greatereq RR, vAA
380        (
381            0x13,
382            ByteCodeFormat::new(
383                "greatereq RR, vAA".to_owned(),
384                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
385            ),
386        ),
387        // 0x15 	IMM8_V8 	shl2 RR, vAA
388        (
389            0x15,
390            ByteCodeFormat::new(
391                "shl2 RR, vAA".to_owned(),
392                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
393            ),
394        ),
395        // 0x16 	IMM8_V8 	shr2 RR, vAA
396        (
397            0x16,
398            ByteCodeFormat::new(
399                "shr2 RR, vAA".to_owned(),
400                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
401            ),
402        ),
403        // 0x17 	IMM8_V8 	ashr2 RR, vAA
404        (
405            0x17,
406            ByteCodeFormat::new(
407                "ashr2 RR, vAA".to_owned(),
408                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
409            ),
410        ),
411        // 0x18 	IMM8_V8 	and2 RR, vAA
412        (
413            0x18,
414            ByteCodeFormat::new(
415                "and2 RR, vAA".to_owned(),
416                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
417            ),
418        ),
419        // 0x19 	IMM8_V8 	or2 RR, vAA
420        (
421            0x19,
422            ByteCodeFormat::new(
423                "or2 RR, vAA".to_owned(),
424                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
425            ),
426        ),
427        // 0x1a 	IMM8_V8 	xor2 RR, vAA
428        (
429            0x1a,
430            ByteCodeFormat::new(
431                "xor2 RR, vAA".to_owned(),
432                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
433            ),
434        ),
435        // 0x1b 	IMM8_V8 	exp RR, vAA
436        (
437            0x1b,
438            ByteCodeFormat::new(
439                "exp RR, vAA".to_owned(),
440                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
441            ),
442        ),
443        // 0x1c 	IMM8 	typeof RR
444        (
445            0x1c,
446            ByteCodeFormat::new(
447                "typeof RR".to_owned(),
448                vec![FormatUnit::Opcode, FormatUnit::RR],
449            ),
450        ),
451        // 0x1d 	IMM8 	tonumber RR
452        (
453            0x1d,
454            ByteCodeFormat::new(
455                "tonumber RR".to_owned(),
456                vec![FormatUnit::Opcode, FormatUnit::RR],
457            ),
458        ),
459        // 0x1e 	IMM8 	tonumeric RR
460        (
461            0x1e,
462            ByteCodeFormat::new(
463                "tonumeric RR".to_owned(),
464                vec![FormatUnit::Opcode, FormatUnit::RR],
465            ),
466        ),
467        // 0x1f 	IMM8 	neg RR
468        (
469            0x1f,
470            ByteCodeFormat::new(
471                "neg RR".to_owned(),
472                vec![FormatUnit::Opcode, FormatUnit::RR],
473            ),
474        ),
475        // 0x20 	IMM8 	not RR
476        (
477            0x20,
478            ByteCodeFormat::new(
479                "not RR".to_owned(),
480                vec![FormatUnit::Opcode, FormatUnit::RR],
481            ),
482        ),
483        // 0x21 	IMM8 	inc RR
484        (
485            0x21,
486            ByteCodeFormat::new(
487                "inc RR".to_owned(),
488                vec![FormatUnit::Opcode, FormatUnit::RR],
489            ),
490        ),
491        // 0x22 	IMM8 	dec RR
492        (
493            0x22,
494            ByteCodeFormat::new(
495                "dec RR".to_owned(),
496                vec![FormatUnit::Opcode, FormatUnit::RR],
497            ),
498        ),
499        // 0x23 	NONE 	istrue
500        (
501            0x23,
502            ByteCodeFormat::new(
503                "istrue".to_owned(),
504                vec![FormatUnit::Opcode, FormatUnit::RR],
505            ),
506        ),
507        // 0x24 	NONE 	isfalse
508        (
509            0x24,
510            ByteCodeFormat::new(
511                "isfalse".to_owned(),
512                vec![FormatUnit::Opcode, FormatUnit::RR],
513            ),
514        ),
515        // 0x25 	IMM8_V8 	isin RR, vAA
516        (
517            0x25,
518            ByteCodeFormat::new(
519                "isin RR, vAA".to_owned(),
520                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
521            ),
522        ),
523        // 0x26 	IMM8_V8 	instanceof RR, vAA
524        (
525            0x26,
526            ByteCodeFormat::new(
527                "instanceof RR, vAA".to_owned(),
528                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
529            ),
530        ),
531        // 0x27 	IMM8_V8 	strictnoteq RR, vAA
532        (
533            0x27,
534            ByteCodeFormat::new(
535                "strictnoteq RR, vAA".to_owned(),
536                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
537            ),
538        ),
539        // 0x28 	IMM8_V8 	stricteq RR, vAA
540        (
541            0x28,
542            ByteCodeFormat::new(
543                "stricteq RR, vAA".to_owned(),
544                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
545            ),
546        ),
547        // 0x29 	IMM8 	callarg0 RR
548        (
549            0x29,
550            ByteCodeFormat::new(
551                "callarg0 RR".to_owned(),
552                vec![FormatUnit::Opcode, FormatUnit::RR],
553            ),
554        ),
555        // 0x2a 	IMM8_V8 	callarg1 RR, vAA
556        (
557            0x2a,
558            ByteCodeFormat::new(
559                "callarg1 RR, vAA".to_owned(),
560                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
561            ),
562        ),
563        // 0x2b 	IMM8_V8_V8 	callargs2 RR, vAA, vBB
564        (
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        // 0x2c 	IMM8_V8_V8_V8 	callargs3 RR, vAA, vBB, vCC
577        (
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        // 0x2d 	IMM8_V8 	callthis0 RR, vAA
591        (
592            0x2d,
593            ByteCodeFormat::new(
594                "callthis0 RR, vAA".to_owned(),
595                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
596            ),
597        ),
598        // 0x2e 	IMM8_V8_V8 	callthis1 RR, vAA, vBB
599        (
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        // 0x2f 	IMM8_V8_V8_V8 	callthis2 RR, vAA, vBB, vCC
612        (
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        // 0x30 	IMM8_V8_V8_V8_V8 	callthis3 RR, vAA, vBB, vCC, vDD
626        (
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        // 0x31 	IMM8_IMM8_V8 	callthisrange RR, +AA, vBB
641        (
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        // 0x32 	IMM8_IMM8_V8 	supercallthisrange RR, +AA, vBB
654        (
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        // 0x33 	IMM8_ID16_IMM8 	definefunc RR, @AAAA, +BB
667        (
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        // 0x34 	IMM8_ID16_IMM8 	definemethod RR, @AAAA, +BB
680        (
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        // 0x35 	IMM8_ID16_ID16_IMM16_V8 	defineclasswithbuffer RR, @AAAA, @BBBB, +CCCC, vDD
693        (
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        // 0x36 	V8 	getnextpropname vAA 	A:迭代器 	执行for-in迭代器A的next方法,并将结果存放到acc中。
708        (
709            0x36,
710            ByteCodeFormat::new(
711                "getnextpropname".to_owned(),
712                vec![FormatUnit::Opcode, FormatUnit::V8],
713            ),
714        ),
715        // 0x37 	IMM8_V8 	ldobjbyvalue RR, vAA
716        (
717            0x37,
718            ByteCodeFormat::new(
719                "ldobjbyvalue RR, vAA".to_owned(),
720                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
721            ),
722        ),
723        // 0x38 	IMM8_V8_V8 	stobjbyvalue RR, vAA, vBB
724        (
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        // 0x39 	IMM8_V8 	ldsuperbyvalue RR, vAA
737        (
738            0x39,
739            ByteCodeFormat::new(
740                "ldsuperbyvalue RR, vAA".to_owned(),
741                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
742            ),
743        ),
744        // 0x3a 	IMM8_IMM16 	ldobjbyindex RR, +AAAA
745        (
746            0x3a,
747            ByteCodeFormat::new(
748                "ldobjbyindex RR, +AAAA".to_owned(),
749                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::IMM16],
750            ),
751        ),
752        // 0x3b 	IMM8_V8_IMM16 	stobjbyindex RR, vAA, +BBBB
753        (
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        // 0x3c 	IMM4_IMM4 	ldlexvar +A, +B
766        (
767            0x3c,
768            ByteCodeFormat::new(
769                "ldlexvar +A, +B".to_owned(),
770                vec![FormatUnit::Opcode, FormatUnit::Imm4Imm4],
771            ),
772        ),
773        // 0x3d 	IMM4_IMM4 	stlexvar +A, +B
774        (
775            0x3d,
776            ByteCodeFormat::new(
777                "stlexvar +A, +B".to_owned(),
778                vec![FormatUnit::Opcode, FormatUnit::Imm4Imm4],
779            ),
780        ),
781        // 0x3e 	ID16 	lda.str @AAAA 	A:string id 	将索引A对应的字符串存放到acc中。
782        (
783            0x3e,
784            ByteCodeFormat::new(
785                "lda.str @AAAA".to_owned(),
786                vec![FormatUnit::Opcode, FormatUnit::StringID],
787            ),
788        ),
789        // 0x3f 	IMM8_ID16 	tryldglobalbyname RR, @AAAA
790        (
791            0x3f,
792            ByteCodeFormat::new(
793                "tryldglobalbyname RR, @AAAA".to_owned(),
794                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
795            ),
796        ),
797        // 0x40 	IMM8_ID16 	trystglobalbyname RR, @AAAA
798        (
799            0x40,
800            ByteCodeFormat::new(
801                "trystglobalbyname RR, @AAAA".to_owned(),
802                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
803            ),
804        ),
805        // 0x41 	IMM16_ID16 	ldglobalvar RRRR, @AAAA
806        (
807            0x41,
808            ByteCodeFormat::new(
809                "ldglobalvar RRRR, @AAAA".to_owned(),
810                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::StringID],
811            ),
812        ),
813        // 0x42 	IMM8_ID16 	ldobjbyname RR, @AAAA
814        (
815            0x42,
816            ByteCodeFormat::new(
817                "ldobjbyname RR, @AAAA".to_owned(),
818                vec![FormatUnit::Opcode, FormatUnit::IMM8, FormatUnit::StringID],
819            ),
820        ),
821        // 0x43 	IMM8_ID16_V8 	stobjbyname RR, @AAAA, vBB
822        (
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        // 0x44 	V4_V4 	mov vA, vB 	A, B:寄存器索引 	将寄存器B中的内容复制到寄存器A中。
835        (
836            0x44,
837            ByteCodeFormat::new(
838                "mov vA, vB".to_owned(),
839                vec![FormatUnit::Opcode, FormatUnit::V4V4],
840            ),
841        ),
842        // 0x45 	V8_V8 	mov vAA, vBB
843        (
844            0x45,
845            ByteCodeFormat::new(
846                "mov vAA, vBB".to_owned(),
847                vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::V8],
848            ),
849        ),
850        // 0x46 	IMM8_ID16 	ldsuperbyname RR, @AAAA
851        (
852            0x46,
853            ByteCodeFormat::new(
854                "ldsuperbyname RR, @AAAA".to_owned(),
855                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
856            ),
857        ),
858        // 0x47 	IMM16_ID16 	stconsttoglobalrecord RRRR, @AAAA
859        (
860            0x47,
861            ByteCodeFormat::new(
862                "stconsttoglobalrecord RRRR, @AAAA".to_owned(),
863                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::StringID],
864            ),
865        ),
866        // 0x48 	IMM16_ID16 	sttoglobalrecord RRRR, @AAAA
867        (
868            0x48,
869            ByteCodeFormat::new(
870                "stconsttoglobalrecord RRRR, @AAAA".to_owned(),
871                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::StringID],
872            ),
873        ),
874        // 0x49 	IMM8_ID16 	ldthisbyname RR, @AAAA
875        (
876            0x49,
877            ByteCodeFormat::new(
878                "ldthisbyname RR, @AAAA".to_owned(),
879                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
880            ),
881        ),
882        // 0x4a 	IMM8_ID16 	stthisbyname RR, @AAAA
883        (
884            0x4a,
885            ByteCodeFormat::new(
886                "stthisbyname RR, @AAAA".to_owned(),
887                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::StringID],
888            ),
889        ),
890        // 0x4b 	IMM8 	ldthisbyvalue RR
891        (
892            0x4b,
893            ByteCodeFormat::new(
894                "ldthisbyvalue RR".to_owned(),
895                vec![FormatUnit::Opcode, FormatUnit::RR],
896            ),
897        ),
898        // 0x4c 	IMM8_V8 	stthisbyvalue RR, vAA
899        (
900            0x4c,
901            ByteCodeFormat::new(
902                "stthisbyvalue RR, vAA".to_owned(),
903                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
904            ),
905        ),
906        // 0x4d 	IMM8 	jmp +AA 	A:有符号的分支偏移量 	无条件跳转到分支A。
907        (
908            0x4d,
909            ByteCodeFormat::new(
910                "jmp +AA".to_owned(),
911                vec![FormatUnit::Opcode, FormatUnit::IMM8],
912            ),
913        ),
914        // 0x4e 	IMM16 	jmp +AAAA 	A:有符号的分支偏移量 	无条件跳转到分支A。
915        (
916            0x4e,
917            ByteCodeFormat::new(
918                "jmp +AAAA".to_owned(),
919                vec![FormatUnit::Opcode, FormatUnit::IMM16],
920            ),
921        ),
922        // 0x4f 	IMM8 	jeqz +AA
923        (
924            0x4f,
925            ByteCodeFormat::new(
926                "jeqz +AA".to_owned(),
927                vec![FormatUnit::Opcode, FormatUnit::IMM8],
928            ),
929        ),
930        // 0x50 	IMM16 	jeqz +AAAA
931        (
932            0x50,
933            ByteCodeFormat::new(
934                "jeqz +AAAA".to_owned(),
935                vec![FormatUnit::Opcode, FormatUnit::IMM16],
936            ),
937        ),
938        // 0x51 	IMM8 	jnez +AA
939        (
940            0x51,
941            ByteCodeFormat::new(
942                "jnez +AA".to_owned(),
943                vec![FormatUnit::Opcode, FormatUnit::IMM8],
944            ),
945        ),
946        // 0x52 	IMM8 	jstricteqz +AA
947        (
948            0x52,
949            ByteCodeFormat::new(
950                "jstricteqz +AA".to_owned(),
951                vec![FormatUnit::Opcode, FormatUnit::IMM8],
952            ),
953        ),
954        // 0x53 	IMM8 	jnstricteqz +AA
955        (
956            0x53,
957            ByteCodeFormat::new(
958                "jnstricteqz +AA".to_owned(),
959                vec![FormatUnit::Opcode, FormatUnit::IMM8],
960            ),
961        ),
962        // 0x54 	IMM8 	jeqnull +AA
963        (
964            0x54,
965            ByteCodeFormat::new(
966                "jeqnull +AA".to_owned(),
967                vec![FormatUnit::Opcode, FormatUnit::IMM8],
968            ),
969        ),
970        // 0x55 	IMM8 	jnenull +AA
971        (
972            0x55,
973            ByteCodeFormat::new(
974                "jnenull +AA".to_owned(),
975                vec![FormatUnit::Opcode, FormatUnit::IMM8],
976            ),
977        ),
978        // 0x56 	IMM8 	jstricteqnull +AA
979        (
980            0x56,
981            ByteCodeFormat::new(
982                "jstricteqnull +AA".to_owned(),
983                vec![FormatUnit::Opcode, FormatUnit::IMM8],
984            ),
985        ),
986        // 0x57 	IMM8 	jnstricteqnull +AA
987        (
988            0x57,
989            ByteCodeFormat::new(
990                "jnstricteqnull +AA".to_owned(),
991                vec![FormatUnit::Opcode, FormatUnit::IMM8],
992            ),
993        ),
994        // 0x58 	IMM8 	jequndefined +AA
995        (
996            0x58,
997            ByteCodeFormat::new(
998                "jequndefined +AA".to_owned(),
999                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1000            ),
1001        ),
1002        // 0x59 	IMM8 	jneundefined +AA
1003        (
1004            0x59,
1005            ByteCodeFormat::new(
1006                "jneundefined +AA".to_owned(),
1007                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1008            ),
1009        ),
1010        // 0x5a 	IMM8 	jstrictequndefined +AA
1011        (
1012            0x5a,
1013            ByteCodeFormat::new(
1014                "jstrictequndefined +AA".to_owned(),
1015                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1016            ),
1017        ),
1018        // 0x5b 	IMM8 	jnstrictequndefined +AA
1019        (
1020            0x5b,
1021            ByteCodeFormat::new(
1022                "jnstrictequndefined +AA".to_owned(),
1023                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1024            ),
1025        ),
1026        // 0x5c 	V8_IMM8 	jeq vAA, +BB
1027        (
1028            0x5c,
1029            ByteCodeFormat::new(
1030                "jeq vAA, +BB".to_owned(),
1031                vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::IMM8],
1032            ),
1033        ),
1034        // 0x5d 	V8_IMM8 	jne vAA, +BB
1035        (
1036            0x5d,
1037            ByteCodeFormat::new(
1038                "jne vAA, +BB".to_owned(),
1039                vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::IMM8],
1040            ),
1041        ),
1042        // 0x5e 	V8_IMM8 	jstricteq vAA, +BB
1043        (
1044            0x5e,
1045            ByteCodeFormat::new(
1046                "jstricteq vAA, +BB".to_owned(),
1047                vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::IMM8],
1048            ),
1049        ),
1050        // 0x5f 	V8_IMM8 	jnstricteq vAA, +BB
1051        (
1052            0x5f,
1053            ByteCodeFormat::new(
1054                "jnstricteq vAA, +BB".to_owned(),
1055                vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::IMM8],
1056            ),
1057        ),
1058        // 0x60 	V8 	lda vAA 	A:寄存器索引 	将寄存器A中的内容存放到acc中。
1059        (
1060            0x60,
1061            ByteCodeFormat::new(
1062                "lda vAA".to_owned(),
1063                vec![FormatUnit::Opcode, FormatUnit::V8],
1064            ),
1065        ),
1066        // 0x61 	V8 	sta vAA
1067        (
1068            0x61,
1069            ByteCodeFormat::new(
1070                "sta vAA".to_owned(),
1071                vec![FormatUnit::Opcode, FormatUnit::V8],
1072            ),
1073        ),
1074        // 0x62 	IMM32 	ldai +AAAAAAAA 	A:常量字面量 	将整型字面量A存放到acc中。
1075        (
1076            0x62,
1077            ByteCodeFormat::new(
1078                "ldai".to_owned(),
1079                vec![FormatUnit::Opcode, FormatUnit::IMM32],
1080            ),
1081        ),
1082        // 0x63 	IMM64 	fldai +AAAAAAAAAAAAAAAA 	A:常量字面量 	将双精度浮点型字面量A存放到acc中。
1083        (
1084            0x63,
1085            ByteCodeFormat::new(
1086                "fldai".to_owned(),
1087                vec![FormatUnit::Opcode, FormatUnit::IMM64],
1088            ),
1089        ),
1090        // 0x64 	NONE 	return 	默认入参:acc:值 	返回acc中的值。
1091        (
1092            0x64,
1093            ByteCodeFormat::new("return".to_owned(), vec![FormatUnit::Opcode]),
1094        ),
1095        // 0x65 	NONE 	returnundefined 		返回undefined。
1096        (
1097            0x65,
1098            ByteCodeFormat::new("returnundefined".to_owned(), vec![FormatUnit::Opcode]),
1099        ),
1100        // 0x66 	NONE 	getpropiterator 	默认入参:acc:对象 	将acc中所存的对象的for-in迭代器存放到acc中。
1101        (
1102            0x66,
1103            ByteCodeFormat::new("getpropiterator".to_owned(), vec![FormatUnit::Opcode]),
1104        ),
1105        // 0x67 	IMM8 	getiterator RR
1106        (
1107            0x67,
1108            ByteCodeFormat::new(
1109                "getiterator".to_owned(),
1110                vec![FormatUnit::Opcode, FormatUnit::RR],
1111            ),
1112        ),
1113        // 0x68 	IMM8_V8 	closeiterator RR, vAA
1114        (
1115            0x68,
1116            ByteCodeFormat::new(
1117                "closeiterator".to_owned(),
1118                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
1119            ),
1120        ),
1121        // 0x69 	NONE 	poplexenv 		跳出当前的词法环境,进入外面一层词法环境。
1122        (
1123            0x69,
1124            ByteCodeFormat::new("poplexenv".to_owned(), vec![FormatUnit::Opcode]),
1125        ),
1126        // 0x6a 	NONE 	ldnan 		将nan存放到acc中。
1127        (
1128            0x6a,
1129            ByteCodeFormat::new("ldnan".to_owned(), vec![FormatUnit::Opcode]),
1130        ),
1131        // 0x6b 	NONE 	ldinfinity 		将infinity存放到acc中。
1132        (
1133            0x6b,
1134            ByteCodeFormat::new("ldinfinity".to_owned(), vec![FormatUnit::Opcode]),
1135        ),
1136        // 0x6c 	NONE 	getunmappedargs 		将当前函数的arguments存放到acc中。
1137        (
1138            0x6c,
1139            ByteCodeFormat::new("getunmappedargs".to_owned(), vec![FormatUnit::Opcode]),
1140        ),
1141        // 0x6d 	NONE 	ldglobal 		将global对象存放到acc中。
1142        (
1143            0x6d,
1144            ByteCodeFormat::new("ldglobal".to_owned(), vec![FormatUnit::Opcode]),
1145        ),
1146        // 0x6e 	NONE 	ldnewtarget
1147        (
1148            0x6e,
1149            ByteCodeFormat::new("ldnewtarget".to_owned(), vec![FormatUnit::Opcode]),
1150        ),
1151        // 0x6f 	NONE 	ldthis 		将this存放到acc中。
1152        (
1153            0x6f,
1154            ByteCodeFormat::new("ldthis".to_owned(), vec![FormatUnit::Opcode]),
1155        ),
1156        // 0x70 	NONE 	ldhole 		将hole存放到acc中。
1157        (
1158            0x70,
1159            ByteCodeFormat::new("ldhole".to_owned(), vec![FormatUnit::Opcode]),
1160        ),
1161        // 0x71 	IMM8_ID16_IMM8 	createregexpwithliteral RR, @AAAA, +BB
1162        (
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        // 0x72 	IMM16_ID16_IMM8 	createregexpwithliteral RRRR, @AAAA, +BB
1175        (
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        // 0x73 	IMM8_IMM8_V8 	callrange RR, +AA, vBB
1188        (
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        // 0x74 	IMM16_ID16_IMM8 	definefunc RRRR, @AAAA, +BB
1201        (
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        // 0x75 	IMM16_ID16_ID16_IMM16_V8 	defineclasswithbuffer RRRR, @AAAA, @BBBB, +CCCC, vDD
1214        (
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        // 0x76 	IMM8 	gettemplateobject RR
1229        (
1230            0x76,
1231            ByteCodeFormat::new(
1232                "gettemplateobject".to_owned(),
1233                vec![FormatUnit::Opcode, FormatUnit::RR],
1234            ),
1235        ),
1236        // 0x77 	IMM8_V8 	setobjectwithproto RR, vAA
1237        (
1238            0x77,
1239            ByteCodeFormat::new(
1240                "setobjectwithproto".to_owned(),
1241                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
1242            ),
1243        ),
1244        // 0x78 	IMM8_V8_V8 	stownbyvalue RR, vAA, vBB
1245        (
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        // 0x79 	IMM8_V8_IMM16 	stownbyindex RR, vAA, +BBBB
1258        (
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        // 0x7a 	IMM8_ID16_V8 	stownbyname RR, @AAAA, vBB
1271        (
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        // 0x7b 	IMM8 	getmodulenamespace +AA 	A:模块索引 	对第A个模块,执行GetModuleNamespace,并将结果存放到acc中。
1284        (
1285            0x7b,
1286            ByteCodeFormat::new(
1287                "getmodulenamespace".to_owned(),
1288                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1289            ),
1290        ),
1291        // 0x7c 	IMM8 	stmodulevar +AA
1292        (
1293            0x7c,
1294            ByteCodeFormat::new(
1295                "stmodulevar".to_owned(),
1296                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1297            ),
1298        ),
1299        // 0x7d 	IMM8 	ldlocalmodulevar +AA 	A:槽位号 	将槽位号为A的局部模块变量存放到acc中。
1300        (
1301            0x7d,
1302            ByteCodeFormat::new(
1303                "ldlocalmodulevar".to_owned(),
1304                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1305            ),
1306        ),
1307        // 0x7e 	IMM8 	ldexternalmodulevar +AA 	A:槽位号 	将槽位号为A的外部模块变量存放到acc中。
1308        (
1309            0x7e,
1310            ByteCodeFormat::new(
1311                "ldexternalmodulevar +AA".to_owned(),
1312                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1313            ),
1314        ),
1315        // 0x7f 	IMM16_ID16 	stglobalvar RRRR, @AAAA
1316        (
1317            0x7f,
1318            ByteCodeFormat::new(
1319                "stglobalvar".to_owned(),
1320                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::StringID],
1321            ),
1322        ),
1323        // 0x80 	IMM16 	createemptyarray RRRR 	R:方舟运行时内部使用的16位保留数字 	创建一个空数组,并将其存放到acc中。
1324        (
1325            0x80,
1326            ByteCodeFormat::new(
1327                "createemptyarray".to_owned(),
1328                vec![FormatUnit::Opcode, FormatUnit::RRRR],
1329            ),
1330        ),
1331        // 0x81 	IMM16_ID16 	createarraywithbuffer RRRR, @AAAA
1332        (
1333            0x81,
1334            ByteCodeFormat::new(
1335                "createarraywithbuffer".to_owned(),
1336                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::LiteralID],
1337            ),
1338        ),
1339        // 0x82 	IMM16_ID16 	createobjectwithbuffer RRRR, @AAAA
1340        (
1341            0x82,
1342            ByteCodeFormat::new(
1343                "createobjectwithbuffer".to_owned(),
1344                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::LiteralID],
1345            ),
1346        ),
1347        // 0x83 	IMM16_IMM8_V8 	newobjrange RRRR, +AA, vBB
1348        (
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        // 0x84 	IMM16 	typeof RRRR
1361        (
1362            0x84,
1363            ByteCodeFormat::new(
1364                "typeof".to_owned(),
1365                vec![FormatUnit::Opcode, FormatUnit::RRRR],
1366            ),
1367        ),
1368        // 0x85 	IMM16_V8 	ldobjbyvalue RRRR, vAA
1369        (
1370            0x85,
1371            ByteCodeFormat::new(
1372                "ldobjbyvalue".to_owned(),
1373                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::V8],
1374            ),
1375        ),
1376        // 0x86 	IMM16_V8_V8 	stobjbyvalue RRRR, vAA, vBB
1377        (
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        // 0x87 	IMM16_V8 	ldsuperbyvalue RRRR, vAA
1390        (
1391            0x87,
1392            ByteCodeFormat::new(
1393                "ldsuperbyvalue".to_owned(),
1394                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::V8],
1395            ),
1396        ),
1397        // 0x88 	IMM16_IMM16 	ldobjbyindex RRRR, +AAAA
1398
1399        // 0x89 	IMM16_V8_IMM16 	stobjbyindex RRRR, vAA, +BBBB
1400        // 0x8a 	IMM8_IMM8 	ldlexvar +AA, +BB
1401        // 0x8b 	IMM8_IMM8 	stlexvar +AA, +BB
1402        // 0x8c 	IMM16_ID16 	tryldglobalbyname RRRR, @AAAA
1403        // 0x8d 	IMM16_ID16 	trystglobalbyname RRRR, @AAAA
1404        // 0x8e 	IMM8_ID16_V8 	stownbynamewithnameset RR, @AAAA, vBB
1405        // 0x8f 	V16_V16 	mov vAAAA, vBBBB 	A, B:寄存器索引 	将寄存器B中的内容复制到寄存器A中。
1406        // 0x90 	IMM16_ID16 	ldobjbyname RRRR, @AAAA
1407        // 0x91 	IMM16_ID16_V8 	stobjbyname RRRR, @AAAA, vBB
1408        // 0x92 	IMM16_ID16 	ldsuperbyname RRRR, @AAAA
1409        // 0x93 	IMM16_ID16 	ldthisbyname RRRR, @AAAA
1410        // 0x94 	IMM16_ID16 	stthisbyname RRRR, @AAAA
1411        // 0x95 	IMM16 	ldthisbyvalue RRRR
1412        // 0x96 	IMM16_V8 	stthisbyvalue RRRR, vAA
1413        // 0x97 	V8 	asyncgeneratorreject vAA
1414        // 0x98 	IMM32 	jmp +AAAAAAAA 	A:有符号的分支偏移量 	无条件跳转到分支A。
1415        // 0x99 	IMM8_V8_V8 	stownbyvaluewithnameset RR, vAA, vBB
1416        // 0x9a 	IMM32 	jeqz +AAAAAAAA
1417        // 0x9b 	IMM16 	jnez +AAAA
1418        // 0x9c 	IMM32 	jnez +AAAAAAAA
1419        // 0x9d 	IMM16 	jstricteqz +AAAA
1420        // 0x9e 	IMM16 	jnstricteqz +AAAA
1421        // 0x9f 	IMM16 	jeqnull +AAAA
1422        // 0xa0 	IMM16 	jnenull +AAAA
1423        // 0xa1 	IMM16 	jstricteqnull +AAAA
1424        // 0xa2 	IMM16 	jnstricteqnull +AAAA
1425        // 0xa3 	IMM16 	jequndefined +AAAA
1426        // 0xa4 	IMM16 	jneundefined +AAAA
1427        // 0xa5 	IMM16 	jstrictequndefined +AAAA
1428        // 0xa6 	IMM16 	jnstrictequndefined +AAAA
1429        // 0xa7 	V8_IMM16 	jeq vAA, +BBBB
1430        // 0xa8 	V8_IMM16 	jne vAA, +BBBB
1431        // 0xa9 	V8_IMM16 	jstricteq vAA, +BBBB
1432        // 0xaa 	V8_IMM16 	jnstricteq vAA, +BBBB
1433        // 0xab 	IMM16 	getiterator RRRR
1434        // 0xac 	IMM16_V8 	closeiterator RRRR, vAA
1435        // 0xad 	NONE 	ldsymbol 		加载Symbol对象到acc中。
1436        (
1437            0xad,
1438            ByteCodeFormat::new("ldsymbol".to_owned(), vec![FormatUnit::Opcode]),
1439        ),
1440        // 0xae 	NONE 	asyncfunctionenter 		创建一个异步函数对象,并将这个对象存放到acc中。
1441        (
1442            0xae,
1443            ByteCodeFormat::new("asyncfunctionenter".to_owned(), vec![FormatUnit::Opcode]),
1444        ),
1445        // 0xaf 	NONE 	ldfunction 		将当前的函数对象加载到acc中。
1446        (
1447            0xaf,
1448            ByteCodeFormat::new("ldfunction".to_owned(), vec![FormatUnit::Opcode]),
1449        ),
1450        // 0xb0 	NONE 	debugger 		调试时用于暂停执行。
1451        (
1452            0xb0,
1453            ByteCodeFormat::new("debugger".to_owned(), vec![FormatUnit::Opcode]),
1454        ),
1455        // 0xb1 	V8 	creategeneratorobj vAA
1456        (
1457            0xb1,
1458            ByteCodeFormat::new(
1459                "creategeneratorobj vAA".to_owned(),
1460                vec![FormatUnit::Opcode, FormatUnit::V8],
1461            ),
1462        ),
1463        // 0xb2 	V8_V8 	createiterresultobj vAA, vBB
1464        (
1465            0xb2,
1466            ByteCodeFormat::new(
1467                "createiterresultobj vAA, vBB".to_owned(),
1468                vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::V8],
1469            ),
1470        ),
1471        // 0xb3 	IMM8_V8_V8 	createobjectwithexcludedkeys +AA, vBB, vCC
1472        (
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        // 0xb4 	IMM8_V8 	newobjapply RR, vAA
1485        (
1486            0xb4,
1487            ByteCodeFormat::new(
1488                "newobjapply RR, vAA".to_owned(),
1489                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
1490            ),
1491        ),
1492        // 0xb5 	IMM16_V8 	newobjapply RRRR, vAA
1493        (
1494            0xb5,
1495            ByteCodeFormat::new(
1496                "newobjapply RRRR, vAA".to_owned(),
1497                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::V8],
1498            ),
1499        ),
1500        // 0xb6 	IMM8_ID16 	newlexenvwithname +AA, @BBBB
1501        (
1502            0xb6,
1503            ByteCodeFormat::new(
1504                "newlexenvwithname".to_owned(),
1505                vec![FormatUnit::Opcode, FormatUnit::IMM8, FormatUnit::LiteralID],
1506            ),
1507        ),
1508        // 0xb7 	V8 	createasyncgeneratorobj vAA
1509        (
1510            0xb7,
1511            ByteCodeFormat::new(
1512                "createasyncgeneratorobj vAA".to_owned(),
1513                vec![FormatUnit::Opcode, FormatUnit::V8],
1514            ),
1515        ),
1516        // 0xb8 	V8_V8_V8 	asyncgeneratorresolve vAA, vBB, vCC
1517        (
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        // 0xb9 	IMM8_V8 	supercallspread RR, vAA
1530        (
1531            0xb9,
1532            ByteCodeFormat::new(
1533                "supercallspread RR, vAA".to_owned(),
1534                vec![FormatUnit::Opcode, FormatUnit::RR, FormatUnit::V8],
1535            ),
1536        ),
1537        // 0xba 	IMM8_V8_V8 	applyspread RR, vAA, vBB
1538        (
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        // 0xba 	IMM8_V8_V8 	apply RR, vAA, vBB
1551        (
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        // 0xbb 	IMM8_IMM8_V8 	supercallarrowrange RR, +AA, vBB
1564        (
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        // 0xbc 	V8_V8_V8_V8 	definegettersetterbyvalue vAA, vBB, vCC, vDD
1577        (
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        // 0xbd 	NONE 	dynamicimport 	默认入参:acc:值 	使用acc中的值作为参数,执行ImportCalls,并把结果存放到acc中。
1591        (
1592            0xbd,
1593            ByteCodeFormat::new("dynamicimport".to_owned(), vec![FormatUnit::Opcode]),
1594        ),
1595        // 0xbe 	IMM16_ID16_IMM8 	definemethod RRRR, @AAAA, +BB
1596        (
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        // 0xbf 	NONE 	resumegenerator
1609        (
1610            0xbf,
1611            ByteCodeFormat::new("resumegenerator".to_owned(), vec![FormatUnit::Opcode]),
1612        ),
1613        // 0xc0 	NONE 	getresumemode
1614        (
1615            0xc0,
1616            ByteCodeFormat::new("getresumemode".to_owned(), vec![FormatUnit::Opcode]),
1617        ),
1618        // 0xc1 	IMM16 	gettemplateobject RRRR
1619        (
1620            0xc1,
1621            ByteCodeFormat::new(
1622                "gettemplateobject RRRR".to_owned(),
1623                vec![FormatUnit::Opcode, FormatUnit::RRRR],
1624            ),
1625        ),
1626        // 0xc2 	V8 	delobjprop vAA
1627        (
1628            0xc2,
1629            ByteCodeFormat::new(
1630                "delobjprop vAA".to_owned(),
1631                vec![FormatUnit::Opcode, FormatUnit::V8],
1632            ),
1633        ),
1634        // 0xc3 	V8 	suspendgenerator vAA
1635        (
1636            0xc3,
1637            ByteCodeFormat::new(
1638                "suspendgenerator vAA".to_owned(),
1639                vec![FormatUnit::Opcode, FormatUnit::V8],
1640            ),
1641        ),
1642        // 0xc4 	V8 	asyncfunctionawaituncaught vAA
1643        (
1644            0xc4,
1645            ByteCodeFormat::new(
1646                "asyncfunctionawaituncaught vAA".to_owned(),
1647                vec![FormatUnit::Opcode, FormatUnit::V8],
1648            ),
1649        ),
1650        // 0xc5 	V8 	copydataproperties vAA
1651        (
1652            0xc5,
1653            ByteCodeFormat::new(
1654                "copydataproperties vAA".to_owned(),
1655                vec![FormatUnit::Opcode, FormatUnit::V8],
1656            ),
1657        ),
1658        // 0xc6 	V8_V8 	starrayspread vAA, vBB
1659        (
1660            0xc6,
1661            ByteCodeFormat::new(
1662                "starrayspread vAA, vBB".to_owned(),
1663                vec![FormatUnit::Opcode, FormatUnit::V8, FormatUnit::V8],
1664            ),
1665        ),
1666        // 0xc7 	IMM16_V8 	setobjectwithproto RRRR, vAA
1667        (
1668            0xc7,
1669            ByteCodeFormat::new(
1670                "setobjectwithproto RRRR, vAA".to_owned(),
1671                vec![FormatUnit::Opcode, FormatUnit::RRRR, FormatUnit::V8],
1672            ),
1673        ),
1674        // 0xc8 	IMM16_V8_V8 	stownbyvalue RRRR, vAA, vBB
1675        (
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        // 0xc9 	IMM8_V8_V8 	stsuperbyvalue RR, vAA, vBB
1688        (
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        // 0xca 	IMM16_V8_V8 	stsuperbyvalue RRRR, vAA, vBB
1701        (
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        // 0xcb 	IMM16_V8_IMM16 	stownbyindex RRRR, vAA, +BBBB
1714        (
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        // 0xcc 	IMM16_ID16_V8 	stownbyname RRRR, @AAAA, vBB
1727        (
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        // 0xcd 	V8 	asyncfunctionresolve vAA
1740        (
1741            0xcd,
1742            ByteCodeFormat::new("asyncfunctionresolve".to_owned(), vec![FormatUnit::Opcode]),
1743        ),
1744        // 0xce 	V8 	asyncfunctionreject vAA
1745        (
1746            0xce,
1747            ByteCodeFormat::new("asyncfunctionreject".to_owned(), vec![FormatUnit::Opcode]),
1748        ),
1749        // 0xcf 	IMM8 	copyrestargs +AA 	A:形参列表中剩余参数所在的位次 	复制剩余参数,并将复制出的参数数组副本存放到acc中。
1750        (
1751            0xcf,
1752            ByteCodeFormat::new(
1753                "copyrestargs".to_owned(),
1754                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1755            ),
1756        ),
1757        // 0xd0 	IMM8_ID16_V8 	stsuperbyname RR, @AAAA, vBB
1758        (
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        // 0xd1 	IMM16_ID16_V8 	stsuperbyname RRRR, @AAAA, vBB
1771        (
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        // 0xd2 	IMM16_V8_V8 	stownbyvaluewithnameset RRRR, vAA, vBB
1784        (
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        // 0xd3 	ID16 	ldbigint @AAAA 	A:string id 	基于索引A对应的字符串,创建BigInt类型的值,并将其存放到acc中。
1797        (
1798            0xd3,
1799            ByteCodeFormat::new(
1800                "ldbigint".to_owned(),
1801                vec![FormatUnit::Opcode, FormatUnit::StringID],
1802            ),
1803        ),
1804        // 0xd4 	IMM16_ID16_V8 	stownbynamewithnameset RRRR, @AAAA, vBB
1805        (
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        // 0xd5 	NONE 	nop 		无操作。
1818        (
1819            0xd5,
1820            ByteCodeFormat::new("nop".to_owned(), vec![FormatUnit::Opcode]),
1821        ),
1822        // 0xd6 	IMM8 	setgeneratorstate +AA
1823        (
1824            0xd6,
1825            ByteCodeFormat::new(
1826                "setgeneratorstate".to_owned(),
1827                vec![FormatUnit::Opcode, FormatUnit::IMM8],
1828            ),
1829        ),
1830        // 0xd7 	IMM8 	getasynciterator RR
1831        (
1832            0xd7,
1833            ByteCodeFormat::new(
1834                "getasynciterator".to_owned(),
1835                vec![FormatUnit::Opcode, FormatUnit::RR],
1836            ),
1837        ),
1838        // 0xd8 	IMM8_IMM16_IMM16 	ldprivateproperty RR, +AAAA, +BBBB
1839        (
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        // 0xd9 	IMM8_IMM16_IMM16_V8 	stprivateproperty RR, +AAAA, +BBBB, vCC
1852        (
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        // 0xda 	IMM8_IMM16_IMM16 	testin RR, +AAAA, +BBBB
1866        (
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        // 0xdb 	IMM8_ID16_V8 	definefieldbyname RR, @AAAA, vBB
1879        (
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        // 0xfb 	PREF_NONE 	callruntime.notifyconcurrentresult 	默认入参:acc:并发函数的返回值
1892        (
1893            0xfb,
1894            ByteCodeFormat::new(
1895                "callruntime.notifyconcurrentresult".to_owned(),
1896                vec![FormatUnit::PrefixOpcode],
1897            ),
1898        ),
1899        // 0xfd 	PREF_IMM16_V8_V8 	wide.createobjectwithexcludedkeys +AAAA, vBB, vCC
1900        (
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        // 0xfe 	PREF_NONE 	throw 	默认入参:acc:异常 	抛出acc中存放的异
1913        (
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        // 0x04fe 	PREF_V8 	throw.constassignment vAA 	A:常量变量的名称 	抛出异常:对常量变量进行赋值。
2014        (
2015            0x04fe,
2016            ByteCodeFormat::new(
2017                "throw.constassignment".to_owned(),
2018                vec![FormatUnit::PrefixOpcode, FormatUnit::V8],
2019            ),
2020        ),
2021        // 0x05fb 	PREF_IMM8_IMM_16_IMM_16_V8 	callruntime.defineprivateproperty RR, +AAAA, +BBBB, vCC
2022        (
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        // 0x05fd 	PREF_IMM16_V8 	wide.callthisrange +AAAA, vBB
2036        (
2037            0x05fd,
2038            ByteCodeFormat::new(
2039                "wide.callthisrange".to_owned(),
2040                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2041            ),
2042        ),
2043        // 0x05fb 	PREF_IMM8_IMM_16_IMM_16_V8 	callruntime.defineprivateproperty RR, +AAAA, +BBBB, vCC
2044        (
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        // 0x05fd 	PREF_IMM16_V8 	wide.callthisrange +AAAA, vBB
2058        (
2059            0x05fd,
2060            ByteCodeFormat::new(
2061                "wide.callthisrange".to_owned(),
2062                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2063            ),
2064        ),
2065        // 0x05fe 	PREF_V8 	throw.ifnotobject vAA 	A:对象 	如果A不是一个对象,抛出异常。
2066        (
2067            0x05fe,
2068            ByteCodeFormat::new(
2069                "throw.ifnotobject".to_owned(),
2070                vec![FormatUnit::PrefixOpcode, FormatUnit::V8],
2071            ),
2072        ),
2073        // 0x06fb 	PREF_IMM8_V8 	callruntime.callinit +RR, vAA
2074        (
2075            0x06fb,
2076            ByteCodeFormat::new(
2077                "callruntime.callinit".to_owned(),
2078                vec![FormatUnit::PrefixOpcode, FormatUnit::RR, FormatUnit::V8],
2079            ),
2080        ),
2081        // 0x06fd 	PREF_IMM16_V8 	wide.supercallthisrange +AAAA, vBB
2082        (
2083            0x06fd,
2084            ByteCodeFormat::new(
2085                "wide.supercallthisrange".to_owned(),
2086                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2087            ),
2088        ),
2089        // 0x06fd 	PREF_IMM16_V8 	wide.supercallthisrange +AAAA, vBB
2090        (
2091            0x06fe,
2092            ByteCodeFormat::new(
2093                "throw.undefinedifhole".to_owned(),
2094                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2095            ),
2096        ),
2097        // 0x06fe 	PREF_V8_V8 	throw.undefinedifhole vAA, vBB
2098        (
2099            0x06fe,
2100            ByteCodeFormat::new(
2101                "throw.undefinedifhole".to_owned(),
2102                vec![FormatUnit::PrefixOpcode, FormatUnit::V8, FormatUnit::V8],
2103            ),
2104        ),
2105        // 0x07fb 	PREF_IMM16_ID16_ID16_IMM16_V8 	callruntime.definesendableclass RRRR, @AAAA, @BBBB, +CCCC, vDD
2106        (
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        // 0x07fd 	PREF_IMM16_V8 	wide.supercallarrowrange +AAAA, vBB
2121        (
2122            0x07fd,
2123            ByteCodeFormat::new(
2124                "wide.supercallarrowrange".to_owned(),
2125                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16, FormatUnit::V8],
2126            ),
2127        ),
2128        // 0x07fe 	PREF_IMM8 	throw.ifsupernotcorrectcall +AA
2129        (
2130            0x07fe,
2131            ByteCodeFormat::new(
2132                "throw.ifsupernotcorrectcall".to_owned(),
2133                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM8],
2134            ),
2135        ),
2136        // 0x08fb 	PREF_IMM16 	callruntime.ldsendableclass +AAAA
2137        (
2138            0x08fb,
2139            ByteCodeFormat::new(
2140                "callruntime.ldsendableclass".to_owned(),
2141                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2142            ),
2143        ),
2144        // 0x08fd 	PREF_IMM32 	wide.ldobjbyindex +AAAAAAAA
2145        (
2146            0x08fd,
2147            ByteCodeFormat::new(
2148                "wide.ldobjbyindex".to_owned(),
2149                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM32],
2150            ),
2151        ),
2152        // 0x08fe 	PREF_IMM16 	throw.ifsupernotcorrectcall +AAAA
2153        (
2154            0x08fe,
2155            ByteCodeFormat::new(
2156                "throw.ifsupernotcorrectcall".to_owned(),
2157                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2158            ),
2159        ),
2160        // 0x09fd 	PREF_V8_IMM32 	wide.stobjbyindex vAA, +BBBBBBBB
2161        (
2162            0x09fd,
2163            ByteCodeFormat::new(
2164                "wide.stobjbyindex".to_owned(),
2165                vec![FormatUnit::PrefixOpcode, FormatUnit::V8, FormatUnit::IMM32],
2166            ),
2167        ),
2168        // 0x09fe 	PREF_ID16 	throw.undefinedifholewithname @AAAA
2169        (
2170            0x09fe,
2171            ByteCodeFormat::new(
2172                "throw.undefinedifholewithname".to_owned(),
2173                vec![FormatUnit::PrefixOpcode, FormatUnit::StringID],
2174            ),
2175        ),
2176        // 0x0afd 	PREF_V8_IMM32 	wide.stownbyindex vAA, +BBBBBBBB
2177        (
2178            0x0afd,
2179            ByteCodeFormat::new(
2180                "wide.stownbyindex vAA, +BBBBBBBB".to_owned(),
2181                vec![FormatUnit::PrefixOpcode, FormatUnit::V8, FormatUnit::IMM32],
2182            ),
2183        ),
2184        // 0x0bfd 	PREF_IMM16 	wide.copyrestargs +AAAA
2185        (
2186            0x0bfd,
2187            ByteCodeFormat::new(
2188                "wide.copyrestargs +AAAA".to_owned(),
2189                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2190            ),
2191        ),
2192        // 0x0cfd 	PREF_IMM16_IMM16 	wide.ldlexvar +AAAA, +BBBB
2193        (
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        // 0x0dfd 	PREF_IMM16_IMM16 	wide.stlexvar +AAAA, +BBBB
2205        (
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        // 0x0efd 	PREF_IMM16 	wide.getmodulenamespace +AAAA
2217        (
2218            0x0efd,
2219            ByteCodeFormat::new(
2220                "wide.getmodulenamespace +AAAA".to_owned(),
2221                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2222            ),
2223        ),
2224        // 0x0ffd 	PREF_IMM16 	wide.stmodulevar +AAAA
2225        (
2226            0x0ffd,
2227            ByteCodeFormat::new(
2228                "wide.stmodulevar +AAAA".to_owned(),
2229                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2230            ),
2231        ),
2232        // 0x10fd 	PREF_IMM16 	wide.ldlocalmodulevar +AAAA
2233        (
2234            0x10fd,
2235            ByteCodeFormat::new(
2236                "wide.ldlocalmodulevar +AAAA".to_owned(),
2237                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2238            ),
2239        ),
2240        // 0x11fd 	PREF_IMM16 	wide.ldexternalmodulevar +AAAA
2241        (
2242            0x11fd,
2243            ByteCodeFormat::new(
2244                "wide.ldexternalmodulevar +AAAA".to_owned(),
2245                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2246            ),
2247        ),
2248        // 0x12fd 	PREF_IMM16 	wide.ldpatchvar +AAAA
2249        (
2250            0x12fd,
2251            ByteCodeFormat::new(
2252                "wide.ldpatchvar +AAAA".to_owned(),
2253                vec![FormatUnit::PrefixOpcode, FormatUnit::IMM16],
2254            ),
2255        ),
2256        // 0x13fd 	PREF_IMM16 	wide.stpatchvar +AAAA
2257        (
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            // 剩余最后一个
2321            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}