luaur_code_gen/methods/
assembly_builder_x_64_finalize.rs1use crate::macros::codegen_assert::CODEGEN_ASSERT;
2use crate::records::assembly_builder_x_64::AssemblyBuilderX64;
3
4impl AssemblyBuilderX64 {
5 pub fn finalize(&mut self) -> bool {
6 let code_size = (self.code_pos as usize).wrapping_sub(self.code.as_ptr() as usize);
7 self.code.resize(code_size, 0);
8
9 for fixup in self.pending_labels.iter().copied() {
10 let location = self.label_locations[(fixup.id - 1) as usize];
11 if !(location != !0u32) {
12 luaur_common::LUAU_DEBUGBREAK!();
13 }
14 let value = location.wrapping_sub(fixup.location.wrapping_add(4));
15 let offset = fixup.location as usize;
16 self.code[offset..offset + 4].copy_from_slice(&value.to_le_bytes());
17 }
18
19 let data_size = self.data.len() - self.data_pos;
20
21 if data_size > 0 {
22 self.data
23 .copy_within(self.data_pos..self.data_pos + data_size, 0);
24 }
25
26 self.data.resize(data_size, 0);
27
28 self.finalized = true;
29
30 true
31 }
32}