14 releases (4 stable)

2.0.0 Jun 16, 2021
1.0.2 Feb 5, 2021
1.0.0-rc1 Dec 23, 2020
1.0.0-alpha5 Nov 6, 2020

#69 in WebAssembly

Download history 2190/week @ 2021-04-03 2374/week @ 2021-04-10 4414/week @ 2021-04-17 3448/week @ 2021-04-24 3416/week @ 2021-05-01 3078/week @ 2021-05-08 2813/week @ 2021-05-15 2595/week @ 2021-05-22 2433/week @ 2021-05-29 2210/week @ 2021-06-05 3109/week @ 2021-06-12 4188/week @ 2021-06-19 3638/week @ 2021-06-26 3906/week @ 2021-07-03 4794/week @ 2021-07-10 3056/week @ 2021-07-17

11,695 downloads per month
Used in 60 crates (17 directly)

MIT OR Apache-2.0 WITH LLVM-exception

535KB
11K 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 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

~6MB
~131K SLoC