pub struct FuncTranslationState {
pub(crate) stack: Vec<Value>,
pub(crate) control_stack: Vec<ControlStackFrame>,
pub(crate) reachable: bool,
globals: HashMap<GlobalIndex, GlobalVariable>,
heaps: HashMap<MemoryIndex, Heap>,
signatures: HashMap<SignatureIndex, (SigRef, usize)>,
functions: HashMap<FunctionIndex, (FuncRef, usize)>,
}
Expand description
Contains information passed along during a function’s translation and that records:
- The current value and control stacks.
- The depth of the two unreachable control blocks stacks, that are manipulated when translating unreachable code;
Fields§
§stack: Vec<Value>
A stack of values corresponding to the active values in the input wasm function at this point.
control_stack: Vec<ControlStackFrame>
A stack of active control flow operations at this point in the input wasm function.
reachable: bool
Is the current translation state still reachable? This is false when translating operators like End, Return, or Unreachable.
globals: HashMap<GlobalIndex, GlobalVariable>
§heaps: HashMap<MemoryIndex, Heap>
§signatures: HashMap<SignatureIndex, (SigRef, usize)>
§functions: HashMap<FunctionIndex, (FuncRef, usize)>
Implementations§
source§impl FuncTranslationState
impl FuncTranslationState
fn clear(&mut self)
sourcepub(crate) fn initialize(&mut self, sig: &Signature, exit_block: Block)
pub(crate) fn initialize(&mut self, sig: &Signature, exit_block: Block)
Initialize the state for compiling a function with the given signature.
This resets the state to containing only a single block representing the whole function. The exit block is the last block in the function which will contain the return instruction.
sourcepub(crate) fn pop2(&mut self) -> (Value, Value)
pub(crate) fn pop2(&mut self) -> (Value, Value)
Pop two values. Return them in the order they were pushed.
sourcepub(crate) fn pop3(&mut self) -> (Value, Value, Value)
pub(crate) fn pop3(&mut self) -> (Value, Value, Value)
Pop three values. Return them in the order they were pushed.
sourcefn ensure_length_is_at_least(&self, n: usize)
fn ensure_length_is_at_least(&self, n: usize)
Helper to ensure the stack size is at least as big as n
; note that due to
debug_assert
this will not execute in non-optimized builds.
sourcepub(crate) fn popn(&mut self, n: usize)
pub(crate) fn popn(&mut self, n: usize)
Pop the top n
values on the stack.
The popped values are not returned. Use peekn
to look at them before popping.
sourcepub(crate) fn peekn(&self, n: usize) -> &[Value]
pub(crate) fn peekn(&self, n: usize) -> &[Value]
Peek at the top n
values on the stack in the order they were pushed.
sourcepub(crate) fn peekn_mut(&mut self, n: usize) -> &mut [Value]
pub(crate) fn peekn_mut(&mut self, n: usize) -> &mut [Value]
Peek at the top n
values on the stack in the order they were pushed.
sourcepub(crate) fn push_block(
&mut self,
following_code: Block,
num_param_types: usize,
num_result_types: usize,
)
pub(crate) fn push_block( &mut self, following_code: Block, num_param_types: usize, num_result_types: usize, )
Push a block on the control stack.
source§impl FuncTranslationState
impl FuncTranslationState
Methods for handling entity references.
sourcepub(crate) fn get_global<FE: FuncEnvironment + ?Sized>(
&mut self,
func: &mut Function,
index: u32,
environ: &mut FE,
) -> WasmResult<GlobalVariable>
pub(crate) fn get_global<FE: FuncEnvironment + ?Sized>( &mut self, func: &mut Function, index: u32, environ: &mut FE, ) -> WasmResult<GlobalVariable>
Get the GlobalVariable
reference that should be used to access the global variable
index
. Create the reference if necessary.
Also return the WebAssembly type of the global.
sourcepub(crate) fn get_heap<FE: FuncEnvironment + ?Sized>(
&mut self,
func: &mut Function,
index: u32,
environ: &mut FE,
) -> WasmResult<Heap>
pub(crate) fn get_heap<FE: FuncEnvironment + ?Sized>( &mut self, func: &mut Function, index: u32, environ: &mut FE, ) -> WasmResult<Heap>
Get the Heap
reference that should be used to access linear memory index
.
Create the reference if necessary.
sourcepub(crate) fn get_indirect_sig<FE: FuncEnvironment + ?Sized>(
&mut self,
func: &mut Function,
index: u32,
environ: &mut FE,
) -> WasmResult<(SigRef, usize)>
pub(crate) fn get_indirect_sig<FE: FuncEnvironment + ?Sized>( &mut self, func: &mut Function, index: u32, environ: &mut FE, ) -> WasmResult<(SigRef, usize)>
Get the SigRef
reference that should be used to make an indirect call with signature
index
. Also return the number of WebAssembly arguments in the signature.
Create the signature if necessary.
sourcepub(crate) fn get_direct_func<FE: FuncEnvironment + ?Sized>(
&mut self,
func: &mut Function,
index: u32,
environ: &mut FE,
) -> WasmResult<(FuncRef, usize)>
pub(crate) fn get_direct_func<FE: FuncEnvironment + ?Sized>( &mut self, func: &mut Function, index: u32, environ: &mut FE, ) -> WasmResult<(FuncRef, usize)>
Get the FuncRef
reference that should be used to make a direct call to function
index
. Also return the number of WebAssembly arguments in the signature.
Create the function reference if necessary.
Auto Trait Implementations§
impl Freeze for FuncTranslationState
impl RefUnwindSafe for FuncTranslationState
impl Send for FuncTranslationState
impl Sync for FuncTranslationState
impl Unpin for FuncTranslationState
impl UnwindSafe for FuncTranslationState
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more