Skip to main content

luaur_code_gen/methods/
assembly_builder_a_64_patch_label.rs

1use crate::enums::kind::Kind;
2use crate::records::assembly_builder_a_64::AssemblyBuilderA64;
3use crate::records::label::Label;
4use crate::records::patch::Patch;
5
6impl AssemblyBuilderA64 {
7    pub fn patch_label(&mut self, label: &mut Label, kind: Kind) {
8        let location = self.get_code_size().wrapping_sub(1);
9
10        if label.location == !0u32 {
11            if label.id == 0 {
12                label.id = self.next_label;
13                self.next_label = self.next_label.wrapping_add(1);
14                self.label_locations.push(!0u32);
15            }
16
17            let mut patch = Patch {
18                kind_and_label: 0,
19                location,
20            };
21            patch.set_kind(kind);
22            patch.set_label(label.id);
23            self.pending_labels.push(patch);
24        } else {
25            let value = label.location as i32 - location as i32;
26            self.patch_offset(location, value, kind);
27        }
28    }
29}