wasmer_runtime_core_x/
lib.rs1#![deny(
16 dead_code,
17 missing_docs,
18 nonstandard_style,
19 unused_imports,
20 unused_mut,
21 unused_variables,
22 unused_unsafe,
23 unreachable_patterns
24)]
25#![doc(html_favicon_url = "https://wasmer.io/static/icons/favicon.ico")]
26#![doc(html_logo_url = "https://avatars3.githubusercontent.com/u/44205449?s=200&v=4")]
27
28#[macro_use]
29extern crate serde_derive;
30
31#[allow(unused_imports)]
32#[macro_use]
33extern crate lazy_static;
34
35#[macro_use]
36mod macros;
37#[doc(hidden)]
38pub mod backend;
39mod backing;
40
41pub mod cache;
42pub mod codegen;
43pub mod error;
44pub mod export;
45pub mod global;
46pub mod import;
47pub mod instance;
48pub mod loader;
49pub mod memory;
50pub mod module;
51pub mod parse;
52mod sig_registry;
53pub mod structures;
54mod sys;
55pub mod table;
56#[cfg(all(unix, target_arch = "x86_64"))]
57pub mod trampoline_x64;
58pub mod typed_func;
59pub mod types;
60pub mod units;
61pub mod vm;
62#[doc(hidden)]
63pub mod vmcalls;
64#[cfg(all(unix, target_arch = "x86_64"))]
65pub use trampoline_x64 as trampoline;
66#[cfg(unix)]
67pub mod fault;
68#[cfg(feature = "generate-debug-information")]
69pub mod jit_debug;
70pub mod state;
71#[cfg(feature = "managed")]
72pub mod tiering;
73
74use self::error::CompileResult;
75#[doc(inline)]
76pub use self::error::Result;
77#[doc(inline)]
78pub use self::import::IsExport;
79#[doc(inline)]
80pub use self::instance::{DynFunc, Instance};
81#[doc(inline)]
82pub use self::module::Module;
83#[doc(inline)]
84pub use self::typed_func::Func;
85use std::sync::Arc;
86
87pub use wasmparser;
88
89use self::cache::{Artifact, Error as CacheError};
90
91pub mod prelude {
92 pub use crate::import::{ImportObject, Namespace};
96 pub use crate::types::{
97 FuncIndex, GlobalIndex, ImportedFuncIndex, ImportedGlobalIndex, ImportedMemoryIndex,
98 ImportedTableIndex, LocalFuncIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex,
99 MemoryIndex, TableIndex, Type, Value,
100 };
101 pub use crate::vm;
102 pub use crate::{func, imports};
103}
104
105pub fn compile_with(
110 wasm: &[u8],
111 compiler: &dyn backend::Compiler,
112) -> CompileResult<module::Module> {
113 let token = backend::Token::generate();
114 compiler
115 .compile(wasm, Default::default(), token)
116 .map(|mut inner| {
117 let inner_info: &mut crate::module::ModuleInfo = &mut inner.info;
118 inner_info.import_custom_sections(wasm).unwrap();
119 module::Module::new(Arc::new(inner))
120 })
121}
122
123pub fn compile_with_config(
126 wasm: &[u8],
127 compiler: &dyn backend::Compiler,
128 compiler_config: backend::CompilerConfig,
129) -> CompileResult<module::Module> {
130 let token = backend::Token::generate();
131 compiler
132 .compile(wasm, compiler_config, token)
133 .map(|inner| module::Module::new(Arc::new(inner)))
134}
135
136pub fn validate(wasm: &[u8]) -> bool {
140 validate_and_report_errors(wasm).is_ok()
141}
142
143pub fn validate_and_report_errors(wasm: &[u8]) -> ::std::result::Result<(), String> {
145 validate_and_report_errors_with_features(wasm, Default::default())
146}
147
148pub fn validate_and_report_errors_with_features(
150 wasm: &[u8],
151 features: backend::Features,
152) -> ::std::result::Result<(), String> {
153 use wasmparser::WasmDecoder;
154 let config = wasmparser::ValidatingParserConfig {
155 operator_config: wasmparser::OperatorValidatorConfig {
156 enable_simd: features.simd,
157 enable_bulk_memory: false,
158 enable_multi_value: false,
159 enable_reference_types: false,
160 enable_threads: features.threads,
161
162 #[cfg(feature = "deterministic-execution")]
163 deterministic_only: true,
164 },
165 };
166 let mut parser = wasmparser::ValidatingParser::new(wasm, Some(config));
167 loop {
168 let state = parser.read();
169 match *state {
170 wasmparser::ParserState::EndWasm => break Ok(()),
171 wasmparser::ParserState::Error(ref e) => break Err(format!("{}", e)),
172 _ => {}
173 }
174 }
175}
176
177pub unsafe fn load_cache_with(
179 cache: Artifact,
180 compiler: &dyn backend::Compiler,
181) -> std::result::Result<module::Module, CacheError> {
182 let token = backend::Token::generate();
183 compiler
184 .from_cache(cache, token)
185 .map(|inner| module::Module::new(Arc::new(inner)))
186}
187
188pub const VERSION: &str = env!("CARGO_PKG_VERSION");