1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#[cfg(test)]
#[macro_use]
extern crate field_offset;
#[macro_use]
extern crate serde_derive;
#[macro_use]
mod macros;
#[doc(hidden)]
pub mod backend;
mod backing;
pub mod cache;
pub mod error;
pub mod export;
pub mod global;
pub mod import;
pub mod instance;
pub mod memory;
pub mod module;
mod sig_registry;
pub mod structures;
mod sys;
pub mod table;
mod typed_func;
pub mod types;
pub mod units;
pub mod vm;
#[doc(hidden)]
pub mod vmcalls;
use self::error::CompileResult;
#[doc(inline)]
pub use self::error::Result;
#[doc(inline)]
pub use self::import::IsExport;
#[doc(inline)]
pub use self::instance::Instance;
#[doc(inline)]
pub use self::module::Module;
#[doc(inline)]
pub use self::typed_func::Func;
use std::sync::Arc;
use self::cache::{Artifact, Error as CacheError};
pub mod prelude {
pub use crate::import::{ImportObject, Namespace};
pub use crate::types::{
FuncIndex, GlobalIndex, ImportedFuncIndex, ImportedGlobalIndex, ImportedMemoryIndex,
ImportedTableIndex, LocalFuncIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex,
MemoryIndex, TableIndex, Type, Value,
};
pub use crate::vm;
pub use crate::{func, imports};
}
pub fn compile_with(
wasm: &[u8],
compiler: &dyn backend::Compiler,
) -> CompileResult<module::Module> {
let token = backend::Token::generate();
compiler
.compile(wasm, token)
.map(|inner| module::Module::new(Arc::new(inner)))
}
pub fn validate(wasm: &[u8]) -> bool {
use wasmparser::WasmDecoder;
let mut parser = wasmparser::ValidatingParser::new(wasm, None);
loop {
let state = parser.read();
match *state {
wasmparser::ParserState::EndWasm => break true,
wasmparser::ParserState::Error(_) => break false,
_ => {}
}
}
}
pub unsafe fn load_cache_with(
cache: Artifact,
compiler: &dyn backend::Compiler,
) -> std::result::Result<module::Module, CacheError> {
let token = backend::Token::generate();
compiler
.from_cache(cache, token)
.map(|inner| module::Module::new(Arc::new(inner)))
}
pub const VERSION: &str = env!("CARGO_PKG_VERSION");