pub trait Compiler: Send + Sync {
    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 page_size_align(&self) -> u64; 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 object(&self, kind: ObjectKind) -> 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§

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.

Creates a function of type VMTrampoline which will then call the function pointer argument which has the ty type provided.

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

This function will receive the same Box<dyn Ayn> 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.

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.

Returns the target triple that this compiler is compiling for.

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.

Returns a list of configured settings for this compiler.

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

Get a flag indicating whether branch protection is enabled.

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

Provided Methods§

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.

Implementors§