Struct wasm::execution::lut::Lut

source ·
pub struct Lut {
    function_lut: Vec<Vec<(usize, usize)>>,
}

Fields§

§function_lut: Vec<Vec<(usize, usize)>>

function_lut[local_module_idx][function_local_idx] = (foreign_module_idx, function_foreign_idx)

  • Module A imports a function “foo”. Inside module A, the function has the index “function_local_idx”. Module A is assigned the index “local_module_idx”.
  • Module B exports a function “foo”. Inside module B, the function has the index “function_foreign_idx”. Module B is assigned the index “foreign_module_idx”.

Implementations§

source§

impl Lut

source

pub fn new( modules: &[ExecutionInfo<'_>], module_map: &BTreeMap<String, usize> ) -> Option<Self>

Create a new linker lookup-table.

§Arguments
  • modules: The modules to link together.
  • module_map: A map from module name to module index within the modules array.
§Returns

A new linker lookup-table. Can return None if there are import directives that cannot be resolved.

source

pub fn lookup( &self, module_idx: usize, function_idx: usize ) -> Option<(usize, usize)>

Lookup a function by its module and function index.

§Arguments
  • module_idx: The index of the module within the modules array passed in Lut::new.
  • function_idx: The index of the function within the module. This index is considered in-bounds only if it is an index of an imported function.
§Returns
  • None, if the indicies are out of bound
  • Some(export_module_idx, export_function_idx), where the new indicies are the indicies of the module which contains the implementation of the imported function, and the implementation has the returned index within.
source

pub fn manual_lookup( modules: &[ExecutionInfo<'_>], module_map: &BTreeMap<String, usize>, module_name: &str, function_name: &str ) -> Option<(usize, usize)>

Manually lookup a function by its module and function name.

This function is used to resolve import directives before the Lut is created, and can be used to resolve imports even after the Lut is created at the cost of speed.

§Arguments
  • modules: The modules to link together.
  • module_map: A map from module name to module index within the modules array.
  • module_name: The name of the module which imports the function.
  • function_name: The name of the function to import.
§Returns
  • None, if the module or function is not found.
  • Some(export_module_idx, export_function_idx), where the new indicies are the indicies of the module which contains the implementation of the imported function, and the implementation has the returned index within. Note that this function returns the first matching function, if there are multiple functions with the same name.

Auto Trait Implementations§

§

impl RefUnwindSafe for Lut

§

impl Send for Lut

§

impl Sync for Lut

§

impl Unpin for Lut

§

impl UnwindSafe for Lut

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.