code
stringlengths 40
729k
| docstring
stringlengths 22
46.3k
| func_name
stringlengths 1
97
| language
stringclasses 1
value | repo
stringlengths 6
48
| path
stringlengths 8
176
| url
stringlengths 47
228
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
fn fetch_branch_table_offset(&self, index: Reg, len_targets: u32) -> usize {
let index: u32 = self.get_register_as::<u32>(index);
// The index of the default target which is the last target of the slice.
let max_index = len_targets - 1;
// A normalized index will always yield a target without panicking.
cmp::min(index, max_index) as usize + 1
}
|
Fetches the branch table index value and normalizes it to clamp between `0..len_targets`.
|
fetch_branch_table_offset
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/branch.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/branch.rs
|
Apache-2.0
|
fn execute_branch_binop_imm16_rhs<T>(
&mut self,
lhs: Reg,
rhs: Const16<T>,
offset: BranchOffset16,
f: fn(T, T) -> bool,
) where
T: From<Const16<T>>,
UntypedVal: ReadAs<T>,
{
let lhs: T = self.get_register_as(lhs);
let rhs = T::from(rhs);
if f(lhs, rhs) {
return self.branch_to16(offset);
}
self.next_instr()
}
|
Executes a generic fused compare and branch instruction with immediate `rhs` operand.
|
execute_branch_binop_imm16_rhs
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/branch.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/branch.rs
|
Apache-2.0
|
fn execute_branch_binop_imm16_lhs<T>(
&mut self,
lhs: Const16<T>,
rhs: Reg,
offset: BranchOffset16,
f: fn(T, T) -> bool,
) where
T: From<Const16<T>>,
UntypedVal: ReadAs<T>,
{
let lhs = T::from(lhs);
let rhs: T = self.get_register_as(rhs);
if f(lhs, rhs) {
return self.branch_to16(offset);
}
self.next_instr()
}
|
Executes a generic fused compare and branch instruction with immediate `rhs` operand.
|
execute_branch_binop_imm16_lhs
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/branch.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/branch.rs
|
Apache-2.0
|
pub fn dispatch_host_func(
store: &mut PrunedStore,
value_stack: &mut ValueStack,
host_func: HostFuncEntity,
instance: Option<&Instance>,
call_hooks: CallHooks,
) -> Result<(u16, u16), Error> {
let len_params = host_func.len_params();
let len_results = host_func.len_results();
let max_inout = len_params.max(len_results);
let values = value_stack.as_slice_mut();
let params_results = FuncInOut::new(
values.split_at_mut(values.len() - usize::from(max_inout)).1,
usize::from(len_params),
usize::from(len_results),
);
store
.call_host_func(&host_func, instance, params_results, call_hooks)
.inspect_err(|_error| {
// Note: We drop the values that have been temporarily added to
// the stack to act as parameter and result buffer for the
// called host function. Since the host function failed we
// need to clean up the temporary buffer values here.
// This is required for resumable calls to work properly.
value_stack.drop(usize::from(max_inout));
})?;
Ok((len_params, len_results))
}
|
Dispatches and executes the host function.
Returns the number of parameters and results of the called host function.
# Errors
Returns the error of the host function if an error occurred.
|
dispatch_host_func
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
fn pull_call_indirect_params(&mut self) -> (u64, index::Table) {
self.ip.add(1);
match *self.ip.get() {
Instruction::CallIndirectParams { index, table } => {
let index: u64 = self.get_register_as(index);
(index, table)
}
unexpected => {
// Safety: Wasmi translation guarantees that correct instruction parameter follows.
unsafe {
unreachable_unchecked!(
"expected `Instruction::CallIndirectParams` but found {unexpected:?}"
)
}
}
}
}
|
Fetches the [`Instruction::CallIndirectParams`] parameter for a call [`Instruction`].
# Note
- This advances the [`InstructionPtr`] to the next [`Instruction`].
- This is done by encoding an [`Instruction::TableGet`] instruction
word following the actual instruction where the [`index::Table`]
parameter belongs to.
- This is required for some instructions that do not fit into
a single instruction word and store a [`index::Table`] value in
another instruction word.
|
pull_call_indirect_params
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
fn pull_call_indirect_params_imm16(&mut self) -> (u64, index::Table) {
self.ip.add(1);
match *self.ip.get() {
Instruction::CallIndirectParamsImm16 { index, table } => {
let index: u64 = index.into();
(index, table)
}
unexpected => {
// Safety: Wasmi translation guarantees that correct instruction parameter follows.
unsafe {
unreachable_unchecked!(
"expected `Instruction::CallIndirectParamsImm16` but found {unexpected:?}"
)
}
}
}
}
|
Fetches the [`Instruction::CallIndirectParamsImm16`] parameter for a call [`Instruction`].
# Note
- This advances the [`InstructionPtr`] to the next [`Instruction`].
- This is done by encoding an [`Instruction::TableGet`] instruction
word following the actual instruction where the [`index::Table`]
parameter belongs to.
- This is required for some instructions that do not fit into
a single instruction word and store a [`index::Table`] value in
another instruction word.
|
pull_call_indirect_params_imm16
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
fn copy_call_params(&mut self, uninit_params: &mut FrameParams) {
self.ip.add(1);
if let Instruction::RegisterList { .. } = self.ip.get() {
self.copy_call_params_list(uninit_params);
}
match self.ip.get() {
Instruction::Register { reg } => {
self.copy_regs(uninit_params, array::from_ref(reg));
}
Instruction::Register2 { regs } => {
self.copy_regs(uninit_params, regs);
}
Instruction::Register3 { regs } => {
self.copy_regs(uninit_params, regs);
}
unexpected => {
// Safety: Wasmi translation guarantees that register list finalizer exists.
unsafe {
unreachable_unchecked!(
"expected register-list finalizer but found: {unexpected:?}"
)
}
}
}
}
|
Copies the parameters from caller for the callee [`CallFrame`].
This will also adjust the instruction pointer to point to the
last call parameter [`Instruction`] if any.
|
copy_call_params
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
fn copy_regs<const N: usize>(&self, uninit_params: &mut FrameParams, regs: &[Reg; N]) {
for value in regs {
let value = self.get_register(*value);
// Safety: The `callee.results()` always refer to a span of valid
// registers of the `caller` that does not overlap with the
// registers of the callee since they reside in different
// call frames. Therefore this access is safe.
unsafe { uninit_params.init_next(value) }
}
}
|
Copies an array of [`Reg`] to the `dst` [`Reg`] span.
|
copy_regs
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
fn execute_return_call_imported_impl<C: ReturnCallContext>(
&mut self,
store: &mut PrunedStore,
func: index::Func,
) -> Result<ControlFlow, Error> {
let func = self.get_func(func);
self.execute_call_imported_impl::<C>(store, None, &func)
}
|
Executes an [`Instruction::ReturnCallImported`] or [`Instruction::ReturnCallImported0`].
|
execute_return_call_imported_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
fn execute_call_imported_impl<C: CallContext>(
&mut self,
store: &mut PrunedStore,
results: Option<RegSpan>,
func: &Func,
) -> Result<ControlFlow, Error> {
match store.inner().resolve_func(func) {
FuncEntity::Wasm(func) => {
let instance = *func.instance();
let func_body = func.func_body();
let results = results.unwrap_or_else(|| self.caller_results());
self.prepare_compiled_func_call::<C>(
store.inner_mut(),
results,
func_body,
Some(instance),
)?;
self.cache.update(store.inner_mut(), &instance);
Ok(ControlFlow::Continue(()))
}
FuncEntity::Host(host_func) => {
let host_func = *host_func;
self.execute_host_func::<C>(store, results, func, host_func)
}
}
}
|
Executes an imported or indirect (tail) call instruction.
|
execute_call_imported_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
fn execute_host_func<C: CallContext>(
&mut self,
store: &mut PrunedStore,
results: Option<RegSpan>,
func: &Func,
host_func: HostFuncEntity,
) -> Result<ControlFlow, Error> {
let len_params = host_func.len_params();
let len_results = host_func.len_results();
let max_inout = usize::from(len_params.max(len_results));
let instance = *self.stack.calls.instance_expect();
// We have to reinstantiate the `self.sp` [`FrameRegisters`] since we just called
// [`ValueStack::reserve`] which might invalidate all live [`FrameRegisters`].
let (caller, popped_instance) = match <C as CallContext>::KIND {
CallKind::Nested => self.stack.calls.peek().copied().map(|frame| (frame, None)),
CallKind::Tail => self.stack.calls.pop(),
}
.expect("need to have a caller on the call stack");
let buffer = self.stack.values.extend_by(max_inout, |this| {
// Safety: we use the base offset of a live call frame on the call stack.
self.sp = unsafe { this.stack_ptr_at(caller.base_offset()) };
})?;
if <C as CallContext>::HAS_PARAMS {
let mut uninit_params = FrameParams::new(buffer);
self.copy_call_params(&mut uninit_params);
}
if matches!(<C as CallContext>::KIND, CallKind::Nested) {
self.update_instr_ptr_at(1);
}
let results = results.unwrap_or_else(|| caller.results());
self.dispatch_host_func(store, host_func, &instance)
.map_err(|error| match self.stack.calls.is_empty() {
true => error,
false => ResumableHostTrapError::new(error, *func, results).into(),
})?;
self.cache.update(store.inner_mut(), &instance);
let results = results.iter(len_results);
match <C as CallContext>::KIND {
CallKind::Nested => {
let returned = self.stack.values.drop_return(max_inout);
for (result, value) in results.zip(returned) {
// # Safety (1)
//
// We can safely acquire the stack pointer to the caller's and callee's (host)
// call frames because we just allocated the host call frame and can be sure that
// they are different.
// In the following we make sure to not access registers out of bounds of each
// call frame since we rely on Wasm validation and proper Wasm translation to
// provide us with valid result registers.
unsafe { self.sp.set(result, *value) };
}
Ok(ControlFlow::Continue(()))
}
CallKind::Tail => {
let (mut regs, cf) = match self.stack.calls.peek() {
Some(frame) => {
// Case: return the caller's caller frame registers.
let sp = unsafe { self.stack.values.stack_ptr_at(frame.base_offset()) };
(sp, ControlFlow::Continue(()))
}
None => {
// Case: call stack is empty -> return the root frame registers.
let sp = self.stack.values.root_stack_ptr();
(sp, ControlFlow::Break(()))
}
};
let returned = self.stack.values.drop_return(max_inout);
for (result, value) in results.zip(returned) {
// # Safety (1)
//
// We can safely acquire the stack pointer to the caller's and callee's (host)
// call frames because we just allocated the host call frame and can be sure that
// they are different.
// In the following we make sure to not access registers out of bounds of each
// call frame since we rely on Wasm validation and proper Wasm translation to
// provide us with valid result registers.
unsafe { regs.set(result, *value) };
}
self.stack.values.truncate(caller.frame_offset());
let new_instance = popped_instance.and_then(|_| self.stack.calls.instance());
if let Some(new_instance) = new_instance {
self.cache.update(store.inner_mut(), new_instance);
}
if let Some(caller) = self.stack.calls.peek() {
Self::init_call_frame_impl(
&mut self.stack.values,
&mut self.sp,
&mut self.ip,
caller,
);
}
Ok(cf)
}
}
}
|
Executes a host function.
# Note
This uses the value stack to store parameters and results of the host function call.
Returns an [`ErrorKind::ResumableHostTrap`] variant if the host function returned an error
and there are still call frames on the call stack making it possible to resume the
execution at a later point in time.
[`ErrorKind::ResumableHostTrap`]: crate::error::ErrorKind::ResumableHostTrap
|
execute_host_func
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
fn execute_call_indirect_impl<C: CallContext>(
&mut self,
store: &mut PrunedStore,
results: Option<RegSpan>,
func_type: index::FuncType,
index: u64,
table: index::Table,
) -> Result<ControlFlow, Error> {
let table = self.get_table(table);
let funcref = store
.inner()
.resolve_table(&table)
.get_untyped(index)
.map(FuncRef::from)
.ok_or(TrapCode::TableOutOfBounds)?;
let func = funcref.func().ok_or(TrapCode::IndirectCallToNull)?;
let actual_signature = store.inner().resolve_func(func).ty_dedup();
let expected_signature = &self.get_func_type_dedup(func_type);
if actual_signature != expected_signature {
return Err(Error::from(TrapCode::BadSignature));
}
self.execute_call_imported_impl::<C>(store, results, func)
}
|
Executes an [`Instruction::CallIndirect`] and [`Instruction::CallIndirect0`].
|
execute_call_indirect_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/call.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/call.rs
|
Apache-2.0
|
pub fn execute_copy_span(&mut self, results: RegSpan, values: RegSpan, len: u16) {
self.execute_copy_span_impl(results, values, len);
self.next_instr();
}
|
Executes an [`Instruction::CopySpan`].
# Note
- This instruction assumes that `results` and `values` _do_ overlap
and thus requires a costly temporary buffer to avoid overwriting
intermediate copy results.
- If `results` and `values` do _not_ overlap [`Instruction::CopySpanNonOverlapping`] is used.
|
execute_copy_span
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/copy.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/copy.rs
|
Apache-2.0
|
pub fn execute_copy_span_impl(&mut self, results: RegSpan, values: RegSpan, len: u16) {
let results = results.iter(len);
let values = values.iter(len);
let mut tmp = <SmallVec<[UntypedVal; 8]>>::default();
tmp.extend(values.into_iter().map(|value| self.get_register(value)));
for (result, value) in results.into_iter().zip(tmp) {
self.set_register(result, value);
}
}
|
Internal implementation of [`Instruction::CopySpan`] execution.
|
execute_copy_span_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/copy.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/copy.rs
|
Apache-2.0
|
pub fn execute_copy_span_non_overlapping(
&mut self,
results: RegSpan,
values: RegSpan,
len: u16,
) {
self.execute_copy_span_non_overlapping_impl(results, values, len);
self.next_instr();
}
|
Executes an [`Instruction::CopySpanNonOverlapping`].
# Note
- This instruction assumes that `results` and `values` do _not_ overlap
and thus can copy all the elements without a costly temporary buffer.
- If `results` and `values` _do_ overlap [`Instruction::CopySpan`] is used.
|
execute_copy_span_non_overlapping
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/copy.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/copy.rs
|
Apache-2.0
|
pub fn execute_copy_span_non_overlapping_impl(
&mut self,
results: RegSpan,
values: RegSpan,
len: u16,
) {
let results = results.iter(len);
let values = values.iter(len);
for (result, value) in results.into_iter().zip(values.into_iter()) {
let value = self.get_register(value);
self.set_register(result, value);
}
}
|
Internal implementation of [`Instruction::CopySpanNonOverlapping`] execution.
|
execute_copy_span_non_overlapping_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/copy.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/copy.rs
|
Apache-2.0
|
pub fn execute_copy_many_impl(
&mut self,
ip: InstructionPtr,
results: RegSpan,
values: &[Reg],
) -> InstructionPtr {
// We need `tmp` since `values[n]` might be overwritten by previous copies.
let mut tmp = <SmallVec<[UntypedVal; 8]>>::default();
let mut ip = ip;
tmp.extend(values.iter().map(|value| self.get_register(*value)));
while let Instruction::RegisterList { regs } = ip.get() {
tmp.extend(regs.iter().map(|value| self.get_register(*value)));
ip.add(1);
}
let values = match ip.get() {
Instruction::Register { reg } => slice::from_ref(reg),
Instruction::Register2 { regs } => regs,
Instruction::Register3 { regs } => regs,
unexpected => {
// Safety: Wasmi translator guarantees that register-list finalizer exists.
unsafe {
unreachable_unchecked!(
"expected register-list finalizer but found: {unexpected:?}"
)
}
}
};
tmp.extend(values.iter().map(|value| self.get_register(*value)));
for (result, value) in results.iter_sized(tmp.len()).zip(tmp) {
self.set_register(result, value);
}
ip
}
|
Internal implementation of [`Instruction::CopyMany`] execution.
|
execute_copy_many_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/copy.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/copy.rs
|
Apache-2.0
|
pub fn execute_copy_many_non_overlapping_impl(
&mut self,
ip: InstructionPtr,
results: RegSpan,
values: &[Reg],
) -> InstructionPtr {
let mut ip = ip;
let mut result = results.head();
let mut copy_values = |values: &[Reg]| {
for &value in values {
let value = self.get_register(value);
self.set_register(result, value);
result = result.next();
}
};
copy_values(values);
while let Instruction::RegisterList { regs } = ip.get() {
copy_values(regs);
ip.add(1);
}
let values = match ip.get() {
Instruction::Register { reg } => slice::from_ref(reg),
Instruction::Register2 { regs } => regs,
Instruction::Register3 { regs } => regs,
unexpected => {
// Safety: Wasmi translator guarantees that register-list finalizer exists.
unsafe {
unreachable_unchecked!(
"expected register-list finalizer but found: {unexpected:?}"
)
}
}
};
copy_values(values);
ip
}
|
Internal implementation of [`Instruction::CopyManyNonOverlapping`] execution.
|
execute_copy_many_non_overlapping_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/copy.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/copy.rs
|
Apache-2.0
|
fn fetch_ptr_and_offset_hi(&self) -> (Reg, Offset64Hi) {
// Safety: Wasmi translation guarantees that `Instruction::RegisterAndImm32` exists.
unsafe { self.fetch_reg_and_offset_hi() }
}
|
Returns the register `value` and `offset` parameters for a `load` [`Instruction`].
|
fetch_ptr_and_offset_hi
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/load.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/load.rs
|
Apache-2.0
|
fn execute_load_extend<T>(
&mut self,
store: &StoreInner,
memory: Memory,
result: Reg,
address: u64,
offset: Offset64,
load_extend: WasmLoadOp<T>,
) -> Result<(), Error>
where
UntypedVal: WriteAs<T>,
{
let memory = self.fetch_memory_bytes(memory, store);
let loaded_value = load_extend(memory, address, u64::from(offset))?;
self.set_register_as::<T>(result, loaded_value);
Ok(())
}
|
Executes a generic Wasm `load[N_{s|u}]` operation.
# Note
This can be used to emulate the following Wasm operands:
- `{i32, i64, f32, f64}.load`
- `{i32, i64}.load8_s`
- `{i32, i64}.load8_u`
- `{i32, i64}.load16_s`
- `{i32, i64}.load16_u`
- `i64.load32_s`
- `i64.load32_u`
|
execute_load_extend
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/load.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/load.rs
|
Apache-2.0
|
fn execute_load_extend_at<T>(
&mut self,
store: &StoreInner,
memory: Memory,
result: Reg,
address: Address32,
load_extend_at: WasmLoadAtOp<T>,
) -> Result<(), Error>
where
UntypedVal: WriteAs<T>,
{
let memory = self.fetch_memory_bytes(memory, store);
let loaded_value = load_extend_at(memory, usize::from(address))?;
self.set_register_as::<T>(result, loaded_value);
Ok(())
}
|
Executes a generic Wasm `load[N_{s|u}]` operation.
# Note
This can be used to emulate the following Wasm operands:
- `{i32, i64, f32, f64}.load`
- `{i32, i64}.load8_s`
- `{i32, i64}.load8_u`
- `{i32, i64}.load16_s`
- `{i32, i64}.load16_u`
- `i64.load32_s`
- `i64.load32_u`
|
execute_load_extend_at
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/load.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/load.rs
|
Apache-2.0
|
fn execute_load_extend_mem0<T>(
&mut self,
result: Reg,
address: u64,
offset: Offset64,
load_extend: WasmLoadOp<T>,
) -> Result<(), Error>
where
UntypedVal: WriteAs<T>,
{
let memory = self.fetch_default_memory_bytes();
let loaded_value = load_extend(memory, address, u64::from(offset))?;
self.set_register_as::<T>(result, loaded_value);
Ok(())
}
|
Executes a generic Wasm `store[N_{s|u}]` operation on the default memory.
# Note
This can be used to emulate the following Wasm operands:
- `{i32, i64, f32, f64}.load`
- `{i32, i64}.load8_s`
- `{i32, i64}.load8_u`
- `{i32, i64}.load16_s`
- `{i32, i64}.load16_u`
- `i64.load32_s`
- `i64.load32_u`
|
execute_load_extend_mem0
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/load.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/load.rs
|
Apache-2.0
|
fn fetch_memory_index(&self, offset: usize) -> Memory {
let mut addr: InstructionPtr = self.ip;
addr.add(offset);
match *addr.get() {
Instruction::MemoryIndex { index } => index,
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::MemoryIndex`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::MemoryIndex` but found: {unexpected:?}"
)
}
}
}
}
|
Returns the [`Instruction::MemoryIndex`] parameter for an [`Instruction`].
|
fetch_memory_index
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/memory.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/memory.rs
|
Apache-2.0
|
fn fetch_data_segment_index(&self, offset: usize) -> Data {
let mut addr: InstructionPtr = self.ip;
addr.add(offset);
match *addr.get() {
Instruction::DataIndex { index } => index,
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::DataIndex`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::DataIndex` but found: {unexpected:?}"
)
}
}
}
}
|
Returns the [`Instruction::DataIndex`] parameter for an [`Instruction`].
|
fetch_data_segment_index
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/memory.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/memory.rs
|
Apache-2.0
|
fn return_impl(&mut self, store: &mut StoreInner) -> ControlFlow {
let (returned, popped_instance) = self
.stack
.calls
.pop()
.expect("the executing call frame is always on the stack");
self.stack.values.truncate(returned.frame_offset());
let new_instance = popped_instance.and_then(|_| self.stack.calls.instance());
if let Some(new_instance) = new_instance {
self.cache.update(store, new_instance);
}
match self.stack.calls.peek() {
Some(caller) => {
Self::init_call_frame_impl(
&mut self.stack.values,
&mut self.sp,
&mut self.ip,
caller,
);
ControlFlow::Continue(())
}
None => ControlFlow::Break(()),
}
}
|
Returns the execution to the caller.
Any return values are expected to already have been transferred
from the returning callee to the caller.
|
return_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
fn return_caller_results(&mut self) -> (FrameRegisters, RegSpan) {
let (callee, caller) = self
.stack
.calls
.peek_2()
.expect("the callee must exist on the call stack");
match caller {
Some(caller) => {
// Case: we need to return the `value` back to the caller frame.
//
// In this case we transfer the single return `value` to the `results`
// register span of the caller's call frame.
//
// Safety: The caller call frame is still live on the value stack
// and therefore it is safe to acquire its value stack pointer.
let caller_sp = unsafe { self.stack.values.stack_ptr_at(caller.base_offset()) };
let results = callee.results();
(caller_sp, results)
}
None => {
// Case: the root call frame is returning.
//
// In this case we transfer the single return `value` to the root
// register span of the entire value stack which is simply its zero index.
let dst_sp = self.stack.values.root_stack_ptr();
let results = RegSpan::new(Reg::from(0));
(dst_sp, results)
}
}
}
|
Returns the [`FrameRegisters`] of the caller and the [`RegSpan`] of the results.
The returned [`FrameRegisters`] is valid for all [`Reg`] in the returned [`RegSpan`].
|
return_caller_results
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
fn execute_return_value<T>(
&mut self,
store: &mut StoreInner,
value: T,
f: fn(&Self, T) -> UntypedVal,
) -> ControlFlow {
let (mut caller_sp, results) = self.return_caller_results();
let value = f(self, value);
// Safety: The `callee.results()` always refer to a span of valid
// registers of the `caller` that does not overlap with the
// registers of the callee since they reside in different
// call frames. Therefore this access is safe.
unsafe { caller_sp.set(results.head(), value) }
self.return_impl(store)
}
|
Execute a generic return [`Instruction`] returning a single value.
|
execute_return_value
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn execute_return_reg(&mut self, store: &mut StoreInner, value: Reg) -> ControlFlow {
self.execute_return_value(store, value, Self::get_register)
}
|
Execute an [`Instruction::ReturnReg`] returning a single [`Reg`] value.
|
execute_return_reg
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn execute_return_reg2(&mut self, store: &mut StoreInner, values: [Reg; 2]) -> ControlFlow {
self.execute_return_reg_n_impl::<2>(store, values)
}
|
Execute an [`Instruction::ReturnReg2`] returning two [`Reg`] values.
|
execute_return_reg2
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn execute_return_reg3(&mut self, store: &mut StoreInner, values: [Reg; 3]) -> ControlFlow {
self.execute_return_reg_n_impl::<3>(store, values)
}
|
Execute an [`Instruction::ReturnReg3`] returning three [`Reg`] values.
|
execute_return_reg3
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
fn execute_return_reg_n_impl<const N: usize>(
&mut self,
store: &mut StoreInner,
values: [Reg; N],
) -> ControlFlow {
let (mut caller_sp, results) = self.return_caller_results();
debug_assert!(u16::try_from(N).is_ok());
for (result, value) in results.iter(N as u16).zip(values) {
let value = self.get_register(value);
// Safety: The `callee.results()` always refer to a span of valid
// registers of the `caller` that does not overlap with the
// registers of the callee since they reside in different
// call frames. Therefore this access is safe.
unsafe { caller_sp.set(result, value) }
}
self.return_impl(store)
}
|
Executes an [`Instruction::ReturnReg2`] or [`Instruction::ReturnReg3`] generically.
|
execute_return_reg_n_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn execute_return_imm32(
&mut self,
store: &mut StoreInner,
value: AnyConst32,
) -> ControlFlow {
self.execute_return_value(store, value, |_, value| u32::from(value).into())
}
|
Execute an [`Instruction::ReturnImm32`] returning a single 32-bit value.
|
execute_return_imm32
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn execute_return_i64imm32(
&mut self,
store: &mut StoreInner,
value: Const32<i64>,
) -> ControlFlow {
self.execute_return_value(store, value, |_, value| i64::from(value).into())
}
|
Execute an [`Instruction::ReturnI64Imm32`] returning a single 32-bit encoded `i64` value.
|
execute_return_i64imm32
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn execute_return_f64imm32(
&mut self,
store: &mut StoreInner,
value: Const32<f64>,
) -> ControlFlow {
self.execute_return_value(store, value, |_, value| f64::from(value).into())
}
|
Execute an [`Instruction::ReturnF64Imm32`] returning a single 32-bit encoded `f64` value.
|
execute_return_f64imm32
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn execute_return_span(
&mut self,
store: &mut StoreInner,
values: BoundedRegSpan,
) -> ControlFlow {
let (mut caller_sp, results) = self.return_caller_results();
let results = results.iter(values.len());
for (result, value) in results.zip(values) {
// Safety: The `callee.results()` always refer to a span of valid
// registers of the `caller` that does not overlap with the
// registers of the callee since they reside in different
// call frames. Therefore this access is safe.
let value = self.get_register(value);
unsafe { caller_sp.set(result, value) }
}
self.return_impl(store)
}
|
Execute an [`Instruction::ReturnSpan`] returning many values.
|
execute_return_span
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn execute_return_many(&mut self, store: &mut StoreInner, values: [Reg; 3]) -> ControlFlow {
self.ip.add(1);
self.copy_many_return_values(self.ip, &values);
self.return_impl(store)
}
|
Execute an [`Instruction::ReturnMany`] returning many values.
|
execute_return_many
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
pub fn copy_many_return_values(&mut self, ip: InstructionPtr, values: &[Reg]) {
let (mut caller_sp, results) = self.return_caller_results();
let mut result = results.head();
let mut copy_results = |values: &[Reg]| {
for value in values {
let value = self.get_register(*value);
// Safety: The `callee.results()` always refer to a span of valid
// registers of the `caller` that does not overlap with the
// registers of the callee since they reside in different
// call frames. Therefore this access is safe.
unsafe { caller_sp.set(result, value) }
result = result.next();
}
};
copy_results(values);
let mut ip = ip;
while let Instruction::RegisterList { regs } = ip.get() {
copy_results(regs);
ip.add(1);
}
let values = match ip.get() {
Instruction::Register { reg } => slice::from_ref(reg),
Instruction::Register2 { regs } => regs,
Instruction::Register3 { regs } => regs,
unexpected => {
// Safety: Wasmi translation guarantees that a register-list finalizer exists.
unsafe {
unreachable_unchecked!(
"unexpected register-list finalizer but found: {unexpected:?}"
)
}
}
};
copy_results(values);
}
|
Copies many return values to the caller frame.
# Note
Used by the execution logic for
- [`Instruction::ReturnMany`]
- [`Instruction::BranchTableMany`]
|
copy_many_return_values
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/return_.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/return_.rs
|
Apache-2.0
|
fn fetch_register(&self) -> Reg {
let mut addr: InstructionPtr = self.ip;
addr.add(1);
match *addr.get() {
Instruction::Register { reg } => reg,
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::Register`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::Register` but found {unexpected:?}"
)
}
}
}
}
|
Fetches a [`Reg`] from an [`Instruction::Register`] instruction parameter.
|
fetch_register
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/simd.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/simd.rs
|
Apache-2.0
|
unsafe fn fetch_reg_and_lane<LaneType>(&self, delta: usize) -> (Reg, LaneType)
where
LaneType: TryFrom<u8>,
{
let mut addr: InstructionPtr = self.ip;
addr.add(delta);
match addr.get().filter_register_and_lane::<LaneType>() {
Ok(value) => value,
Err(instr) => unsafe {
unreachable_unchecked!(
"expected an `Instruction::RegisterAndImm32` but found: {instr:?}"
)
},
}
}
|
Fetches the [`Reg`] and [`Offset64Hi`] parameters for a load or store [`Instruction`].
|
fetch_reg_and_lane
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/simd.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/simd.rs
|
Apache-2.0
|
pub fn fetch_value_and_lane<LaneType>(&self, delta: usize) -> (Reg, LaneType)
where
LaneType: TryFrom<u8>,
{
// Safety: Wasmi translation guarantees that `Instruction::RegisterAndImm32` exists.
unsafe { self.fetch_reg_and_lane::<LaneType>(delta) }
}
|
Returns the register `value` and `lane` parameters for a `load` [`Instruction`].
|
fetch_value_and_lane
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/simd.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/simd.rs
|
Apache-2.0
|
fn fetch_const32_as<T>(&self) -> T
where
T: From<AnyConst32>,
{
let mut addr: InstructionPtr = self.ip;
addr.add(1);
match *addr.get() {
Instruction::Const32 { value } => value.into(),
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::Const32`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::Const32` but found {unexpected:?}"
)
}
}
}
}
|
Fetches a [`Reg`] from an [`Instruction::Const32`] instruction parameter.
|
fetch_const32_as
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/simd.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/simd.rs
|
Apache-2.0
|
fn fetch_i64const32(&self) -> i64 {
let mut addr: InstructionPtr = self.ip;
addr.add(1);
match *addr.get() {
Instruction::I64Const32 { value } => value.into(),
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::I64Const32`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::I64Const32` but found {unexpected:?}"
)
}
}
}
}
|
Fetches a [`Reg`] from an [`Instruction::I64Const32`] instruction parameter.
|
fetch_i64const32
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/simd.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/simd.rs
|
Apache-2.0
|
fn fetch_f64const32(&self) -> f64 {
let mut addr: InstructionPtr = self.ip;
addr.add(1);
match *addr.get() {
Instruction::F64Const32 { value } => value.into(),
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::F64Const32`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::F64Const32` but found {unexpected:?}"
)
}
}
}
}
|
Fetches a [`Reg`] from an [`Instruction::F64Const32`] instruction parameter.
|
fetch_f64const32
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/simd.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/simd.rs
|
Apache-2.0
|
fn execute_replace_lane_impl<T, LaneType>(
&mut self,
result: Reg,
input: Reg,
lane: LaneType,
value: T,
delta: usize,
eval: fn(V128, LaneType, T) -> V128,
) {
let input = self.get_register_as::<V128>(input);
self.set_register_as::<V128>(result, eval(input, lane, value));
self.next_instr_at(delta);
}
|
Generically execute a SIMD replace lane instruction.
|
execute_replace_lane_impl
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/simd.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/simd.rs
|
Apache-2.0
|
fn fetch_value_and_offset_imm<T>(&self) -> (T, Offset64Hi)
where
T: From<AnyConst16>,
{
let mut addr: InstructionPtr = self.ip;
addr.add(1);
match addr.get().filter_imm16_and_offset_hi::<T>() {
Ok(value) => value,
Err(instr) => unsafe {
unreachable_unchecked!(
"expected an `Instruction::RegisterAndImm32` but found: {instr:?}"
)
},
}
}
|
Returns the immediate `value` and `offset_hi` parameters for a `load` [`Instruction`].
|
fetch_value_and_offset_imm
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/store.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/store.rs
|
Apache-2.0
|
pub(super) fn execute_store_wrap<T>(
&mut self,
store: &mut StoreInner,
memory: Memory,
address: u64,
offset: Offset64,
value: T,
store_wrap: WasmStoreOp<T>,
) -> Result<(), Error>
where
UntypedVal: ReadAs<T>,
{
let memory = self.fetch_memory_bytes_mut(memory, store);
store_wrap(memory, address, u64::from(offset), value)?;
Ok(())
}
|
Executes a generic Wasm `store[N]` operation.
# Note
This can be used to emulate the following Wasm operands:
- `{i32, i64, f32, f64}.store`
- `{i32, i64}.store8`
- `{i32, i64}.store16`
- `i64.store32`
|
execute_store_wrap
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/store.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/store.rs
|
Apache-2.0
|
fn execute_store_wrap_at<T>(
&mut self,
store: &mut StoreInner,
memory: Memory,
address: Address32,
value: T,
store_wrap_at: WasmStoreAtOp<T>,
) -> Result<(), Error> {
let memory = self.fetch_memory_bytes_mut(memory, store);
store_wrap_at(memory, usize::from(address), value)?;
Ok(())
}
|
Executes a generic Wasm `store[N]` operation.
# Note
This can be used to emulate the following Wasm operands:
- `{i32, i64, f32, f64}.store`
- `{i32, i64}.store8`
- `{i32, i64}.store16`
- `i64.store32`
|
execute_store_wrap_at
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/store.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/store.rs
|
Apache-2.0
|
fn execute_store_wrap_mem0<T>(
&mut self,
address: u64,
offset: Offset64,
value: T,
store_wrap: WasmStoreOp<T>,
) -> Result<(), Error>
where
UntypedVal: ReadAs<T>,
{
let memory = self.fetch_default_memory_bytes_mut();
store_wrap(memory, address, u64::from(offset), value)?;
Ok(())
}
|
Executes a generic Wasm `store[N]` operation for the default memory.
# Note
This can be used to emulate the following Wasm operands:
- `{i32, i64, f32, f64}.store`
- `{i32, i64}.store8`
- `{i32, i64}.store16`
- `i64.store32`
|
execute_store_wrap_mem0
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/store.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/store.rs
|
Apache-2.0
|
fn fetch_table_index(&self, offset: usize) -> Table {
let mut addr: InstructionPtr = self.ip;
addr.add(offset);
match *addr.get() {
Instruction::TableIndex { index } => index,
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::TableIndex`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::TableIndex` but found: {unexpected:?}"
)
}
}
}
}
|
Returns the [`Instruction::TableIndex`] parameter for an [`Instruction`].
|
fetch_table_index
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/table.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/table.rs
|
Apache-2.0
|
fn fetch_element_segment_index(&self, offset: usize) -> Elem {
let mut addr: InstructionPtr = self.ip;
addr.add(offset);
match *addr.get() {
Instruction::ElemIndex { index } => index,
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::ElemIndex`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::ElemIndex` but found: {unexpected:?}"
)
}
}
}
}
|
Returns the [`Instruction::ElemIndex`] parameter for an [`Instruction`].
|
fetch_element_segment_index
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/table.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/table.rs
|
Apache-2.0
|
pub fn fetch_value_and_offset_hi(&self) -> (Reg, Offset64Hi) {
// Safety: Wasmi translation guarantees that `Instruction::RegisterAndImm32` exists.
unsafe { self.fetch_reg_and_offset_hi() }
}
|
Returns the register `value` and `offset` parameters for a `load` [`Instruction`].
|
fetch_value_and_offset_hi
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/utils.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/utils.rs
|
Apache-2.0
|
pub fn fetch_default_memory_bytes(&self) -> &[u8] {
// Safety: the `self.cache.memory` pointer is always synchronized
// conservatively whenever it could have been invalidated.
unsafe { self.cache.memory.data() }
}
|
Fetches the bytes of the default memory at index 0.
|
fetch_default_memory_bytes
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/utils.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/utils.rs
|
Apache-2.0
|
pub fn fetch_memory_bytes<'exec, 'store, 'bytes>(
&'exec self,
memory: Memory,
store: &'store StoreInner,
) -> &'bytes [u8]
where
'exec: 'bytes,
'store: 'bytes,
{
match memory.is_default() {
true => self.fetch_default_memory_bytes(),
false => self.fetch_non_default_memory_bytes(memory, store),
}
}
|
Fetches the bytes of the given `memory`.
|
fetch_memory_bytes
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/utils.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/utils.rs
|
Apache-2.0
|
fn fetch_params128(&self) -> Params128 {
let mut addr: InstructionPtr = self.ip;
addr.add(1);
match *addr.get() {
Instruction::Register3 { regs } => Params128 {
lhs_hi: regs[0],
rhs_lo: regs[1],
rhs_hi: regs[2],
},
unexpected => {
// Safety: Wasmi translation guarantees that [`Instruction::MemoryIndex`] exists.
unsafe {
unreachable_unchecked!(
"expected `Instruction::Register3` but found: {unexpected:?}"
)
}
}
}
}
|
Fetches the parameters required by the `i64.add128` and `i64.sub128` instructions.
|
fetch_params128
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/instrs/wide_arithmetic.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/instrs/wide_arithmetic.rs
|
Apache-2.0
|
pub fn peek_2(&self) -> Option<(&CallFrame, Option<&CallFrame>)> {
let (callee, remaining) = self.frames.split_last()?;
let caller = remaining.last();
Some((callee, caller))
}
|
Peeks the two top-most [`CallFrame`] on the [`CallStack`] if any.
# Note
- The top-most [`CallFrame`] on the [`CallStack`] is referred to as the `callee`.
- The second top-most [`CallFrame`] on the [`CallStack`] is referred to as the `caller`.
So this function returns a pair of `(callee, caller?)`.
|
peek_2
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/calls.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/calls.rs
|
Apache-2.0
|
pub fn update_instr_ptr(&mut self, new_instr_ptr: InstructionPtr) {
self.instr_ptr = new_instr_ptr;
}
|
Updates the [`InstructionPtr`] of the [`CallFrame`].
This is required before dispatching a nested function call to update
the instruction pointer of the caller so that it can continue at that
position when the called function returns.
|
update_instr_ptr
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/calls.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/calls.rs
|
Apache-2.0
|
pub fn new(limits: StackLimits) -> Self {
let calls = CallStack::new(limits.maximum_recursion_depth);
let values = ValueStack::new(
limits.initial_value_stack_height,
limits.maximum_value_stack_height,
);
Self { calls, values }
}
|
Creates a new [`Stack`] given the [`Config`].
[`Config`]: [`crate::Config`]
|
new
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/mod.rs
|
Apache-2.0
|
pub fn reset(&mut self) {
self.calls.reset();
self.values.reset();
}
|
Resets the [`Stack`] for clean reuse.
|
reset
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/mod.rs
|
Apache-2.0
|
pub fn empty() -> Self {
Self {
values: ValueStack::empty(),
calls: CallStack::default(),
}
}
|
Create an empty [`Stack`].
# Note
Empty stacks require no heap allocations and are cheap to construct.
|
empty
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/mod.rs
|
Apache-2.0
|
pub fn new(initial_len: usize, maximum_len: usize) -> Self {
assert!(
initial_len > 0,
"cannot initialize the value stack with zero length",
);
assert!(
initial_len <= maximum_len,
"initial value stack length is greater than maximum value stack length",
);
Self {
values: Vec::with_capacity(initial_len),
max_len: maximum_len,
}
}
|
Creates a new empty [`ValueStack`].
# Panics
- If the `initial_len` is zero.
- If the `initial_len` is greater than `maximum_len`.
|
new
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
pub fn empty() -> Self {
Self {
values: Vec::new(),
max_len: 0,
}
}
|
Creates an empty [`ValueStack`] that does not allocate heap memory.
# Note
This is required for resumable functions in order to replace their
proper stack with a cheap dummy one.
|
empty
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
pub unsafe fn stack_ptr_at(&mut self, offset: impl Into<ValueStackOffset>) -> FrameRegisters {
let ptr = self.values.as_mut_ptr().add(offset.into().0);
FrameRegisters::new(ptr)
}
|
Returns the [`FrameRegisters`] at the given `offset`.
|
stack_ptr_at
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
pub fn capacity(&self) -> usize {
debug_assert!(self.values.len() <= self.values.capacity());
self.values.capacity()
}
|
Returns the capacity of the [`ValueStack`].
|
capacity
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
pub unsafe fn init_next(&mut self, value: UntypedVal) {
self.range.start.write(MaybeUninit::new(value));
self.range.start = self.range.start.add(1);
}
|
Sets the value of the `register` to `value`.`
# Safety
It is the callers responsibility to provide a [`Reg`] that
does not access the underlying [`ValueStack`] out of bounds.
|
init_next
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
pub fn init_zeroes(mut self) {
debug_assert!(self.range.start <= self.range.end);
while !core::ptr::eq(self.range.start, self.range.end) {
// Safety: We do not write out-of-buffer due to the above condition.
unsafe { self.init_next(UntypedVal::from(0_u64)) }
}
}
|
Zero-initialize the remaining locals and parameters.
|
init_zeroes
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
pub unsafe fn read_as<T>(&self, register: Reg) -> T
where
UntypedVal: ReadAs<T>,
{
UntypedVal::read_as(&*self.register_offset(register))
}
|
Returns the [`UntypedVal`] at the given [`Reg`].
# Safety
It is the callers responsibility to provide a [`Reg`] that
does not access the underlying [`ValueStack`] out of bounds.
|
read_as
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
pub unsafe fn set(&mut self, register: Reg, value: UntypedVal) {
ptr::write(self.register_offset(register), value)
}
|
Sets the value of the `register` to `value`.`
# Safety
It is the callers responsibility to provide a [`Reg`] that
does not access the underlying [`ValueStack`] out of bounds.
|
set
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
pub unsafe fn write_as<T>(&mut self, register: Reg, value: T)
where
UntypedVal: WriteAs<T>,
{
let val: &mut UntypedVal = &mut *self.register_offset(register);
val.write_as(value);
}
|
Sets the value of the `register` to `value`.`
# Safety
It is the callers responsibility to provide a [`Reg`] that
does not access the underlying [`ValueStack`] out of bounds.
|
write_as
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
unsafe fn register_offset(&self, register: Reg) -> *mut UntypedVal {
unsafe { self.ptr.offset(isize::from(i16::from(register))) }
}
|
Returns the underlying pointer offset by the [`Reg`] index.
|
register_offset
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/executor/stack/values.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/executor/stack/values.rs
|
Apache-2.0
|
fn setup_store() -> Store<i32> {
let config = Config::default();
let engine = Engine::new(&config);
Store::new(&engine, 5_i32)
}
|
Setup a new `Store` for testing with initial value of 5.
|
setup_store
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/tests/host_calls.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/tests/host_calls.rs
|
Apache-2.0
|
fn setup_test(wasm: &str) -> (Store<()>, Func) {
let engine = Engine::default();
let mut store = <Store<()>>::new(&engine, ());
let linker = <Linker<()>>::new(&engine);
let module = Module::new(&engine, wasm).unwrap();
let instance = linker
.instantiate(&mut store, &module)
.unwrap()
.ensure_no_start(&mut store)
.unwrap();
let func = instance.get_func(&store, "test").unwrap();
(store, func)
}
|
Common routine to setup the tests.
|
setup_test
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/tests/many_inout.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/tests/many_inout.rs
|
Apache-2.0
|
pub(crate) fn resolve_instr(
&self,
func: EngineFunc,
index: usize,
) -> Result<Option<Instruction>, Error> {
self.inner.resolve_instr(func, index)
}
|
Resolves the [`EngineFunc`] to the underlying Wasmi bytecode instructions.
# Note
- This is a variant of [`Engine::resolve_instr`] that returns register
machine based bytecode instructions.
- This API is mainly intended for unit testing purposes and shall not be used
outside of this context. The function bodies are intended to be data private
to the Wasmi interpreter.
# Errors
If the `func` fails Wasm to Wasmi bytecode translation after it was lazily initialized.
# Panics
- If the [`EngineFunc`] is invalid for the [`Engine`].
- If register machine bytecode translation is disabled.
|
resolve_instr
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/tests/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/tests/mod.rs
|
Apache-2.0
|
pub(crate) fn get_func_const(
&self,
func: EngineFunc,
index: usize,
) -> Result<Option<UntypedVal>, Error> {
self.inner.get_func_const(func, index)
}
|
Resolves the function local constant of [`EngineFunc`] at `index` if any.
# Note
This API is intended for unit testing purposes and shall not be used
outside of this context. The function bodies are intended to be data
private to the Wasmi interpreter.
# Errors
If the `func` fails Wasm to Wasmi bytecode translation after it was lazily initialized.
# Panics
- If the [`EngineFunc`] is invalid for the [`Engine`].
- If register machine bytecode translation is disabled.
|
get_func_const
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/tests/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/tests/mod.rs
|
Apache-2.0
|
pub(crate) fn resolve_func<'a, F, R>(&'a self, func: EngineFunc, f: F) -> Result<R, Error>
where
F: FnOnce(CompiledFuncRef<'a>) -> R,
{
// Note: We use `None` so this test-only function will never charge for compilation fuel.
Ok(f(self.code_map.get(None, func)?))
}
|
Resolves the [`InternalFuncEntity`] for [`EngineFunc`] and applies `f` to it.
# Panics
If [`EngineFunc`] is invalid for [`Engine`].
|
resolve_func
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/tests/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/tests/mod.rs
|
Apache-2.0
|
pub(crate) fn resolve_instr(
&self,
func: EngineFunc,
index: usize,
) -> Result<Option<Instruction>, Error> {
self.resolve_func(func, |func| func.instrs().get(index).copied())
}
|
Returns the [`Instruction`] of `func` at `index`.
Returns `None` if the function has no instruction at `index`.
# Errors
If the `func` fails Wasm to Wasmi bytecode translation after it was lazily initialized.
# Pancis
If `func` cannot be resolved to a function for the [`EngineInner`].
|
resolve_instr
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/tests/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/tests/mod.rs
|
Apache-2.0
|
pub(crate) fn get_func_const(
&self,
func: EngineFunc,
index: usize,
) -> Result<Option<UntypedVal>, Error> {
// Function local constants are stored in reverse order of their indices since
// they are allocated in reverse order to their absolute indices during function
// translation. That is why we need to access them in reverse order.
self.resolve_func(func, |func| func.consts().iter().rev().nth(index).copied())
}
|
Returns the function local constant value of `func` at `index`.
Returns `None` if the function has no function local constant at `index`.
# Errors
If the `func` fails Wasm to Wasmi bytecode translation after it was lazily initialized.
# Pancis
If `func` cannot be resolved to a function for the [`EngineInner`].
|
get_func_const
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/tests/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/tests/mod.rs
|
Apache-2.0
|
pub fn new(
offset: impl Into<Option<usize>>,
bytes: &'parser [u8],
translator: T,
) -> Result<Self, Error> {
let offset = offset.into().unwrap_or(0);
let features = translator.features();
let reader = BinaryReader::new_features(bytes, offset, features);
let func_body = FunctionBody::new(reader);
Ok(Self {
func_body,
bytes,
translator,
})
}
|
Creates a new Wasm to Wasmi bytecode function translator.
|
new
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/driver.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/driver.rs
|
Apache-2.0
|
pub fn translate(
mut self,
finalize: impl FnOnce(CompiledFuncEntity),
) -> Result<T::Allocations, Error> {
if self.translator.setup(self.bytes)? {
let allocations = self.translator.finish(finalize)?;
return Ok(allocations);
}
self.translate_locals()?;
let offset = self.translate_operators()?;
let allocations = self.finish(offset, finalize)?;
Ok(allocations)
}
|
Starts translation of the Wasm stream into Wasmi bytecode.
|
translate
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/driver.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/driver.rs
|
Apache-2.0
|
fn finish(
mut self,
offset: usize,
finalize: impl FnOnce(CompiledFuncEntity),
) -> Result<T::Allocations, Error> {
self.translator.update_pos(offset);
self.translator.finish(finalize)
}
|
Finishes construction of the function and returns its reusable allocations.
|
finish
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/driver.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/driver.rs
|
Apache-2.0
|
fn translate_locals(&mut self) -> Result<(), Error> {
let mut reader = self.func_body.get_locals_reader()?;
let len_locals = reader.get_count();
for _ in 0..len_locals {
let offset = reader.original_position();
let (amount, value_type) = reader.read()?;
self.translator.update_pos(offset);
self.translator.translate_locals(amount, value_type)?;
}
self.translator.finish_translate_locals()?;
Ok(())
}
|
Translates local variables of the Wasm function.
|
translate_locals
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/driver.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/driver.rs
|
Apache-2.0
|
fn translate_operators(&mut self) -> Result<usize, Error> {
let mut reader = self.func_body.get_operators_reader()?;
while !reader.eof() {
let pos = reader.original_position();
self.translator.update_pos(pos);
reader.visit_operator(&mut self.translator)??;
}
reader.ensure_end()?;
Ok(reader.original_position())
}
|
Translates the Wasm operators of the Wasm function.
Returns the offset of the `End` Wasm operator.
|
translate_operators
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/driver.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/driver.rs
|
Apache-2.0
|
pub fn pin_label(&mut self, label: LabelRef, instr: Instr) -> Result<(), LabelError> {
match self.get_label_mut(label) {
Label::Pinned(pinned) => Err(LabelError::AlreadyPinned {
label,
pinned_to: *pinned,
}),
unpinned @ Label::Unpinned => {
*unpinned = Label::Pinned(instr);
Ok(())
}
}
}
|
Pins the `label` to the given `instr`.
# Errors
If the `label` has already been pinned to some other [`Instr`].
|
pin_label
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/labels.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/labels.rs
|
Apache-2.0
|
pub fn try_pin_label(&mut self, label: LabelRef, instr: Instr) {
if let unpinned @ Label::Unpinned = self.get_label_mut(label) {
*unpinned = Label::Pinned(instr)
}
}
|
Pins the `label` to the given `instr` if unpinned.
|
try_pin_label
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/labels.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/labels.rs
|
Apache-2.0
|
pub fn try_resolve_label(
&mut self,
label: LabelRef,
user: Instr,
) -> Result<BranchOffset, Error> {
let offset = match *self.get_label(label) {
Label::Pinned(target) => {
BranchOffset::from_src_to_dst(u32::from(user), u32::from(target))?
}
Label::Unpinned => {
self.users.push(LabelUser::new(label, user));
BranchOffset::uninit()
}
};
Ok(offset)
}
|
Tries to resolve the `label`.
Returns the proper `BranchOffset` in case the `label` has already been
pinned and returns an uninitialized `BranchOffset` otherwise.
In case the `label` has not yet been pinned the `user` is registered
for deferred label resolution.
|
try_resolve_label
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/labels.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/labels.rs
|
Apache-2.0
|
fn resolve_label(&self, label: LabelRef) -> Result<Instr, LabelError> {
match self.get_label(label) {
Label::Pinned(instr) => Ok(*instr),
Label::Unpinned => Err(LabelError::Unpinned { label }),
}
}
|
Resolves a `label` to its pinned [`Instr`].
# Errors
If the `label` is unpinned.
|
resolve_label
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/labels.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/labels.rs
|
Apache-2.0
|
pub fn resolved_users(&self) -> ResolvedUserIter {
ResolvedUserIter {
users: self.users.iter(),
registry: self,
}
}
|
Returns an iterator over pairs of user [`Instr`] and their [`BranchOffset`].
# Panics
If used before all used branching labels have been pinned.
|
resolved_users
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/labels.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/labels.rs
|
Apache-2.0
|
fn validate_then_translate<Validate, Translate>(
&mut self,
validate: Validate,
translate: Translate,
) -> Result<(), Error>
where
Validate: FnOnce(&mut FuncValidator) -> Result<(), BinaryReaderError>,
Translate: FnOnce(&mut T) -> Result<(), Error>,
{
validate(&mut self.validator)?;
translate(&mut self.translator)?;
Ok(())
}
|
Translates into Wasmi bytecode if the current code path is reachable.
|
validate_then_translate
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/mod.rs
|
Apache-2.0
|
pub fn is_checked(&self) -> bool {
matches!(self, Self::Checked(_))
}
|
Returns `true` if `self` performs validates Wasm upon lazy translation.
|
is_checked
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/mod.rs
|
Apache-2.0
|
pub fn features(&self) -> WasmFeatures {
match self {
Validation::Checked(func_to_validate) => func_to_validate.features,
Validation::Unchecked(wasm_features) => *wasm_features,
}
}
|
Returns the [`WasmFeatures`] used for Wasm parsing and validation.
|
features
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/mod.rs
|
Apache-2.0
|
pub fn take_func_to_validate(&mut self) -> Option<FuncToValidate<ValidatorResources>> {
let features = self.features();
match mem::replace(self, Self::Unchecked(features)) {
Self::Checked(func_to_validate) => Some(func_to_validate),
Self::Unchecked(_) => None,
}
}
|
Returns the [`FuncToValidate`] if `self` is checked.
|
take_func_to_validate
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/mod.rs
|
Apache-2.0
|
pub fn new_unchecked(
func_idx: FuncIdx,
engine_func: EngineFunc,
module: ModuleHeader,
features: WasmFeatures,
) -> Self {
Self {
func_idx,
engine_func,
module,
validation: Validation::Unchecked(features),
}
}
|
Create a new [`LazyFuncTranslator`] that does not validate Wasm upon lazy translation.
|
new_unchecked
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/mod.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/mod.rs
|
Apache-2.0
|
pub fn some(costs: FuelCostsProvider, instr: Instr) -> Self {
Self::Some { costs, instr }
}
|
Create a new [`FuelInfo`] for enabled fuel metering.
|
some
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/utils.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/utils.rs
|
Apache-2.0
|
pub fn into_usize(self) -> usize {
match usize::try_from(self.0) {
Ok(index) => index,
Err(error) => {
panic!("out of bound index {} for `Instr`: {error}", self.0)
}
}
}
|
Returns an `usize` representation of the instruction index.
|
into_usize
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/utils.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/utils.rs
|
Apache-2.0
|
pub fn new(engine: &Engine, height: usize, block_type: BlockType) -> Result<Self, Error> {
fn new_impl(engine: &Engine, height: usize, block_type: BlockType) -> Option<BlockHeight> {
let len_params = block_type.len_params(engine);
let height = u16::try_from(height).ok()?;
let block_height = height.checked_sub(len_params)?;
Some(BlockHeight(block_height))
}
new_impl(engine, height, block_type)
.ok_or(TranslationError::EmulatedValueStackOverflow)
.map_err(Error::from)
}
|
Creates a new [`BlockHeight`] for the given [`ValueStack`] `height` and [`BlockType`].
|
new
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/func/control_frame.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/func/control_frame.rs
|
Apache-2.0
|
fn branch_to(&mut self) {
self.is_branched_to = true;
}
|
Makes the [`BlockControlFrame`] aware that there is a branch to it.
|
branch_to
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/func/control_frame.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/func/control_frame.rs
|
Apache-2.0
|
fn branch_to(&mut self) {
self.is_branched_to = true;
}
|
Makes the [`BlockControlFrame`] aware that there is a branch to it.
|
branch_to
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/func/control_frame.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/func/control_frame.rs
|
Apache-2.0
|
pub fn both(else_label: LabelRef) -> Self {
Self::Both { else_label }
}
|
Creates an [`IfReachability`] when both `then` and `else` parts are reachable.
|
both
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/func/control_frame.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/func/control_frame.rs
|
Apache-2.0
|
pub fn branch_to(&mut self) {
self.is_branched_to = true;
}
|
Makes the [`IfControlFrame`] aware that there is a branch to it.
|
branch_to
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/func/control_frame.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/func/control_frame.rs
|
Apache-2.0
|
pub fn else_label(&self) -> Option<LabelRef> {
match self.reachability {
IfReachability::Both { else_label } => Some(else_label),
IfReachability::OnlyThen | IfReachability::OnlyElse => None,
}
}
|
Returns the label to the `else` branch of the [`IfControlFrame`].
|
else_label
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/func/control_frame.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/func/control_frame.rs
|
Apache-2.0
|
pub fn is_then_reachable(&self) -> bool {
match self.reachability {
IfReachability::Both { .. } | IfReachability::OnlyThen => true,
IfReachability::OnlyElse => false,
}
}
|
Returns `true` if the `then` branch is reachable.
# Note
The `then` branch is unreachable if the `if` condition is a constant `false` value.
|
is_then_reachable
|
rust
|
wasmi-labs/wasmi
|
crates/wasmi/src/engine/translator/func/control_frame.rs
|
https://github.com/wasmi-labs/wasmi/blob/master/crates/wasmi/src/engine/translator/func/control_frame.rs
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.