wasmtime_environ

Trait Compiler

source
pub trait Compiler: Send + Sync {
Show 15 methods // Required methods fn compile_function( &self, translation: &ModuleTranslation<'_>, index: DefinedFuncIndex, data: FunctionBodyData<'_>, types: &ModuleTypesBuilder, ) -> Result<(WasmFunctionInfo, Box<dyn Any + Send>), CompileError>; fn compile_array_to_wasm_trampoline( &self, translation: &ModuleTranslation<'_>, types: &ModuleTypesBuilder, index: DefinedFuncIndex, ) -> Result<Box<dyn Any + Send>, CompileError>; fn compile_wasm_to_array_trampoline( &self, wasm_func_ty: &WasmFuncType, ) -> Result<Box<dyn Any + Send>, CompileError>; fn compile_wasm_to_builtin( &self, index: BuiltinFunctionIndex, ) -> Result<Box<dyn Any + Send>, CompileError>; fn compiled_function_relocation_targets<'a>( &'a self, func: &'a dyn Any, ) -> Box<dyn Iterator<Item = RelocationTarget> + 'a>; fn append_code( &self, obj: &mut Object<'static>, funcs: &[(String, Box<dyn Any + Send>)], resolve_reloc: &dyn Fn(usize, RelocationTarget) -> usize, ) -> Result<Vec<(SymbolId, FunctionLoc)>>; fn triple(&self) -> &Triple; fn flags(&self) -> Vec<(&'static str, FlagValue<'static>)>; fn isa_flags(&self) -> Vec<(&'static str, FlagValue<'static>)>; fn is_branch_protection_enabled(&self) -> bool; fn component_compiler(&self) -> &dyn ComponentCompiler; fn append_dwarf<'a>( &self, obj: &mut Object<'_>, translations: &'a PrimaryMap<StaticModuleIndex, ModuleTranslation<'a>>, get_func: &'a dyn Fn(StaticModuleIndex, DefinedFuncIndex) -> (SymbolId, &'a (dyn Any + Send)), dwarf_package_bytes: Option<&'a [u8]>, tunables: &'a Tunables, ) -> Result<()>; // Provided methods fn object(&self, kind: ObjectKind) -> Result<Object<'static>> { ... } fn page_size_align(&self) -> u64 { ... } fn create_systemv_cie(&self) -> Option<CommonInformationEntry> { ... }
}
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§

source

fn compile_function( &self, translation: &ModuleTranslation<'_>, index: DefinedFuncIndex, data: FunctionBodyData<'_>, types: &ModuleTypesBuilder, ) -> Result<(WasmFunctionInfo, 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.

This function returns a tuple:

  1. Metadata about the wasm function itself.
  2. The function itself, as an Any to get downcasted later when passed to append_code.
source

fn compile_array_to_wasm_trampoline( &self, translation: &ModuleTranslation<'_>, types: &ModuleTypesBuilder, index: DefinedFuncIndex, ) -> Result<Box<dyn Any + Send>, CompileError>

Compile a trampoline for an array-call host function caller calling the indexth Wasm function.

The trampoline should save the necessary state to record the host-to-Wasm transition (e.g. registers used for fast stack walking).

source

fn compile_wasm_to_array_trampoline( &self, wasm_func_ty: &WasmFuncType, ) -> Result<Box<dyn Any + Send>, CompileError>

Compile a trampoline for a Wasm caller calling a array callee with the given signature.

The trampoline should save the necessary state to record the Wasm-to-host transition (e.g. registers used for fast stack walking).

source

fn compile_wasm_to_builtin( &self, index: BuiltinFunctionIndex, ) -> Result<Box<dyn Any + Send>, CompileError>

Creates a tramopline that can be used to call Wasmtime’s implementation of the builtin function specified by index.

The trampoline created can technically have any ABI but currently has the native ABI. This will then perform all the necessary duties of an exit trampoline from wasm and then perform the actual dispatch to the builtin function. Builtin functions in Wasmtime are stored in an array in all VMContext pointers, so the call to the host is an indirect call.

source

fn compiled_function_relocation_targets<'a>( &'a self, func: &'a dyn Any, ) -> Box<dyn Iterator<Item = RelocationTarget> + 'a>

Returns the list of relocations required for a function from one of the previous compile_* functions above.

source

fn append_code( &self, obj: &mut Object<'static>, funcs: &[(String, Box<dyn Any + Send>)], resolve_reloc: &dyn Fn(usize, RelocationTarget) -> usize, ) -> Result<Vec<(SymbolId, FunctionLoc)>>

Appends a list of compiled functions to an in-memory object.

This function will receive the same Box<dyn Any> produced as part of compilation from functions like compile_function, compile_host_to_wasm_trampoline, and other component-related shims. Internally this will take all of these functions and add information to the object such as:

  • Compiled code in a .text section
  • Unwind information in Wasmtime-specific sections
  • Relocations, if necessary, for the text section

Each function is accompanied with its desired symbol name and the return value of this function is the symbol for each function as well as where each function was placed within the object.

The resolve_reloc argument is intended to resolving relocations between function, chiefly resolving intra-module calls within one core wasm module. The closure here takes two arguments:

  1. First, the index within funcs that is being resolved,

  2. and next the RelocationTarget which is the relocation target to resolve.

The return value is an index within funcs that the relocation points to.

source

fn triple(&self) -> &Triple

Returns the target triple that this compiler is compiling for.

source

fn flags(&self) -> Vec<(&'static str, FlagValue<'static>)>

Returns a list of configured settings for this compiler.

source

fn isa_flags(&self) -> Vec<(&'static str, FlagValue<'static>)>

Same as Compiler::flags, but ISA-specific (a cranelift-ism)

source

fn is_branch_protection_enabled(&self) -> bool

Get a flag indicating whether branch protection is enabled.

source

fn component_compiler(&self) -> &dyn ComponentCompiler

Returns a suitable compiler usable for component-related compliations.

Note that the ComponentCompiler trait can also be implemented for Self in which case this function would simply return self.

source

fn append_dwarf<'a>( &self, obj: &mut Object<'_>, translations: &'a PrimaryMap<StaticModuleIndex, ModuleTranslation<'a>>, get_func: &'a dyn Fn(StaticModuleIndex, DefinedFuncIndex) -> (SymbolId, &'a (dyn Any + Send)), dwarf_package_bytes: Option<&'a [u8]>, tunables: &'a Tunables, ) -> Result<()>

Appends generated DWARF sections to the obj specified.

The translations track all compiled functions and get_func can be used to acquire the metadata for a particular function within a module.

Provided Methods§

source

fn object(&self, kind: ObjectKind) -> Result<Object<'static>>

Creates a new Object file which is used to build the results of a compilation into.

The returned object file will have an appropriate architecture/endianness for self.triple(), but at this time it is always an ELF file, regardless of target platform.

source

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.

source

fn create_systemv_cie(&self) -> Option<CommonInformationEntry>

Creates a new System V Common Information Entry for the ISA.

Returns None if the ISA does not support System V unwind information.

Implementors§