cranelift_wasm/
lib.rs

1//! Performs translation from a wasm module in binary format to the in-memory form
2//! of Cranelift IR. More particularly, it translates the code of all the functions bodies and
3//! interacts with an environment implementing the
4//! [`ModuleEnvironment`](trait.ModuleEnvironment.html)
5//! trait to deal with tables, globals and linear memory.
6//!
7//! The crate provides a `DummyEnvironment` struct that will allow to translate the code of the
8//! functions but will fail at execution.
9//!
10//! The main function of this module is [`translate_module`](fn.translate_module.html).
11
12#![deny(missing_docs, trivial_numeric_casts, unused_extern_crates)]
13#![warn(unused_import_braces)]
14#![cfg_attr(feature = "std", deny(unstable_features))]
15#![cfg_attr(feature = "clippy", plugin(clippy(conf_file = "../../clippy.toml")))]
16#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]
17#![cfg_attr(
18    feature = "cargo-clippy",
19    warn(
20        clippy::float_arithmetic,
21        clippy::mut_mut,
22        clippy::nonminimal_bool,
23        clippy::map_unwrap_or,
24        clippy::clippy::print_stdout,
25        clippy::unicode_not_nfc,
26        clippy::use_self
27    )
28)]
29#![no_std]
30
31#[cfg(not(feature = "std"))]
32#[macro_use]
33extern crate alloc as std;
34#[cfg(feature = "std")]
35#[macro_use]
36extern crate std;
37
38#[cfg(not(feature = "std"))]
39use hashbrown::{
40    hash_map,
41    hash_map::Entry::{Occupied, Vacant},
42    HashMap,
43};
44#[cfg(feature = "std")]
45use std::collections::{
46    hash_map,
47    hash_map::Entry::{Occupied, Vacant},
48    HashMap,
49};
50
51mod code_translator;
52mod environ;
53mod func_translator;
54mod heap;
55mod module_translator;
56mod sections_translator;
57mod state;
58mod translation_utils;
59
60pub use crate::environ::{
61    DummyEnvironment, DummyFuncEnvironment, DummyModuleInfo, ExpectedReachability, FuncEnvironment,
62    GlobalVariable, ModuleEnvironment, TargetEnvironment,
63};
64pub use crate::func_translator::FuncTranslator;
65pub use crate::heap::{Heap, HeapData, HeapStyle};
66pub use crate::module_translator::translate_module;
67pub use crate::state::FuncTranslationState;
68pub use crate::translation_utils::*;
69pub use cranelift_frontend::FunctionBuilder;
70pub use wasmtime_types::*;
71
72// Convenience reexport of the wasmparser crate that we're linking against,
73// since a number of types in `wasmparser` show up in the public API of
74// `cranelift-wasm`.
75pub use wasmparser;
76
77/// Version number of this crate.
78pub const VERSION: &str = env!("CARGO_PKG_VERSION");