MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / ensure_stack_state

Method ensure_stack_state

winch/codegen/src/codegen/control.rs:409–430  ·  view source on GitHub ↗

This function ensures that the state of the -- machine and value -- stack is the right one when reaching a control frame branch in which reachability is restored or when reaching the end of a function in an unreachable state. This function is intended to be called when handling an unreachable else or end. This function will truncate the value stack to the base length of the control frame and wil

(
        &mut self,
        masm: &mut M,
        context: &mut CodeGenContext<Emission>,
    )

Source from the content-addressed store, hash-verified

407 // NB: This method is assumed to be called *before* pushing any block
408 // results to the value stack, so that any excess values are cleaned up.
409 pub fn ensure_stack_state<M: MacroAssembler>(
410 &mut self,
411 masm: &mut M,
412 context: &mut CodeGenContext<Emission>,
413 ) -> Result<()> {
414 let state = self.stack_state();
415 // This assumes that at jump sites, the machine stack pointer will be
416 // adjusted to match the expectations of the target branch (e.g.
417 // `target_offset`); after performing the jump, the MacroAssembler
418 // implementation will soft-reset the stack pointer offset to its
419 // original offset, ensure that other parts of the program have access
420 // to the right offset, this is especially important in conditional
421 // branches.
422 // When restoring reachability we ensure that the MacroAssembler offset
423 // is set to match the expectations of the target branch, similar to how
424 // the machine stack pointer was adjusted at jump sites.
425 masm.reset_stack_pointer(state.target_offset)?;
426 // We use the base length, because this function is assumed to be called
427 // *before* pushing any results to the value stack. This way, any excess
428 // values will be discarded.
429 context.truncate_stack_to(state.base_len)
430 }
431
432 /// Return the type information of the block.
433 pub fn sig(&self) -> &BlockSig {

Callers 2

Calls 3

stack_stateMethod · 0.80
truncate_stack_toMethod · 0.80
reset_stack_pointerMethod · 0.45

Tested by

no test coverage detected