#wasm-module #compiler #wasm-bytecode

无需std wasmer-compiler-x

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

1个稳定版本

2.4.1 2024年4月26日

518WebAssembly 中排名

Download history 89/week @ 2024-04-21 49/week @ 2024-04-28 106/week @ 2024-05-05 192/week @ 2024-05-12 234/week @ 2024-05-19 210/week @ 2024-05-26 145/week @ 2024-06-02 84/week @ 2024-06-09 83/week @ 2024-06-16 52/week @ 2024-06-23 34/week @ 2024-06-30 24/week @ 2024-07-07 67/week @ 2024-07-14 42/week @ 2024-07-21 44/week @ 2024-07-28

178 每月下载次数
4 crates 中使用

MIT OR Apache-2.0 WITH LLVM-exception

505KB
10K SLoC

wasmer-compiler 构建状态 加入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以进一步了解项目的许可证和其他归属。

依赖关系

~5–14MB
~181K SLoC