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 emit_obj(
        &self,
        module: &ModuleTranslation<'_>,
        types: &ModuleTypes,
        funcs: PrimaryMap<DefinedFuncIndex, 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.

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/types. 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.

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