Finish any deferred emissions and/or fixups.
(
mut self,
constants: &VCodeConstants,
ctrl_plane: &mut ControlPlane,
)
| 1625 | |
| 1626 | /// Finish any deferred emissions and/or fixups. |
| 1627 | pub fn finish( |
| 1628 | mut self, |
| 1629 | constants: &VCodeConstants, |
| 1630 | ctrl_plane: &mut ControlPlane, |
| 1631 | ) -> MachBufferFinalized<Stencil> { |
| 1632 | let _tt = timing::vcode_emit_finish(); |
| 1633 | |
| 1634 | self.finish_emission_maybe_forcing_veneers(ForceVeneers::No, ctrl_plane); |
| 1635 | |
| 1636 | let alignment = self.finish_constants(constants); |
| 1637 | |
| 1638 | // Resolve all labels to their offsets. |
| 1639 | let finalized_relocs = self |
| 1640 | .relocs |
| 1641 | .iter() |
| 1642 | .map(|reloc| FinalizedMachReloc { |
| 1643 | offset: reloc.offset, |
| 1644 | kind: reloc.kind, |
| 1645 | addend: reloc.addend, |
| 1646 | target: match &reloc.target { |
| 1647 | RelocTarget::ExternalName(name) => { |
| 1648 | FinalizedRelocTarget::ExternalName(name.clone()) |
| 1649 | } |
| 1650 | RelocTarget::Label(label) => { |
| 1651 | FinalizedRelocTarget::Func(self.resolve_label_offset(*label)) |
| 1652 | } |
| 1653 | }, |
| 1654 | }) |
| 1655 | .collect(); |
| 1656 | |
| 1657 | let finalized_exception_handlers = self |
| 1658 | .exception_handlers |
| 1659 | .iter() |
| 1660 | .map(|handler| handler.finalize(|label| self.resolve_label_offset(label))) |
| 1661 | .collect(); |
| 1662 | |
| 1663 | let mut srclocs = self.srclocs; |
| 1664 | srclocs.sort_by_key(|entry| entry.start); |
| 1665 | |
| 1666 | MachBufferFinalized { |
| 1667 | data: self.data, |
| 1668 | relocs: finalized_relocs, |
| 1669 | traps: self.traps, |
| 1670 | call_sites: self.call_sites, |
| 1671 | patchable_call_sites: self.patchable_call_sites, |
| 1672 | exception_handlers: finalized_exception_handlers, |
| 1673 | srclocs, |
| 1674 | debug_tags: self.debug_tags, |
| 1675 | debug_tag_pool: self.debug_tag_pool, |
| 1676 | user_stack_maps: self.user_stack_maps, |
| 1677 | unwind_info: self.unwind_info, |
| 1678 | alignment, |
| 1679 | frame_layout: self.frame_layout, |
| 1680 | nop_units: I::gen_nop_units(), |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | /// Add an external relocation at the given offset. |