10 releases (2 stable)

1.0.1 Jan 13, 2021
1.0.0 Jan 5, 2021
1.0.0-rc1 Dec 23, 2020
1.0.0-alpha5 Nov 6, 2020
1.0.0-alpha01.0 Aug 15, 2020

#22 in #compiler

Download history 22/week @ 2020-10-02 128/week @ 2020-10-09 90/week @ 2020-10-16 88/week @ 2020-10-23 141/week @ 2020-10-30 311/week @ 2020-11-06 307/week @ 2020-11-13 327/week @ 2020-11-20 508/week @ 2020-11-27 148/week @ 2020-12-04 301/week @ 2020-12-11 278/week @ 2020-12-18 403/week @ 2020-12-25 507/week @ 2021-01-01 1110/week @ 2021-01-08 1049/week @ 2021-01-15

1,418 downloads per month
Used in 22 crates (12 directly)

MIT OR Apache-2.0 WITH LLVM-exception

425KB
8K SLoC

wasmer-compiler Build Status Join Wasmer Slack MIT License

This crate is the base for Compiler implementations.

It performs the translation from a Wasm module into a basic ModuleInfo, but leaves the Wasm function bytecode translation to the compiler implementor.

Here are some of the Compilers provided by Wasmer:

How to create a compiler

To create a compiler, one needs to implement two traits:

  1. CompilerConfig, that configures and creates a new compiler,
  2. Compiler, the compiler itself that will compile a module.
/// The compiler configuration options.
pub trait CompilerConfig {
    /// Gets the custom compiler config
    fn compiler(&self) -> Box<dyn Compiler>;
}

/// An implementation of a compiler from parsed WebAssembly module to compiled native code.
pub trait Compiler {
    /// Compiles a parsed module.
    ///
    /// It returns the [`Compilation`] or a [`CompileError`].
    fn compile_module<'data, 'module>(
        &self,
        target: &Target,
        compile_info: &'module mut CompileModuleInfo,
        module_translation: &ModuleTranslationState,
        // The list of function bodies
        function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'data>>,
    ) -> Result<Compilation, CompileError>;
}

Acknowledgments

This project borrowed some of the code strucutre from the cranelift-wasm crate, however it's been adapted to not depend on any specific IR and be abstract of any compiler.

Please check Wasmer ATTRIBUTIONS to further see licenses and other attributions of the project.

Dependencies

~2–3MB
~66K SLoC