pub struct Interpreter { /* private fields */ }
Expand description
A ready-to-go interpreter of a wasm module.
An interpreter currently represents effectively cached state. It is reused
between calls to interpret
and is precomputed from a Module
. It houses
state like the wasm stack, wasm memory, etc.
Implementations§
source§impl Interpreter
impl Interpreter
sourcepub fn new(module: &Module) -> Result<Interpreter, Error>
pub fn new(module: &Module) -> Result<Interpreter, Error>
Creates a new interpreter from a provided Module
, precomputing all
information necessary to interpret further.
Note that the module
passed in to this function must be the same as
the module
passed to interpret
below.
sourcepub fn interpret_descriptor(
&mut self,
id: FunctionId,
module: &Module,
) -> Option<&[u32]>
pub fn interpret_descriptor( &mut self, id: FunctionId, module: &Module, ) -> Option<&[u32]>
Interprets the execution of the descriptor function func
.
This function will execute func
in the module
provided. Note that
the module
provided here must be the same as the one passed to new
when this Interpreter
was constructed.
The func
must be a wasm-bindgen descriptor function meaning that it
doesn’t do anything like use floats or i64. Instead all it should do is
call other functions, sometimes some stack pointer manipulation, and
then call the one imported __wbindgen_describe
function. Anything else
will cause this interpreter to panic.
When the descriptor has finished running the assembled descriptor list
is returned. The descriptor returned can then be re-parsed into an
actual Descriptor
in the cli-support crate.
§Return value
Returns Some
if func
was found in the module
and None
if it was
not found in the module
.
sourcepub fn interpret_closure_descriptor(
&mut self,
id: FunctionId,
module: &Module,
entry_removal_list: &mut HashMap<ElementId, BTreeSet<usize>>,
) -> Option<&[u32]>
pub fn interpret_closure_descriptor( &mut self, id: FunctionId, module: &Module, entry_removal_list: &mut HashMap<ElementId, BTreeSet<usize>>, ) -> Option<&[u32]>
Interprets a “closure descriptor”, figuring out the signature of the closure that was intended.
This function will take an id
which is known to internally
execute __wbindgen_describe_closure
and interpret it. The
wasm-bindgen
crate controls all callers of this internal import. It
will then take the index passed to __wbindgen_describe_closure
and
interpret it as a function pointer. This means it’ll look up within the
element section (function table) which index it points to. Upon finding
the relevant entry it’ll assume that function is a descriptor function,
and then it will execute the descriptor function.
The returned value is the return value of the descriptor function found.
The entry_removal_list
list is also then populated with an index of
the entry in the elements section (and then the index within that
section) of the function that needs to be snip’d out.
sourcepub fn describe_closure_id(&self) -> Option<FunctionId>
pub fn describe_closure_id(&self) -> Option<FunctionId>
Returns the function id of the __wbindgen_describe_closure
imported function.
sourcepub fn function_table_id(&self) -> Option<TableId>
pub fn function_table_id(&self) -> Option<TableId>
Returns the detected id of the function table.