luaur_analysis/functions/
dump_instruction.rs1extern crate alloc;
2
3use crate::functions::dump_def::dump_def;
4use crate::functions::dump_expr::dump_expr;
5use crate::functions::dump_refinement::dump_refinement;
6use crate::functions::find_rhs_expr_dump_cfg::find_rhs_expr_symbol_ast_stat_local;
7use crate::functions::find_rhs_expr_dump_cfg_alt_b::find_rhs_expr_symbol_ast_stat_assign;
8use crate::type_aliases::definition::Definition;
9use crate::type_aliases::instruction::Instruction;
10use alloc::string::String;
11use luaur_ast::records::ast_expr::AstExpr;
12use luaur_common::records::dense_hash_map::DenseHashMap;
13
14pub fn dump_instruction(
15 inst: *const Instruction,
16 use_defs: &DenseHashMap<*mut AstExpr, *mut Definition>,
17) -> String {
18 unsafe {
19 match &*inst {
20 Instruction::Declare(decl) => {
21 let mut result = format!("local {}", dump_def(decl.def));
22 let rhs = find_rhs_expr_symbol_ast_stat_local((*decl.def).sym.clone(), decl.source);
23 if !rhs.is_null() {
24 result.push_str(" = ");
25 result.push_str(&dump_expr(rhs, use_defs));
26 }
27 result
28 }
29 Instruction::Assign(assign) => {
30 let mut result = dump_def(assign.def);
31 let rhs =
32 find_rhs_expr_symbol_ast_stat_assign((*assign.def).sym.clone(), assign.source);
33 if !rhs.is_null() {
34 result.push_str(" = ");
35 result.push_str(&dump_expr(rhs, use_defs));
36 }
37 result
38 }
39 Instruction::Join(join) => {
40 let mut result = format!("{} = join(", dump_def(join.definition));
41 for (i, operand) in join.operands.iter().enumerate() {
42 if i > 0 {
43 result.push_str(", ");
44 }
45 result.push_str(&dump_def(*operand));
46 }
47 result.push(')');
48 result
49 }
50 Instruction::Refine(flow) => {
51 format!(
52 "{} = refine({})",
53 dump_def(flow.definition),
54 dump_refinement(&*flow.prop)
55 )
56 }
57 }
58 }
59}