Bind a label to the current offset. A label can only be bound once.
(&mut self, label: MachLabel, ctrl_plane: &mut ControlPlane)
| 724 | |
| 725 | /// Bind a label to the current offset. A label can only be bound once. |
| 726 | pub fn bind_label(&mut self, label: MachLabel, ctrl_plane: &mut ControlPlane) { |
| 727 | trace!( |
| 728 | "MachBuffer: bind label {:?} at offset {}", |
| 729 | label, |
| 730 | self.cur_offset() |
| 731 | ); |
| 732 | debug_assert_eq!(self.label_offsets[label.0 as usize], UNKNOWN_LABEL_OFFSET); |
| 733 | debug_assert_eq!(self.label_aliases[label.0 as usize], UNKNOWN_LABEL); |
| 734 | let offset = self.cur_offset(); |
| 735 | self.label_offsets[label.0 as usize] = offset; |
| 736 | self.lazily_clear_labels_at_tail(); |
| 737 | self.labels_at_tail.push(label); |
| 738 | |
| 739 | // Invariants hold: bound offset of label is <= cur_offset (in fact it |
| 740 | // is equal). If the `labels_at_tail` list was complete and precise |
| 741 | // before, it is still, because we have bound this label to the current |
| 742 | // offset and added it to the list (which contains all labels at the |
| 743 | // current offset). |
| 744 | |
| 745 | self.optimize_branches(ctrl_plane); |
| 746 | |
| 747 | // Post-invariant: by `optimize_branches()` (see argument there). |
| 748 | } |
| 749 | |
| 750 | /// Lazily clear `labels_at_tail` if the tail offset has moved beyond the |
| 751 | /// offset that it applies to. |