Skip to main content

luaur_code_gen/functions/
to_string_detailed_ir_dump.rs

1use crate::enums::include_use_info::IncludeUseInfo;
2use crate::functions::append::append;
3use crate::functions::append_register_set::append_register_set;
4use crate::functions::get_jump_target_extra_live_in::get_jump_target_extra_live_in;
5use crate::functions::has_side_effects::has_side_effects;
6use crate::functions::is_non_terminating_jump::is_non_terminating_jump;
7use crate::functions::pad_to_detail_column::pad_to_detail_column;
8use crate::functions::to_string_ir_dump::to_string as to_string_inst;
9use crate::functions::to_string_ir_dump_alt_d::to_string as to_string_op;
10use crate::records::ir_block::IrBlock;
11use crate::records::ir_inst::IrInst;
12use crate::records::ir_to_string_context::IrToStringContext;
13
14pub fn to_string_detailed(
15    ctx: &mut IrToStringContext,
16    block: &IrBlock,
17    block_idx: u32,
18    inst: &mut IrInst,
19    inst_idx: u32,
20    include_use_info: IncludeUseInfo,
21) {
22    let start = ctx.result.len();
23
24    to_string_inst(ctx, inst, inst_idx);
25
26    if include_use_info == IncludeUseInfo::Yes {
27        pad_to_detail_column(&mut ctx.result, start);
28
29        if inst.use_count == 0 && has_side_effects(inst.cmd) {
30            if is_non_terminating_jump(inst.cmd) {
31                let extra_rs = get_jump_target_extra_live_in(ctx, block, block_idx, inst);
32
33                if extra_rs.regs.iter().any(|&r| r != 0) || extra_rs.vararg_seq {
34                    append(&mut ctx.result, format_args!("; %{}, extra in: ", inst_idx));
35                    append_register_set(ctx, &extra_rs, c", ".as_ptr());
36                    ctx.result.push_str("\n");
37                } else {
38                    append(&mut ctx.result, format_args!("; %{}\n", inst_idx));
39                }
40            } else {
41                append(&mut ctx.result, format_args!("; %{}\n", inst_idx));
42            }
43        } else {
44            append(
45                &mut ctx.result,
46                format_args!(
47                    "; useCount: {}, lastUse: %{}\n",
48                    inst.use_count, inst.last_use
49                ),
50            );
51        }
52    } else {
53        ctx.result.push_str("\n");
54    }
55
56    if luaur_common::FFlag::LuauCodegenVmExitSync.get() {
57        let sync_opt = ctx.vm_exit_info.find(&inst_idx).cloned();
58
59        if let Some(sync) = sync_opt {
60            if !sync.reg_stores.is_empty() {
61                append(&mut ctx.result, format_args!("   ; exit sync: "));
62
63                let mut comma = false;
64
65                for el in &sync.reg_stores {
66                    if comma {
67                        append(&mut ctx.result, format_args!(", "));
68                    }
69                    comma = true;
70
71                    append(&mut ctx.result, format_args!("R{}", el.reg));
72                }
73
74                comma = false;
75
76                append(&mut ctx.result, format_args!(", {{"));
77
78                for arg_op in sync.arg_ops.as_slice() {
79                    if comma {
80                        append(&mut ctx.result, format_args!(", "));
81                    }
82                    comma = true;
83
84                    to_string_op(ctx, *arg_op);
85                }
86
87                append(&mut ctx.result, format_args!("}}"));
88                append(&mut ctx.result, format_args!("\n"));
89            }
90        }
91    }
92}