Skip to main content

luaur_code_gen/methods/
assembly_builder_x_64_place_label.rs

1use crate::records::assembly_builder_x_64::AssemblyBuilderX64;
2use crate::records::label::Label;
3
4impl AssemblyBuilderX64 {
5    pub fn place_label(&mut self, label: &mut Label) {
6        if label.location == !0u32 {
7            if label.id == 0 {
8                label.id = self.next_label;
9                self.next_label = self.next_label.wrapping_add(1);
10                // C++ `labelLocations.push_back(~0u)` — reserve this new label's
11                // slot in `label_locations`. The original port wrongly pushed a
12                // bogus Label into `pending_labels`, leaving `label_locations`
13                // short (out-of-bounds in `set_label`) and corrupting fixups.
14                self.label_locations.push(!0u32);
15            }
16
17            self.pending_labels.push(Label {
18                id: label.id,
19                location: self.get_code_size(),
20            });
21            self.place_imm_32(0);
22        } else {
23            self.place_imm_32((label.location.wrapping_sub(4 + self.get_code_size())) as i32);
24        }
25    }
26}