pub fn finalize_branches(&mut self)
    where
        I: MachInstEmit<MachSectionSize>,
    {
        // Compute fallthrough block, indexed by block.
        let num_final_blocks = self.final_block_order.len();
        let mut block_fallthrough: Vec<Option<BlockIndex>> = vec![None; self.num_blocks()];
        for i in 0..(num_final_blocks - 1) {
            let from = self.final_block_order[i];
            let to = self.final_block_order[i + 1];
            block_fallthrough[from as usize] = Some(to);
        }

        // Pass over VCode instructions and finalize two-way branches into
        // one-way branches with fallthrough.
        for block in 0..self.num_blocks() {
            let next_block = block_fallthrough[block];
            let (start, end) = self.block_ranges[block];

            for iix in start..end {
                let insn = &mut self.insts[iix as usize];
                insn.with_fallthrough_block(next_block);
            }
        }

        // Compute block offsets.
        let mut code_section = MachSectionSize::new(0);
        let mut const_section = MachSectionSize::new(0);
        let mut block_offsets = vec![0; self.num_blocks()];
        for block in &self.final_block_order {
            code_section.offset = I::align_basic_block(code_section.offset);
            block_offsets[*block as usize] = code_section.offset;
            let (start, end) = self.block_ranges[*block as usize];
            for iix in start..end {
                self.insts[iix as usize].emit(&mut code_section, &mut const_section);
            }
        }

        // Update branches with known block offsets. This looks like the
        // traversal above, but (i) does not update block_offsets, rather uses
        // it (so forward references are now possible), and (ii) mutates the
        // instructions.
        let mut code_section = MachSectionSize::new(0);
        let mut const_section = MachSectionSize::new(0);
        for block in &self.final_block_order {
            code_section.offset = I::align_basic_block(code_section.offset);
            let (start, end) = self.block_ranges[*block as usize];
            for iix in start..end {
                self.insts[iix as usize]
                    .with_block_offsets(code_section.offset, &block_offsets[..]);
                self.insts[iix as usize].emit(&mut code_section, &mut const_section);
            }
        }

        self.final_block_offsets = block_offsets;
        self.code_size = code_section.size();
        self.constants_start = I::align_constant_pool(self.code_size);
        self.constants_size = const_section.size();
    }
/// Mutate branch instructions to (i) lower two-way condbrs to one-way,
/// depending on fallthrough; and (ii) use concrete offsets.
Mutate branch instructions to (i) lower two-way condbrs to one-way,
depending on fallthrough; and (ii) use concrete offsets.
Mutate branch instructions to ( i ) lower two - way condbrs to one - way depending on fallthrough ; and ( ii ) use concrete offsets .
pub fn finalize_branches(&mut self)
    where
        I: MachInstEmit<MachSectionSize>,
    {
        // Compute fallthrough block, indexed by block.
        let num_final_blocks = self.final_block_order.len();
        let mut block_fallthrough: Vec<Option<BlockIndex>> = vec![None; self.num_blocks()];
        for i in 0..(num_final_blocks - 1) {
            let from = self.final_block_order[i];
            let to = self.final_block_order[i + 1];
            block_fallthrough[from as usize] = Some(to);
        }
        // Pass over VCode instructions and finalize two-way branches into
        // one-way branches with fallthrough.
        for block in 0..self.num_blocks() {
            let next_block = block_fallthrough[block];
            let (start, end) = self.block_ranges[block];
            for iix in start..end {
                let insn = &mut self.insts[iix as usize];
                insn.with_fallthrough_block(next_block);
            }
        }
        // Compute block offsets.
        let mut code_section = MachSectionSize::new(0);
        let mut const_section = MachSectionSize::new(0);
        let mut block_offsets = vec![0; self.num_blocks()];
        for block in &self.final_block_order {
            code_section.offset = I::align_basic_block(code_section.offset);
            block_offsets[*block as usize] = code_section.offset;
            let (start, end) = self.block_ranges[*block as usize];
            for iix in start..end {
                self.insts[iix as usize].emit(&mut code_section, &mut const_section);
            }
        }
        // Update branches with known block offsets. This looks like the
        // traversal above, but (i) does not update block_offsets, rather uses
        // it (so forward references are now possible), and (ii) mutates the
        // instructions.
        let mut code_section = MachSectionSize::new(0);
        let mut const_section = MachSectionSize::new(0);
        for block in &self.final_block_order {
            code_section.offset = I::align_basic_block(code_section.offset);
            let (start, end) = self.block_ranges[*block as usize];
            for iix in start..end {
                self.insts[iix as usize]
                    .with_block_offsets(code_section.offset, &block_offsets[..]);
                self.insts[iix as usize].emit(&mut code_section, &mut const_section);
            }
        }
        self.final_block_offsets = block_offsets;
        self.code_size = code_section.size();
        self.constants_start = I::align_constant_pool(self.code_size);
        self.constants_size = const_section.size();
    }
pub fn finalize_branches ( & mut self ) where I : MachInstEmit < MachSectionSize > , { // Compute fallthrough block, indexed by block. let num_final_blocks = self . final_block_order . len ( ) ; let mut block_fallthrough : Vec < Option < BlockIndex > > = vec ! [ None self num_blocks ( ) ] ; for i in 0 .. ( num_final_blocks - 1 ) { let from = self . final_block_order [ i ] ; let to = self . final_block_order [ i + 1 ] ; block_fallthrough [ from as usize ] = Some ( to ) ; } // Pass over VCode instructions and finalize two-way branches into // one-way branches with fallthrough. for block in 0 .. self . num_blocks ( ) { let next_block = block_fallthrough [ block ] ; let ( start , end ) = self . block_ranges [ block ] ; for iix in start .. end { let insn = & mut self . insts [ iix as usize ] ; insn . with_fallthrough_block ( next_block ) ; } } // Compute block offsets. let mut code_section = MachSectionSize :: new ( 0 ) ; let mut const_section = MachSectionSize :: new ( 0 ) ; let mut block_offsets = vec ! [ 0 self num_blocks ( ) ] ; for block in & self . final_block_order { code_section . offset = I :: align_basic_block ( code_section . offset ) ; block_offsets [ * block as usize ] = code_section . offset ; let ( start , end ) = self . block_ranges [ * block as usize ] ; for iix in start .. end { self . insts [ iix as usize ] . emit ( & mut code_section , & mut const_section ) ; } } // Update branches with known block offsets. This looks like the // traversal above, but (i) does not update block_offsets, rather uses // it (so forward references are now possible), and (ii) mutates the // instructions. let mut code_section = MachSectionSize :: new ( 0 ) ; let mut const_section = MachSectionSize :: new ( 0 ) ; for block in & self . final_block_order { code_section . offset = I :: align_basic_block ( code_section . offset ) ; let ( start , end ) = self . block_ranges [ * block as usize ] ; for iix in start .. end { self . insts [ iix as usize ] . with_block_offsets ( code_section . offset , & block_offsets [ .. ] ) ; self . insts [ iix as usize ] . emit ( & mut code_section , & mut const_section ) ; } } self . final_block_offsets = block_offsets ; self . code_size = code_section . size ( ) ; self . constants_start = I :: align_constant_pool ( self . code_size ) ; self . constants_size = const_section . size ( ) ; }
Mutate branch instructions to (i) lower two-way condbrs to one-way,
depending on fallthrough; and (ii) use concrete offsets.
Mutate branch instructions to ( i ) lower two - way condbrs to one - way depending on fallthrough ; and ( ii ) use concrete offsets .
&mut self
&mut self