pub struct Module<'a> {
pub orig_bytes: Option<&'a [u8]>,
pub funcs: EntityVec<Func, FuncDecl<'a>>,
pub signatures: EntityVec<Signature, SignatureData>,
pub globals: EntityVec<Global, GlobalData>,
pub tables: EntityVec<Table, TableData>,
pub imports: Vec<Import>,
pub exports: Vec<Export>,
pub memories: EntityVec<Memory, MemoryData>,
pub start_func: Option<Func>,
pub debug: Debug,
pub debug_map: DebugMap,
pub custom_sections: BTreeMap<String, Vec<u8>>,
}
Fields§
§orig_bytes: Option<&'a [u8]>
The original Wasm module this module was parsed from, if any. Used only for “lazy function bodies”, which retain a range that can refer into this slice.
funcs: EntityVec<Func, FuncDecl<'a>>
The functions in this module: imports, un-expanded (“lazily parsed”) functions, functions as IR, or IR compiled into new bytecode.
signatures: EntityVec<Signature, SignatureData>
Type signatures, referred to by funcs
, imports
and
exports
.
globals: EntityVec<Global, GlobalData>
Global variables in this module.
tables: EntityVec<Table, TableData>
Tables in this module.
imports: Vec<Import>
Imports into this module. Function imports must also have an
entry at the appropriate function index in funcs
.
exports: Vec<Export>
Exports from this module.
memories: EntityVec<Memory, MemoryData>
Memories/heapds that this module contains.
start_func: Option<Func>
The “start function” invoked at instantiation, if any.
debug: Debug
Debug-info associated with function bodies: interning pools for source file names and locations in those files.
debug_map: DebugMap
Maps from original Wasm bytecode offsets to source locations.
custom_sections: BTreeMap<String, Vec<u8>>
Implementations§
Source§impl<'a> Module<'a>
impl<'a> Module<'a>
pub fn empty() -> Module<'static>
Sourcepub fn from_wasm_bytes(
bytes: &'a [u8],
options: &FrontendOptions,
) -> Result<Self>
pub fn from_wasm_bytes( bytes: &'a [u8], options: &FrontendOptions, ) -> Result<Self>
Parse a WebAssembly module, as a slice of bytes in memory, into a waffle Module ready to be manipulated and recompile.
Sourcepub fn without_orig_bytes(self) -> Module<'static>
pub fn without_orig_bytes(self) -> Module<'static>
Take this module and strip its reference to the original bytes, producing a module with the same logical contents.
Note that this has a few side-effects:
- Any (non-debug) custom sections are lost; i.e., they will not be roundtripped from the original Wasm module.
- All function bodies are expanded to IR so they can be recompiled into new bytecode. The bytecode should be equivalent, but will not literally be the same bytecode as the original module.
Source§impl<'a> Module<'a>
impl<'a> Module<'a>
pub fn to_wasm_bytes(&self) -> Result<Vec<u8>>
pub fn to_encoded_module(&self) -> Result<Module>
pub fn per_func_body<F: Fn(&mut FunctionBody)>(&mut self, f: F)
pub fn take_per_func_body<F: FnMut(&mut Self, &mut FunctionBody)>( &mut self, f: F, )
pub fn try_per_func_body<F: FnMut(&mut FunctionBody) -> Result<(), E>, E>( &mut self, f: F, ) -> Result<(), E>
pub fn try_take_per_func_body<F: FnMut(&mut Self, &mut FunctionBody) -> Result<(), E>, E>( &mut self, f: F, ) -> Result<(), E>
Sourcepub fn expand_func<'b>(&'b mut self, id: Func) -> Result<&'b mut FuncDecl<'a>>
pub fn expand_func<'b>(&'b mut self, id: Func) -> Result<&'b mut FuncDecl<'a>>
Expand a function body, parsing its lazy reference to original bytecode into IR if needed.
Sourcepub fn clone_and_expand_body(&self, id: Func) -> Result<FunctionBody>
pub fn clone_and_expand_body(&self, id: Func) -> Result<FunctionBody>
Clone a function body without expanding it, and return a new function body with IR expanded. Useful when a tool appends new functions that are processed versions of an original function (which itself must remain as well).
Sourcepub fn expand_all_funcs(&mut self) -> Result<()>
pub fn expand_all_funcs(&mut self) -> Result<()>
For all functions that are lazy references to initial bytecode, expand them into IR.
Sourcepub fn display<'b>(&'b self) -> ModuleDisplay<'b>where
'b: 'a,
pub fn display<'b>(&'b self) -> ModuleDisplay<'b>where
'b: 'a,
Return a wrapper that implements Display on this module, pretty-printing it as textual IR.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Module<'a>
impl<'a> RefUnwindSafe for Module<'a>
impl<'a> Send for Module<'a>
impl<'a> Sync for Module<'a>
impl<'a> Unpin for Module<'a>
impl<'a> UnwindSafe for Module<'a>
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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