/// Emit a control instruction to the output.
///
/// See https://webassembly.github.io/spec/core/binary/instructions.html#control-instructions
Emit a control instruction to the output.
Emit a control instruction to the output .
fn emit_control_instruction<O: Write + ?Sized>(
    instruction: &ControlInstruction,
    output: &mut O,
) -> Result<usize, EmitError> {
    let mut bytes = 0;
    match instruction {
        ControlInstruction::Unreachable => {
            bytes += emit_byte(0x00u8, output)?;
        }
        ControlInstruction::Nop => {
            bytes += emit_byte(0x01u8, output)?;
        }
        ControlInstruction::Block(kind, expression) => {
            bytes += emit_byte(0x02u8, output)?;
            bytes += emit_block_type(kind, output)?;
            bytes += emit_expression(expression, output)?;
        }
        ControlInstruction::Loop(kind, expression) => {
            bytes += emit_byte(0x03u8, output)?;
            bytes += emit_block_type(kind, output)?;
            bytes += emit_expression(expression, output)?;
        }
        ControlInstruction::If(kind, positive, negative) => {
            bytes += emit_byte(0x04u8, output)?;
            bytes += emit_block_type(kind, output)?;
            if let Some(negative) = negative {
                bytes += emit_repeated(positive.instructions(), output, emit_instruction)?;
                bytes += emit_byte(0x05u8, output)?;
                bytes += emit_expression(negative, output)?;
            } else {
                bytes += emit_expression(positive, output)?;
            }
        }
        ControlInstruction::Branch(index) => {
            bytes += emit_byte(0x0Cu8, output)?;
            bytes += emit_u32(index, output)?;
        }
        ControlInstruction::BranchIf(index) => {
            bytes += emit_byte(0x0Du8, output)?;
            bytes += emit_u32(index, output)?;
        }
        ControlInstruction::BranchTable(indices, index) => {
            bytes += emit_byte(0x0Eu8, output)?;
            bytes += emit_vector(indices, output, emit_u32)?;
            bytes += emit_u32(index, output)?;
        }
        ControlInstruction::Return => {
            bytes += emit_byte(0x0Fu8, output)?;
        }
        ControlInstruction::Call(index) => {
            bytes += emit_byte(0x10u8, output)?;
            bytes += emit_u32(index, output)?;
        }
        ControlInstruction::CallIndirect(table, kind) => {
            bytes += emit_byte(0x11u8, output)?;
            bytes += emit_u32(kind, output)?;
            bytes += emit_u32(table, output)?;
        }
    }
    Ok(bytes)
}
fn emit_control_instruction < O : Write + ? Sized > ( instruction : & ControlInstruction , output : & mut O , ) -> Result < usize , EmitError > { let mut bytes = 0 ; match instruction { ControlInstruction :: Unreachable => { bytes += emit_byte ( 0x00u8 , output ) ? ; } ControlInstruction :: Nop => { bytes += emit_byte ( 0x01u8 , output ) ? ; } ControlInstruction :: Block ( kind , expression ) => { bytes += emit_byte ( 0x02u8 , output ) ? ; bytes += emit_block_type ( kind , output ) ? ; bytes += emit_expression ( expression , output ) ? ; } ControlInstruction :: Loop ( kind , expression ) => { bytes += emit_byte ( 0x03u8 , output ) ? ; bytes += emit_block_type ( kind , output ) ? ; bytes += emit_expression ( expression , output ) ? ; } ControlInstruction :: If ( kind , positive , negative ) => { bytes += emit_byte ( 0x04u8 , output ) ? ; bytes += emit_block_type ( kind , output ) ? ; if let Some ( negative ) = negative { bytes += emit_repeated ( positive . instructions ( ) , output , emit_instruction ) ? ; bytes += emit_byte ( 0x05u8 , output ) ? ; bytes += emit_expression ( negative , output ) ? ; } else { bytes += emit_expression ( positive , output ) ? ; } } ControlInstruction :: Branch ( index ) => { bytes += emit_byte ( 0x0Cu8 , output ) ? ; bytes += emit_u32 ( index , output ) ? ; } ControlInstruction :: BranchIf ( index ) => { bytes += emit_byte ( 0x0Du8 , output ) ? ; bytes += emit_u32 ( index , output ) ? ; } ControlInstruction :: BranchTable ( indices , index ) => { bytes += emit_byte ( 0x0Eu8 , output ) ? ; bytes += emit_vector ( indices , output , emit_u32 ) ? ; bytes += emit_u32 ( index , output ) ? ; } ControlInstruction :: Return => { bytes += emit_byte ( 0x0Fu8 , output ) ? ; } ControlInstruction :: Call ( index ) => { bytes += emit_byte ( 0x10u8 , output ) ? ; bytes += emit_u32 ( index , output ) ? ; } ControlInstruction :: CallIndirect ( table , kind ) => { bytes += emit_byte ( 0x11u8 , output ) ? ; bytes += emit_u32 ( kind , output ) ? ; bytes += emit_u32 ( table , output ) ? ; } } Ok ( bytes ) }
Emit a control instruction to the output.
Emit a control instruction to the output .
instruction
&ControlInstruction
output
&mut O