#wasm-module #compiler #wasm-bytecode

no-std wasmer-compiler

Base compiler abstraction for Wasmer WebAssembly runtime

60 releases (30 stable)

4.2.8 Apr 6, 2024
4.2.6 Mar 4, 2024
4.2.5 Dec 23, 2023
4.2.3 Oct 27, 2023
1.0.0-alpha5 Nov 6, 2020

#562 in WebAssembly

Download history 13175/week @ 2023-12-23 23633/week @ 2023-12-30 23607/week @ 2024-01-06 29231/week @ 2024-01-13 27093/week @ 2024-01-20 23594/week @ 2024-01-27 27411/week @ 2024-02-03 24119/week @ 2024-02-10 20200/week @ 2024-02-17 18755/week @ 2024-02-24 24809/week @ 2024-03-02 26532/week @ 2024-03-09 24104/week @ 2024-03-16 22543/week @ 2024-03-23 24959/week @ 2024-03-30 20767/week @ 2024-04-06

95,075 downloads per month
Used in 274 crates (21 directly)

MIT license

525KB
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

~6–16MB
~203K SLoC