fn generate_stack_height_global(ctx: &mut Context, module: &mut elements::Module) {
	let global_entry = builder::global()
		.value_type()
		.i32()
		.mutable()
		.init_expr(elements::Instruction::I32Const(0))
		.build();

	// Try to find an existing global section.
	for section in module.sections_mut() {
		if let elements::Section::Global(ref mut gs) = *section {
			gs.entries_mut().push(global_entry);

			let stack_height_global_idx = (gs.entries().len() as u32) - 1;
			ctx.stack_height_global_idx = Some(stack_height_global_idx);
			return;
		}
	}

	// Existing section not found, create one!
	module.sections_mut().push(elements::Section::Global(
		elements::GlobalSection::with_entries(vec![global_entry]),
	));
	ctx.stack_height_global_idx = Some(0);
}
/// Generate a new global that will be used for tracking current stack height.
Generate a new global that will be used for tracking current stack height.
Generate a new global that will be used for tracking current stack height .
fn generate_stack_height_global(ctx: &mut Context, module: &mut elements::Module) {
	let global_entry = builder::global()
		.value_type()
		.i32()
		.mutable()
		.init_expr(elements::Instruction::I32Const(0))
		.build();
	// Try to find an existing global section.
	for section in module.sections_mut() {
		if let elements::Section::Global(ref mut gs) = *section {
			gs.entries_mut().push(global_entry);
			let stack_height_global_idx = (gs.entries().len() as u32) - 1;
			ctx.stack_height_global_idx = Some(stack_height_global_idx);
			return;
		}
	}
	// Existing section not found, create one!
	module.sections_mut().push(elements::Section::Global(
		elements::GlobalSection::with_entries(vec![global_entry]),
	));
	ctx.stack_height_global_idx = Some(0);
}
fn generate_stack_height_global ( ctx : & mut Context , module : & mut elements :: Module ) { let global_entry = builder :: global ( ) . value_type ( ) . i32 ( ) . mutable ( ) . init_expr ( elements :: Instruction :: I32Const ( 0 ) ) . build ( ) ; // Try to find an existing global section. for section in module . sections_mut ( ) { if let elements :: Section :: Global ( ref mut gs ) = * section { gs . entries_mut ( ) . push ( global_entry ) ; let stack_height_global_idx = ( gs . entries ( ) . len ( ) as u32 ) - 1 ; ctx . stack_height_global_idx = Some ( stack_height_global_idx ) ; return ; } } // Existing section not found, create one! module . sections_mut ( ) . push ( elements :: Section :: Global ( elements :: GlobalSection :: with_entries ( vec ! [ global_entry ] ) , ) ) ; ctx . stack_height_global_idx = Some ( 0 ) ; }
Generate a new global that will be used for tracking current stack height.
Generate a new global that will be used for tracking current stack height .
ctx
&mut Context
module
&mut elements::Module
ctx
&mut Context
module
&mut elements::Module