#wasm-module #compiler #wasm-bytecode

无std wasmer-compiler

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

69个版本 (37个稳定版)

4.3.6 2024年8月22日
4.3.5 2024年7月16日
4.3.2 2024年6月11日
4.2.6 2024年3月4日
1.0.0-alpha52020年11月6日

WebAssembly 中排名 1237

Download history 23166/week @ 2024-05-03 21993/week @ 2024-05-10 20560/week @ 2024-05-17 19030/week @ 2024-05-24 20052/week @ 2024-05-31 19370/week @ 2024-06-07 27611/week @ 2024-06-14 19599/week @ 2024-06-21 21072/week @ 2024-06-28 31485/week @ 2024-07-05 37771/week @ 2024-07-12 30112/week @ 2024-07-19 24463/week @ 2024-07-26 28068/week @ 2024-08-02 27173/week @ 2024-08-09 41351/week @ 2024-08-16

每月下载 124,151
用于 293 个crate(21个直接使用)

MIT 许可证

545KB
11K 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以进一步了解项目的许可证和其他归属。

依赖项

~13–26MB
~466K SLoC