#wasm-module #compiler #wasm-bytecode

no-std wasmer-compiler-x

Base compiler abstraction for Wasmer WebAssembly runtime

1 stable release

2.4.1 Apr 26, 2024

#754 in WebAssembly

Download history 70/week @ 2024-06-17 60/week @ 2024-06-24 23/week @ 2024-07-01 27/week @ 2024-07-08 73/week @ 2024-07-15 34/week @ 2024-07-22 43/week @ 2024-07-29 36/week @ 2024-08-05 57/week @ 2024-08-12 40/week @ 2024-08-19 66/week @ 2024-08-26 29/week @ 2024-09-02 42/week @ 2024-09-09 48/week @ 2024-09-16 76/week @ 2024-09-23 38/week @ 2024-09-30

207 downloads per month
Used in 4 crates

MIT OR Apache-2.0 WITH LLVM-exception

505KB
10K 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
~205K SLoC