Path: blob/main/crates/fuzzing/wasm-spec-interpreter/src/lib.rs
3069 views
//! This library provides a way to interpret Wasm functions in the official Wasm1//! specification interpreter, written in OCaml, from Rust.2//!3//! In order to not break Wasmtime's build, this library will always compile. It4//! does depend on certain tools (see `README.md`) that may or may not be5//! available in the environment:6//! - when the tools are available, we build and link to an OCaml static7//! library (see `with_library` module)8//! - when the tools are not available, this library will panic at runtime (see9//! `without_library` module).1011/// Enumerate the kinds of Wasm values the OCaml interpreter can handle.12#[derive(Clone, Debug, PartialEq)]13pub enum SpecValue {14I32(i32),15I64(i64),16F32(i32),17F64(i64),18V128(Vec<u8>),19}2021/// Represents a WebAssembly export from the OCaml interpreter side.22pub enum SpecExport {23Global(SpecValue),24Memory(Vec<u8>),25}2627/// Represents a WebAssembly instance from the OCaml interpreter side.28pub struct SpecInstance {29#[cfg(feature = "has-libinterpret")]30repr: ocaml_interop::BoxRoot<SpecInstance>,31}3233#[cfg(feature = "has-libinterpret")]34mod with_library;35#[cfg(feature = "has-libinterpret")]36pub use with_library::*;3738#[cfg(not(feature = "has-libinterpret"))]39mod without_library;40#[cfg(not(feature = "has-libinterpret"))]41pub use without_library::*;4243// If the user is fuzzing`, we expect the OCaml library to have been built.44#[cfg(all(fuzzing, not(feature = "has-libinterpret")))]45compile_error!("The OCaml library was not built.");4647/// Check if the OCaml spec interpreter bindings will work.48pub fn support_compiled_in() -> bool {49cfg!(feature = "has-libinterpret")50}515253