#wasm-module #compiler #wasm-bytecode

no-std linera-wasmer-compiler

Wasmer WebAssembly运行时的基本编译器抽象

2个版本

4.3.1-linera.22024年6月7日

WebAssembly 中排名第 382

Download history 285/week @ 2024-06-03 94/week @ 2024-06-10 98/week @ 2024-06-17 24/week @ 2024-06-24 71/week @ 2024-07-01 22/week @ 2024-07-08 72/week @ 2024-07-15 89/week @ 2024-07-22 106/week @ 2024-07-29

每月下载量 289
3 crates 中使用

MIT 许可证

540KB
11K SLoC

wasmer-compiler Build Status Join Wasmer Slack MIT License

此crate是编译器实现的基。

它将Wasm模块转换为基本的 ModuleInfo,但将Wasm函数的字节码转换留给编译器实现者。

以下是Wasmer提供的部分编译器

如何创建编译器

要创建编译器,需要实现两个特质

  1. CompilerConfig,配置并创建一个新的编译器,
  2. Compiler,编译器本身,用于编译模块。
/// 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>;
}

致谢

本项目借鉴了cranelift-wasm crate的一些代码结构,但已适应不再依赖于任何特定的IR,并对任何编译器进行抽象。

请参阅Wasmer ATTRIBUTIONS 以进一步了解项目的许可证和其他归属。

依赖项

~12–24MB
~414K SLoC