luaur_bytecode/methods/
bytecode_builder_annotate_instruction.rs1use crate::enums::dump_flags::DumpFlags;
2use crate::records::bytecode_builder::BytecodeBuilder;
3use crate::records::function::Function;
4use luaur_common::functions::format_append::formatAppend;
5use luaur_common::macros::luau_assert::LUAU_ASSERT;
6
7impl BytecodeBuilder {
8 pub fn annotate_instruction(&self, result: &mut String, fid: u32, instpos: u32) {
9 if (self.dump_flags & DumpFlags::Dump_Code as u32) == 0 {
10 return;
11 }
12
13 LUAU_ASSERT!(fid < self.functions.len() as u32);
14
15 let function: &Function = &self.functions[fid as usize];
16 let dump: &String = &function.dump;
17 let dumpinstoffs: &Vec<i32> = &function.dumpinstoffs;
18
19 let mut next = instpos + 1;
20
21 LUAU_ASSERT!(next < dumpinstoffs.len() as u32);
22
23 while next < dumpinstoffs.len() as u32 && dumpinstoffs[next as usize] == -1 {
25 next += 1;
26 }
27
28 let start_offset = dumpinstoffs[instpos as usize] as usize;
29 let end_offset = dumpinstoffs[next as usize] as usize;
30
31 formatAppend(result, format_args!("{}", &dump[start_offset..end_offset]));
32 }
33}