Struct wasmtime_jit::ObjectBuilder

source ·
pub struct ObjectBuilder<'a> { /* private fields */ }
Expand description

Helper structure to create an ELF file as a compilation artifact.

This structure exposes the process which Wasmtime will encode a core wasm module into an ELF file, notably managing data sections and all that good business going into the final file.

Implementations§

source§

impl<'a> ObjectBuilder<'a>

source

pub fn new(obj: Object<'a>, tunables: &'a Tunables) -> ObjectBuilder<'a>

Creates a new builder for the obj specified.

source

pub fn append( &mut self, translation: ModuleTranslation<'_>, funcs: PrimaryMap<DefinedFuncIndex, CompiledFunctionInfo>, wasm_to_native_trampolines: Vec<(SignatureIndex, FunctionLoc)> ) -> Result<CompiledModuleInfo>

Completes compilation of the translation specified, inserting everything necessary into the Object being built.

This function will consume the final results of compiling a wasm module and finish the ELF image in-progress as part of self.obj by appending any compiler-agnostic sections.

The auxiliary CompiledModuleInfo structure returned here has also been serialized into the object returned, but if the caller will quickly turn-around and invoke CompiledModule::from_artifacts after this then the information can be passed to that method to avoid extra deserialization. This is done to avoid a serialize-then-deserialize for API calls like Module::new where the compiled module is immediately going to be used.

The various arguments here are:

  • translation - the core wasm translation that’s being completed.

  • funcs - compilation metadata about functions within the translation as well as where the functions are located in the text section.

  • array_to_wasm_trampolines - list of all trampolines necessary for array callers (e.g. Func::new) calling Wasm callees. One for each defined function that escapes. Must be sorted by DefinedFuncIndex.

  • native_to_wasm_trampolines - list of all trampolines necessary for native callers (e.g. Func::wrap) calling Wasm callees. One for each defined function that escapes. Must be sorted by DefinedFuncIndex.

  • wasm_to_native_trampolines - list of all trampolines necessary for Wasm callers calling native callees (e.g. Func::wrap). One for each function signature in the module. Must be sorted by SignatureIndex.

Returns the CompiledModuleInfo corresponding to this core Wasm module as a result of this append operation. This is then serialized into the final artifact by the caller.

source

pub fn serialize_info<T>(&mut self, info: &T)
where T: Serialize,

Creates the ELF_WASMTIME_INFO section from the given serializable data structure.

source

pub fn finish(self) -> Result<MmapVec>

Creates a new MmapVec from self.

The returned MmapVec will contain the serialized version of self and is sized appropriately to the exact size of the object serialized.

Auto Trait Implementations§

§

impl<'a> Freeze for ObjectBuilder<'a>

§

impl<'a> RefUnwindSafe for ObjectBuilder<'a>

§

impl<'a> Send for ObjectBuilder<'a>

§

impl<'a> Sync for ObjectBuilder<'a>

§

impl<'a> Unpin for ObjectBuilder<'a>

§

impl<'a> UnwindSafe for ObjectBuilder<'a>

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.