pub trait Compiler: Send + Sync {
    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>; 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

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.

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 is true 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.

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)

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