Trait wasmtime_environ::Compiler

source ·
pub trait Compiler: Send + Sync {
Show 13 methods // Required methods fn compile_function( &self, translation: &ModuleTranslation<'_>, index: DefinedFuncIndex, data: FunctionBodyData<'_>, tunables: &Tunables, types: &ModuleTypes, ) -> Result<(WasmFunctionInfo, Box<dyn Any + Send>), CompileError>; fn compile_host_to_wasm_trampoline( &self, ty: &WasmFuncType, ) -> Result<Box<dyn Any + Send>, CompileError>; fn append_code( &self, obj: &mut Object<'static>, funcs: &[(String, Box<dyn Any + Send>)], tunables: &Tunables, resolve_reloc: &dyn Fn(usize, FuncIndex) -> usize, ) -> Result<Vec<(SymbolId, FunctionLoc)>>; fn emit_trampoline_obj( &self, ty: &WasmFuncType, host_fn: usize, obj: &mut Object<'static>, ) -> Result<(FunctionLoc, FunctionLoc)>; fn triple(&self) -> &Triple; fn flags(&self) -> BTreeMap<String, FlagValue>; fn isa_flags(&self) -> BTreeMap<String, FlagValue>; fn is_branch_protection_enabled(&self) -> bool; fn append_dwarf( &self, obj: &mut Object<'_>, translation: &ModuleTranslation<'_>, funcs: &PrimaryMap<DefinedFuncIndex, (SymbolId, &(dyn Any + Send))>, ) -> Result<()>; fn function_alignment(&self) -> u32; // 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<'_>, tunables: &Tunables, types: &ModuleTypes, ) -> 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.

source

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.

source

fn append_code( &self, obj: &mut Object<'static>, funcs: &[(String, Box<dyn Any + Send>)], tunables: &Tunables, resolve_reloc: &dyn Fn(usize, FuncIndex) -> 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: first the index within funcs that is being resolved and next the FuncIndex which is the relocation target to resolve. The return value is an index within funcs that the relocation points to.

source

fn emit_trampoline_obj( &self, ty: &WasmFuncType, host_fn: usize, obj: &mut Object<'static>, ) -> Result<(FunctionLoc, FunctionLoc)>

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.

source

fn triple(&self) -> &Triple

Returns the target triple that this compiler is compiling for.

source

fn flags(&self) -> BTreeMap<String, FlagValue>

Returns a list of configured settings for this compiler.

source

fn isa_flags(&self) -> BTreeMap<String, FlagValue>

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 append_dwarf( &self, obj: &mut Object<'_>, translation: &ModuleTranslation<'_>, funcs: &PrimaryMap<DefinedFuncIndex, (SymbolId, &(dyn Any + Send))>, ) -> Result<()>

Appends generated DWARF sections to the obj specified for the compiled functions.

source

fn function_alignment(&self) -> u32

The function alignment required by this ISA.

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§