#wasm-module #wasm-bytecode #compiler

no-std unc-vm-compiler

Base compiler abstraction for Wasmer WebAssembly runtime

13 releases (5 breaking)

0.12.2 May 30, 2024
0.10.2 May 15, 2024
0.7.3 Apr 12, 2024
0.7.0 Mar 29, 2024
0.1.0 Mar 5, 2024

#566 in WebAssembly

Download history 69/week @ 2024-06-16 39/week @ 2024-06-23 38/week @ 2024-06-30 17/week @ 2024-07-07 62/week @ 2024-07-14 39/week @ 2024-07-21 44/week @ 2024-07-28 25/week @ 2024-08-04 33/week @ 2024-08-11 20/week @ 2024-08-18 45/week @ 2024-08-25 26/week @ 2024-09-01 34/week @ 2024-09-08 37/week @ 2024-09-15 91/week @ 2024-09-22 56/week @ 2024-09-29

218 downloads per month
Used in 3 crates

GPL-2.0-or-later WITH LLVM-exception

500KB
10K SLoC

unc-vm-compiler

This crate is a fork of wasmer-compiler. A significant number of things changed, but the documentation is not up-to-date yet.

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,
        // The list of function bodies
        function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'data>>,
        instrumentation: &finite_wasm::Module,
    ) -> 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

~11–20MB
~314K SLoC