Skip to main content

luaur_bytecode/methods/
bytecode_builder_dump_instruction.rs

1use crate::records::bytecode_builder::BytecodeBuilder;
2use alloc::string::String;
3use core::ffi::c_int;
4use luaur_common::enums::luau_opcode::LuauOpcode;
5use luaur_common::functions::format_append::formatAppend;
6use luaur_common::macros::luau_assert::LUAU_ASSERT;
7use luaur_common::macros::luau_insn_a::LUAU_INSN_A;
8use luaur_common::macros::luau_insn_aux_kv_16::LUAU_INSN_AUX_KV16;
9use luaur_common::macros::luau_insn_b::LUAU_INSN_B;
10use luaur_common::macros::luau_insn_c::LUAU_INSN_C;
11use luaur_common::macros::luau_insn_d::LUAU_INSN_D;
12use luaur_common::macros::luau_insn_op::LUAU_INSN_OP;
13
14impl BytecodeBuilder {
15    pub fn dump_instruction(&self, code: &[u32], result: &mut String, target_label: i32) -> usize {
16        let insn = code[0];
17        let op = LUAU_INSN_OP(insn);
18        let op_enum = unsafe { core::mem::transmute::<u8, LuauOpcode>(op as u8) };
19
20        match op_enum {
21            LuauOpcode::LOP_LOADNIL => {
22                formatAppend(result, format_args!("LOADNIL R{}\n", LUAU_INSN_A(insn)));
23                1
24            }
25            LuauOpcode::LOP_LOADB => {
26                if LUAU_INSN_C(insn) != 0 {
27                    formatAppend(
28                        result,
29                        format_args!(
30                            "LOADB R{} {} +{}\n",
31                            LUAU_INSN_A(insn),
32                            LUAU_INSN_B(insn),
33                            LUAU_INSN_C(insn)
34                        ),
35                    );
36                } else {
37                    formatAppend(
38                        result,
39                        format_args!("LOADB R{} {}\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
40                    );
41                }
42                1
43            }
44            LuauOpcode::LOP_LOADN => {
45                formatAppend(
46                    result,
47                    format_args!("LOADN R{} {}\n", LUAU_INSN_A(insn), LUAU_INSN_D(insn)),
48                );
49                1
50            }
51            LuauOpcode::LOP_LOADK => {
52                formatAppend(
53                    result,
54                    format_args!("LOADK R{} K{} [", LUAU_INSN_A(insn), LUAU_INSN_D(insn)),
55                );
56                self.dump_constant(result, LUAU_INSN_D(insn), false);
57                result.push_str("]\n");
58                1
59            }
60            LuauOpcode::LOP_MOVE => {
61                formatAppend(
62                    result,
63                    format_args!("MOVE R{} R{}\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
64                );
65                1
66            }
67            LuauOpcode::LOP_GETGLOBAL => {
68                formatAppend(
69                    result,
70                    format_args!("GETGLOBAL R{} K{} [", LUAU_INSN_A(insn), code[1]),
71                );
72                self.dump_constant(result, code[1] as i32, false);
73                result.push_str("]\n");
74                2
75            }
76            LuauOpcode::LOP_SETGLOBAL => {
77                formatAppend(
78                    result,
79                    format_args!("SETGLOBAL R{} K{} [", LUAU_INSN_A(insn), code[1]),
80                );
81                self.dump_constant(result, code[1] as i32, false);
82                result.push_str("]\n");
83                2
84            }
85            LuauOpcode::LOP_GETUPVAL => {
86                formatAppend(
87                    result,
88                    format_args!("GETUPVAL R{} {}\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
89                );
90                1
91            }
92            LuauOpcode::LOP_SETUPVAL => {
93                formatAppend(
94                    result,
95                    format_args!("SETUPVAL R{} {}\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
96                );
97                1
98            }
99            LuauOpcode::LOP_CLOSEUPVALS => {
100                formatAppend(result, format_args!("CLOSEUPVALS R{}\n", LUAU_INSN_A(insn)));
101                1
102            }
103            LuauOpcode::LOP_GETIMPORT => {
104                formatAppend(
105                    result,
106                    format_args!("GETIMPORT R{} {} [", LUAU_INSN_A(insn), LUAU_INSN_D(insn)),
107                );
108                self.dump_constant(result, LUAU_INSN_D(insn), false);
109                result.push_str("]\n");
110                2
111            }
112            LuauOpcode::LOP_GETTABLE => {
113                formatAppend(
114                    result,
115                    format_args!(
116                        "GETTABLE R{} R{} R{}\n",
117                        LUAU_INSN_A(insn),
118                        LUAU_INSN_B(insn),
119                        LUAU_INSN_C(insn)
120                    ),
121                );
122                1
123            }
124            LuauOpcode::LOP_SETTABLE => {
125                formatAppend(
126                    result,
127                    format_args!(
128                        "SETTABLE R{} R{} R{}\n",
129                        LUAU_INSN_A(insn),
130                        LUAU_INSN_B(insn),
131                        LUAU_INSN_C(insn)
132                    ),
133                );
134                1
135            }
136            LuauOpcode::LOP_GETTABLEKS => {
137                formatAppend(
138                    result,
139                    format_args!(
140                        "GETTABLEKS R{} R{} K{} [",
141                        LUAU_INSN_A(insn),
142                        LUAU_INSN_B(insn),
143                        code[1]
144                    ),
145                );
146                self.dump_constant(result, code[1] as i32, false);
147                result.push_str("]\n");
148                2
149            }
150            LuauOpcode::LOP_SETTABLEKS => {
151                formatAppend(
152                    result,
153                    format_args!(
154                        "SETTABLEKS R{} R{} K{} [",
155                        LUAU_INSN_A(insn),
156                        LUAU_INSN_B(insn),
157                        code[1]
158                    ),
159                );
160                self.dump_constant(result, code[1] as i32, false);
161                result.push_str("]\n");
162                2
163            }
164            LuauOpcode::LOP_GETTABLEN => {
165                formatAppend(
166                    result,
167                    format_args!(
168                        "GETTABLEN R{} R{} {}\n",
169                        LUAU_INSN_A(insn),
170                        LUAU_INSN_B(insn),
171                        LUAU_INSN_C(insn) + 1
172                    ),
173                );
174                1
175            }
176            LuauOpcode::LOP_SETTABLEN => {
177                formatAppend(
178                    result,
179                    format_args!(
180                        "SETTABLEN R{} R{} {}\n",
181                        LUAU_INSN_A(insn),
182                        LUAU_INSN_B(insn),
183                        LUAU_INSN_C(insn) + 1
184                    ),
185                );
186                1
187            }
188            LuauOpcode::LOP_NEWCLOSURE => {
189                formatAppend(
190                    result,
191                    format_args!("NEWCLOSURE R{} P{}\n", LUAU_INSN_A(insn), LUAU_INSN_D(insn)),
192                );
193                1
194            }
195            LuauOpcode::LOP_NAMECALL => {
196                formatAppend(
197                    result,
198                    format_args!(
199                        "NAMECALL R{} R{} K{} [",
200                        LUAU_INSN_A(insn),
201                        LUAU_INSN_B(insn),
202                        code[1]
203                    ),
204                );
205                self.dump_constant(result, code[1] as i32, false);
206                result.push_str("]\n");
207                2
208            }
209            LuauOpcode::LOP_CALL => {
210                formatAppend(
211                    result,
212                    format_args!(
213                        "CALL R{} {} {}\n",
214                        LUAU_INSN_A(insn),
215                        LUAU_INSN_B(insn) as i32 - 1,
216                        LUAU_INSN_C(insn) as i32 - 1
217                    ),
218                );
219                1
220            }
221            LuauOpcode::LOP_CALLFB => {
222                formatAppend(
223                    result,
224                    format_args!(
225                        "CALLFB R{} {} {} [{}]\n",
226                        LUAU_INSN_A(insn),
227                        LUAU_INSN_B(insn) as i32 - 1,
228                        LUAU_INSN_C(insn) as i32 - 1,
229                        code[1] as c_int
230                    ),
231                );
232                2
233            }
234            LuauOpcode::LOP_RETURN => {
235                formatAppend(
236                    result,
237                    format_args!(
238                        "RETURN R{} {}\n",
239                        LUAU_INSN_A(insn),
240                        LUAU_INSN_B(insn) as i32 - 1
241                    ),
242                );
243                1
244            }
245            LuauOpcode::LOP_JUMP => {
246                formatAppend(result, format_args!("JUMP L{}\n", target_label));
247                1
248            }
249            LuauOpcode::LOP_JUMPIF => {
250                formatAppend(
251                    result,
252                    format_args!("JUMPIF R{} L{}\n", LUAU_INSN_A(insn), target_label),
253                );
254                1
255            }
256            LuauOpcode::LOP_JUMPIFNOT => {
257                formatAppend(
258                    result,
259                    format_args!("JUMPIFNOT R{} L{}\n", LUAU_INSN_A(insn), target_label),
260                );
261                1
262            }
263            LuauOpcode::LOP_JUMPIFEQ => {
264                formatAppend(
265                    result,
266                    format_args!(
267                        "JUMPIFEQ R{} R{} L{}\n",
268                        LUAU_INSN_A(insn),
269                        code[1],
270                        target_label
271                    ),
272                );
273                2
274            }
275            LuauOpcode::LOP_JUMPIFLE => {
276                formatAppend(
277                    result,
278                    format_args!(
279                        "JUMPIFLE R{} R{} L{}\n",
280                        LUAU_INSN_A(insn),
281                        code[1],
282                        target_label
283                    ),
284                );
285                2
286            }
287            LuauOpcode::LOP_JUMPIFLT => {
288                formatAppend(
289                    result,
290                    format_args!(
291                        "JUMPIFLT R{} R{} L{}\n",
292                        LUAU_INSN_A(insn),
293                        code[1],
294                        target_label
295                    ),
296                );
297                2
298            }
299            LuauOpcode::LOP_JUMPIFNOTEQ => {
300                formatAppend(
301                    result,
302                    format_args!(
303                        "JUMPIFNOTEQ R{} R{} L{}\n",
304                        LUAU_INSN_A(insn),
305                        code[1],
306                        target_label
307                    ),
308                );
309                2
310            }
311            LuauOpcode::LOP_JUMPIFNOTLE => {
312                formatAppend(
313                    result,
314                    format_args!(
315                        "JUMPIFNOTLE R{} R{} L{}\n",
316                        LUAU_INSN_A(insn),
317                        code[1],
318                        target_label
319                    ),
320                );
321                2
322            }
323            LuauOpcode::LOP_JUMPIFNOTLT => {
324                formatAppend(
325                    result,
326                    format_args!(
327                        "JUMPIFNOTLT R{} R{} L{}\n",
328                        LUAU_INSN_A(insn),
329                        code[1],
330                        target_label
331                    ),
332                );
333                2
334            }
335            LuauOpcode::LOP_ADD => {
336                formatAppend(
337                    result,
338                    format_args!(
339                        "ADD R{} R{} R{}\n",
340                        LUAU_INSN_A(insn),
341                        LUAU_INSN_B(insn),
342                        LUAU_INSN_C(insn)
343                    ),
344                );
345                1
346            }
347            LuauOpcode::LOP_SUB => {
348                formatAppend(
349                    result,
350                    format_args!(
351                        "SUB R{} R{} R{}\n",
352                        LUAU_INSN_A(insn),
353                        LUAU_INSN_B(insn),
354                        LUAU_INSN_C(insn)
355                    ),
356                );
357                1
358            }
359            LuauOpcode::LOP_MUL => {
360                formatAppend(
361                    result,
362                    format_args!(
363                        "MUL R{} R{} R{}\n",
364                        LUAU_INSN_A(insn),
365                        LUAU_INSN_B(insn),
366                        LUAU_INSN_C(insn)
367                    ),
368                );
369                1
370            }
371            LuauOpcode::LOP_DIV => {
372                formatAppend(
373                    result,
374                    format_args!(
375                        "DIV R{} R{} R{}\n",
376                        LUAU_INSN_A(insn),
377                        LUAU_INSN_B(insn),
378                        LUAU_INSN_C(insn)
379                    ),
380                );
381                1
382            }
383            LuauOpcode::LOP_IDIV => {
384                formatAppend(
385                    result,
386                    format_args!(
387                        "IDIV R{} R{} R{}\n",
388                        LUAU_INSN_A(insn),
389                        LUAU_INSN_B(insn),
390                        LUAU_INSN_C(insn)
391                    ),
392                );
393                1
394            }
395            LuauOpcode::LOP_MOD => {
396                formatAppend(
397                    result,
398                    format_args!(
399                        "MOD R{} R{} R{}\n",
400                        LUAU_INSN_A(insn),
401                        LUAU_INSN_B(insn),
402                        LUAU_INSN_C(insn)
403                    ),
404                );
405                1
406            }
407            LuauOpcode::LOP_POW => {
408                formatAppend(
409                    result,
410                    format_args!(
411                        "POW R{} R{} R{}\n",
412                        LUAU_INSN_A(insn),
413                        LUAU_INSN_B(insn),
414                        LUAU_INSN_C(insn)
415                    ),
416                );
417                1
418            }
419            LuauOpcode::LOP_ADDK => {
420                formatAppend(
421                    result,
422                    format_args!(
423                        "ADDK R{} R{} K{} [",
424                        LUAU_INSN_A(insn),
425                        LUAU_INSN_B(insn),
426                        LUAU_INSN_C(insn)
427                    ),
428                );
429                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
430                result.push_str("]\n");
431                1
432            }
433            LuauOpcode::LOP_SUBK => {
434                formatAppend(
435                    result,
436                    format_args!(
437                        "SUBK R{} R{} K{} [",
438                        LUAU_INSN_A(insn),
439                        LUAU_INSN_B(insn),
440                        LUAU_INSN_C(insn)
441                    ),
442                );
443                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
444                result.push_str("]\n");
445                1
446            }
447            LuauOpcode::LOP_MULK => {
448                formatAppend(
449                    result,
450                    format_args!(
451                        "MULK R{} R{} K{} [",
452                        LUAU_INSN_A(insn),
453                        LUAU_INSN_B(insn),
454                        LUAU_INSN_C(insn)
455                    ),
456                );
457                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
458                result.push_str("]\n");
459                1
460            }
461            LuauOpcode::LOP_DIVK => {
462                formatAppend(
463                    result,
464                    format_args!(
465                        "DIVK R{} R{} K{} [",
466                        LUAU_INSN_A(insn),
467                        LUAU_INSN_B(insn),
468                        LUAU_INSN_C(insn)
469                    ),
470                );
471                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
472                result.push_str("]\n");
473                1
474            }
475            LuauOpcode::LOP_IDIVK => {
476                formatAppend(
477                    result,
478                    format_args!(
479                        "IDIVK R{} R{} K{} [",
480                        LUAU_INSN_A(insn),
481                        LUAU_INSN_B(insn),
482                        LUAU_INSN_C(insn)
483                    ),
484                );
485                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
486                result.push_str("]\n");
487                1
488            }
489            LuauOpcode::LOP_MODK => {
490                formatAppend(
491                    result,
492                    format_args!(
493                        "MODK R{} R{} K{} [",
494                        LUAU_INSN_A(insn),
495                        LUAU_INSN_B(insn),
496                        LUAU_INSN_C(insn)
497                    ),
498                );
499                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
500                result.push_str("]\n");
501                1
502            }
503            LuauOpcode::LOP_POWK => {
504                formatAppend(
505                    result,
506                    format_args!(
507                        "POWK R{} R{} K{} [",
508                        LUAU_INSN_A(insn),
509                        LUAU_INSN_B(insn),
510                        LUAU_INSN_C(insn)
511                    ),
512                );
513                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
514                result.push_str("]\n");
515                1
516            }
517            LuauOpcode::LOP_SUBRK => {
518                formatAppend(
519                    result,
520                    format_args!("SUBRK R{} K{} [", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
521                );
522                self.dump_constant(result, LUAU_INSN_B(insn) as i32, false);
523                formatAppend(result, format_args!("] R{}\n", LUAU_INSN_C(insn)));
524                1
525            }
526            LuauOpcode::LOP_DIVRK => {
527                formatAppend(
528                    result,
529                    format_args!("DIVRK R{} K{} [", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
530                );
531                self.dump_constant(result, LUAU_INSN_B(insn) as i32, false);
532                formatAppend(result, format_args!("] R{}\n", LUAU_INSN_C(insn)));
533                1
534            }
535            LuauOpcode::LOP_AND => {
536                formatAppend(
537                    result,
538                    format_args!(
539                        "AND R{} R{} R{}\n",
540                        LUAU_INSN_A(insn),
541                        LUAU_INSN_B(insn),
542                        LUAU_INSN_C(insn)
543                    ),
544                );
545                1
546            }
547            LuauOpcode::LOP_OR => {
548                formatAppend(
549                    result,
550                    format_args!(
551                        "OR R{} R{} R{}\n",
552                        LUAU_INSN_A(insn),
553                        LUAU_INSN_B(insn),
554                        LUAU_INSN_C(insn)
555                    ),
556                );
557                1
558            }
559            LuauOpcode::LOP_ANDK => {
560                formatAppend(
561                    result,
562                    format_args!(
563                        "ANDK R{} R{} K{} [",
564                        LUAU_INSN_A(insn),
565                        LUAU_INSN_B(insn),
566                        LUAU_INSN_C(insn)
567                    ),
568                );
569                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
570                result.push_str("]\n");
571                1
572            }
573            LuauOpcode::LOP_ORK => {
574                formatAppend(
575                    result,
576                    format_args!(
577                        "ORK R{} R{} K{} [",
578                        LUAU_INSN_A(insn),
579                        LUAU_INSN_B(insn),
580                        LUAU_INSN_C(insn)
581                    ),
582                );
583                self.dump_constant(result, LUAU_INSN_C(insn) as i32, false);
584                result.push_str("]\n");
585                1
586            }
587            LuauOpcode::LOP_CONCAT => {
588                formatAppend(
589                    result,
590                    format_args!(
591                        "CONCAT R{} R{} R{}\n",
592                        LUAU_INSN_A(insn),
593                        LUAU_INSN_B(insn),
594                        LUAU_INSN_C(insn)
595                    ),
596                );
597                1
598            }
599            LuauOpcode::LOP_NOT => {
600                formatAppend(
601                    result,
602                    format_args!("NOT R{} R{}\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
603                );
604                1
605            }
606            LuauOpcode::LOP_MINUS => {
607                formatAppend(
608                    result,
609                    format_args!("MINUS R{} R{}\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
610                );
611                1
612            }
613            LuauOpcode::LOP_LENGTH => {
614                formatAppend(
615                    result,
616                    format_args!("LENGTH R{} R{}\n", LUAU_INSN_A(insn), LUAU_INSN_B(insn)),
617                );
618                1
619            }
620            LuauOpcode::LOP_NEWTABLE => {
621                formatAppend(
622                    result,
623                    format_args!(
624                        "NEWTABLE R{} {} {}\n",
625                        LUAU_INSN_A(insn),
626                        if LUAU_INSN_B(insn) == 0 {
627                            0
628                        } else {
629                            1 << (LUAU_INSN_B(insn) as i32 - 1)
630                        },
631                        code[1]
632                    ),
633                );
634                2
635            }
636            LuauOpcode::LOP_DUPTABLE => {
637                formatAppend(
638                    result,
639                    format_args!("DUPTABLE R{} {}\n", LUAU_INSN_A(insn), LUAU_INSN_D(insn)),
640                );
641                1
642            }
643            LuauOpcode::LOP_SETLIST => {
644                formatAppend(
645                    result,
646                    format_args!(
647                        "SETLIST R{} R{} {} [{}]\n",
648                        LUAU_INSN_A(insn),
649                        LUAU_INSN_B(insn),
650                        LUAU_INSN_C(insn) as i32 - 1,
651                        code[1]
652                    ),
653                );
654                2
655            }
656            LuauOpcode::LOP_FORNPREP => {
657                formatAppend(
658                    result,
659                    format_args!("FORNPREP R{} L{}\n", LUAU_INSN_A(insn), target_label),
660                );
661                1
662            }
663            LuauOpcode::LOP_FORNLOOP => {
664                formatAppend(
665                    result,
666                    format_args!("FORNLOOP R{} L{}\n", LUAU_INSN_A(insn), target_label),
667                );
668                1
669            }
670            LuauOpcode::LOP_FORGPREP => {
671                formatAppend(
672                    result,
673                    format_args!("FORGPREP R{} L{}\n", LUAU_INSN_A(insn), target_label),
674                );
675                1
676            }
677            LuauOpcode::LOP_FORGLOOP => {
678                formatAppend(
679                    result,
680                    format_args!(
681                        "FORGLOOP R{} L{} {}{}\n",
682                        LUAU_INSN_A(insn),
683                        target_label,
684                        code[1] as u8,
685                        if (code[1] as i32) < 0 { " [inext]" } else { "" }
686                    ),
687                );
688                2
689            }
690            LuauOpcode::LOP_FORGPREP_INEXT => {
691                formatAppend(
692                    result,
693                    format_args!("FORGPREP_INEXT R{} L{}\n", LUAU_INSN_A(insn), target_label),
694                );
695                1
696            }
697            LuauOpcode::LOP_FORGPREP_NEXT => {
698                formatAppend(
699                    result,
700                    format_args!("FORGPREP_NEXT R{} L{}\n", LUAU_INSN_A(insn), target_label),
701                );
702                1
703            }
704            LuauOpcode::LOP_GETVARARGS => {
705                formatAppend(
706                    result,
707                    format_args!(
708                        "GETVARARGS R{} {}\n",
709                        LUAU_INSN_A(insn),
710                        LUAU_INSN_B(insn) as i32 - 1
711                    ),
712                );
713                1
714            }
715            LuauOpcode::LOP_DUPCLOSURE => {
716                formatAppend(
717                    result,
718                    format_args!("DUPCLOSURE R{} K{} [", LUAU_INSN_A(insn), LUAU_INSN_D(insn)),
719                );
720                self.dump_constant(result, LUAU_INSN_D(insn) as i32, false);
721                result.push_str("]\n");
722                1
723            }
724            LuauOpcode::LOP_BREAK => {
725                formatAppend(result, format_args!("BREAK\n"));
726                1
727            }
728            LuauOpcode::LOP_JUMPBACK => {
729                formatAppend(result, format_args!("JUMPBACK L{}\n", target_label));
730                1
731            }
732            LuauOpcode::LOP_LOADKX => {
733                formatAppend(
734                    result,
735                    format_args!("LOADKX R{} K{} [", LUAU_INSN_A(insn), code[1]),
736                );
737                self.dump_constant(result, code[1] as i32, false);
738                result.push_str("]\n");
739                2
740            }
741            LuauOpcode::LOP_JUMPX => {
742                formatAppend(result, format_args!("JUMPX L{}\n", target_label));
743                1
744            }
745            LuauOpcode::LOP_FASTCALL => {
746                formatAppend(
747                    result,
748                    format_args!("FASTCALL {} L{}\n", LUAU_INSN_A(insn), target_label),
749                );
750                1
751            }
752            LuauOpcode::LOP_FASTCALL1 => {
753                formatAppend(
754                    result,
755                    format_args!(
756                        "FASTCALL1 {} R{} L{}\n",
757                        LUAU_INSN_A(insn),
758                        LUAU_INSN_B(insn),
759                        target_label
760                    ),
761                );
762                1
763            }
764            LuauOpcode::LOP_FASTCALL2 => {
765                formatAppend(
766                    result,
767                    format_args!(
768                        "FASTCALL2 {} R{} R{} L{}\n",
769                        LUAU_INSN_A(insn),
770                        LUAU_INSN_B(insn),
771                        code[1],
772                        target_label
773                    ),
774                );
775                2
776            }
777            LuauOpcode::LOP_FASTCALL2K => {
778                formatAppend(
779                    result,
780                    format_args!(
781                        "FASTCALL2K {} R{} K{} L{} [",
782                        LUAU_INSN_A(insn),
783                        LUAU_INSN_B(insn),
784                        code[1],
785                        target_label
786                    ),
787                );
788                self.dump_constant(result, code[1] as i32, false);
789                result.push_str("]\n");
790                2
791            }
792            LuauOpcode::LOP_FASTCALL3 => {
793                formatAppend(
794                    result,
795                    format_args!(
796                        "FASTCALL3 {} R{} R{} R{} L{}\n",
797                        LUAU_INSN_A(insn),
798                        LUAU_INSN_B(insn),
799                        code[1] & 0xff,
800                        (code[1] >> 8) & 0xff,
801                        target_label
802                    ),
803                );
804                2
805            }
806            LuauOpcode::LOP_COVERAGE => {
807                formatAppend(result, format_args!("COVERAGE\n"));
808                1
809            }
810            LuauOpcode::LOP_CAPTURE => {
811                let a = LUAU_INSN_A(insn);
812                // LCT_VAL = 0, LCT_REF = 1, LCT_UPVAL = 2 (the port had VAL/UPVAL swapped).
813                formatAppend(
814                    result,
815                    format_args!(
816                        "CAPTURE {} {}{}\n",
817                        if a == 2 {
818                            "UPVAL"
819                        } else if a == 1 {
820                            "REF"
821                        } else if a == 0 {
822                            "VAL"
823                        } else {
824                            ""
825                        },
826                        if a == 2 { 'U' } else { 'R' },
827                        LUAU_INSN_B(insn)
828                    ),
829                );
830                1
831            }
832            LuauOpcode::LOP_JUMPXEQKNIL => {
833                formatAppend(
834                    result,
835                    format_args!(
836                        "JUMPXEQKNIL R{} L{}{}\n",
837                        LUAU_INSN_A(insn),
838                        target_label,
839                        if (code[1] >> 31) != 0 { " NOT" } else { "" }
840                    ),
841                );
842                2
843            }
844            LuauOpcode::LOP_JUMPXEQKB => {
845                formatAppend(
846                    result,
847                    format_args!(
848                        "JUMPXEQKB R{} {} L{}{}\n",
849                        LUAU_INSN_A(insn),
850                        code[1] & 1,
851                        target_label,
852                        if (code[1] >> 31) != 0 { " NOT" } else { "" }
853                    ),
854                );
855                2
856            }
857            LuauOpcode::LOP_JUMPXEQKN => {
858                formatAppend(
859                    result,
860                    format_args!(
861                        "JUMPXEQKN R{} K{} L{}{} [",
862                        LUAU_INSN_A(insn),
863                        code[1] & 0xffffff,
864                        target_label,
865                        if (code[1] >> 31) != 0 { " NOT" } else { "" }
866                    ),
867                );
868                self.dump_constant(result, (code[1] & 0xffffff) as i32, false);
869                result.push_str("]\n");
870                2
871            }
872            LuauOpcode::LOP_JUMPXEQKS => {
873                formatAppend(
874                    result,
875                    format_args!(
876                        "JUMPXEQKS R{} K{} L{}{} [",
877                        LUAU_INSN_A(insn),
878                        code[1] & 0xffffff,
879                        target_label,
880                        if (code[1] >> 31) != 0 { " NOT" } else { "" }
881                    ),
882                );
883                self.dump_constant(result, (code[1] & 0xffffff) as i32, false);
884                result.push_str("]\n");
885                2
886            }
887            LuauOpcode::LOP_GETUDATAKS => {
888                formatAppend(
889                    result,
890                    format_args!(
891                        "GETUDATAKS R{} R{} K{} [",
892                        LUAU_INSN_A(insn),
893                        LUAU_INSN_B(insn),
894                        LUAU_INSN_AUX_KV16(code[1])
895                    ),
896                );
897                self.dump_constant(result, LUAU_INSN_AUX_KV16(code[1]) as i32, false);
898                result.push_str("]\n");
899                2
900            }
901            LuauOpcode::LOP_SETUDATAKS => {
902                formatAppend(
903                    result,
904                    format_args!(
905                        "SETUDATAKS R{} R{} K{} [",
906                        LUAU_INSN_A(insn),
907                        LUAU_INSN_B(insn),
908                        LUAU_INSN_AUX_KV16(code[1])
909                    ),
910                );
911                self.dump_constant(result, LUAU_INSN_AUX_KV16(code[1]) as i32, false);
912                result.push_str("]\n");
913                2
914            }
915            LuauOpcode::LOP_NAMECALLUDATA => {
916                formatAppend(
917                    result,
918                    format_args!(
919                        "NAMECALLUDATA R{} R{} K{} [",
920                        LUAU_INSN_A(insn),
921                        LUAU_INSN_B(insn),
922                        LUAU_INSN_AUX_KV16(code[1])
923                    ),
924                );
925                self.dump_constant(result, LUAU_INSN_AUX_KV16(code[1]) as i32, false);
926                result.push_str("]\n");
927                2
928            }
929            LuauOpcode::LOP_NEWCLASSMEMBER => {
930                formatAppend(
931                    result,
932                    format_args!(
933                        "NEWCLASSMEMBER R{} R{} [",
934                        LUAU_INSN_A(insn),
935                        LUAU_INSN_C(insn)
936                    ),
937                );
938                self.dump_constant(result, code[1] as i32, false);
939                result.push_str("]\n");
940                2
941            }
942            LuauOpcode::LOP_CMPPROTO => {
943                formatAppend(
944                    result,
945                    format_args!(
946                        "CMPPROTO R{} #{} L{}\n",
947                        LUAU_INSN_A(insn),
948                        code[1],
949                        target_label
950                    ),
951                );
952                2
953            }
954            _ => {
955                LUAU_ASSERT!(false);
956                1
957            }
958        }
959    }
960}