Trait wasmtime_environ::Compiler
source · pub trait Compiler: Send + Sync {
// Required methods
fn compile_function(
&self,
translation: &ModuleTranslation<'_>,
index: DefinedFuncIndex,
data: FunctionBodyData<'_>,
tunables: &Tunables,
types: &ModuleTypes
) -> Result<Box<dyn Any + Send>, CompileError>;
fn compile_host_to_wasm_trampoline(
&self,
ty: &WasmFuncType
) -> Result<Box<dyn Any + Send>, CompileError>;
fn emit_obj(
&self,
module: &ModuleTranslation<'_>,
funcs: PrimaryMap<DefinedFuncIndex, Box<dyn Any + Send>>,
trampolines: Vec<Box<dyn Any + Send>>,
tunables: &Tunables,
obj: &mut Object<'static>
) -> Result<(PrimaryMap<DefinedFuncIndex, FunctionInfo>, Vec<Trampoline>)>;
fn emit_trampoline_obj(
&self,
ty: &WasmFuncType,
host_fn: usize,
obj: &mut Object<'static>
) -> Result<(Trampoline, Trampoline)>;
fn triple(&self) -> &Triple;
fn page_size_align(&self) -> u64;
fn flags(&self) -> BTreeMap<String, FlagValue>;
fn isa_flags(&self) -> BTreeMap<String, FlagValue>;
// Provided method
fn object(&self) -> Result<Object<'static>> { ... }
}
Expand description
An implementation of a compiler which can compile WebAssembly functions to machine code and perform other miscellaneous tasks needed by the JIT runtime.
Required Methods§
sourcefn compile_function(
&self,
translation: &ModuleTranslation<'_>,
index: DefinedFuncIndex,
data: FunctionBodyData<'_>,
tunables: &Tunables,
types: &ModuleTypes
) -> Result<Box<dyn Any + Send>, CompileError>
fn compile_function( &self, translation: &ModuleTranslation<'_>, index: DefinedFuncIndex, data: FunctionBodyData<'_>, tunables: &Tunables, types: &ModuleTypes ) -> Result<Box<dyn Any + Send>, CompileError>
Compiles the function index
within translation
.
The body of the function is available in data
and configuration
values are also passed in via tunables
. Type information in
translation
is all relative to types
.
sourcefn compile_host_to_wasm_trampoline(
&self,
ty: &WasmFuncType
) -> Result<Box<dyn Any + Send>, CompileError>
fn compile_host_to_wasm_trampoline( &self, ty: &WasmFuncType ) -> Result<Box<dyn Any + Send>, CompileError>
Creates a function of type VMTrampoline
which will then call the
function pointer argument which has the ty
type provided.
sourcefn emit_obj(
&self,
module: &ModuleTranslation<'_>,
funcs: PrimaryMap<DefinedFuncIndex, Box<dyn Any + Send>>,
trampolines: Vec<Box<dyn Any + Send>>,
tunables: &Tunables,
obj: &mut Object<'static>
) -> Result<(PrimaryMap<DefinedFuncIndex, FunctionInfo>, Vec<Trampoline>)>
fn emit_obj( &self, module: &ModuleTranslation<'_>, funcs: PrimaryMap<DefinedFuncIndex, Box<dyn Any + Send>>, trampolines: Vec<Box<dyn Any + Send>>, tunables: &Tunables, obj: &mut Object<'static> ) -> Result<(PrimaryMap<DefinedFuncIndex, FunctionInfo>, Vec<Trampoline>)>
Collects the results of compilation into an in-memory object.
This function will receive the same Box<dyn Ayn>
produced as part of
compile_function
, as well as the general compilation environment with
the translation. THe trampolines
argument is generated by
compile_host_to_wasm_trampoline
for each of
module.exported_signatures
. This method is expected to populate
information in the object file such as:
- Compiled code in a
.text
section - Unwind information in Wasmtime-specific sections
- DWARF debugging information for the host, if
emit_dwarf
istrue
and the compiler supports it. - Relocations, if necessary, for the text section
The final result of compilation will contain more sections inserted by the compiler-agnostic runtime.
This function returns information about the compiled functions (where they are in the text section) along with where trampolines are located.
sourcefn emit_trampoline_obj(
&self,
ty: &WasmFuncType,
host_fn: usize,
obj: &mut Object<'static>
) -> Result<(Trampoline, Trampoline)>
fn emit_trampoline_obj( &self, ty: &WasmFuncType, host_fn: usize, obj: &mut Object<'static> ) -> Result<(Trampoline, Trampoline)>
Inserts two functions for host-to-wasm and wasm-to-host trampolines into
the obj
provided.
This will configure the same sections as emit_obj
, but will likely be
much smaller. The two returned Trampoline
structures describe where to
find the host-to-wasm and wasm-to-host trampolines in the text section,
respectively.
sourcefn page_size_align(&self) -> u64
fn page_size_align(&self) -> u64
Returns the alignment necessary to align values to the page size of the compilation target. Note that this may be an upper-bound where the alignment is larger than necessary for some platforms since it may depend on the platform’s runtime configuration.