1#![deny(missing_docs, unused_extern_crates)]
8#![warn(unused_import_braces)]
9#![cfg_attr(not(feature = "std"), no_std)]
10#![allow(clippy::new_without_default)]
11#![warn(
12 clippy::float_arithmetic,
13 clippy::mut_mut,
14 clippy::nonminimal_bool,
15 clippy::map_unwrap_or,
16 clippy::print_stdout,
17 clippy::unicode_not_nfc,
18 clippy::use_self
19)]
20#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
21
22#[cfg(all(feature = "std", feature = "core"))]
23compile_error!(
24 "The `std` and `core` features are both enabled, which is an error. Please enable only once."
25);
26
27#[cfg(all(not(feature = "std"), not(feature = "core")))]
28compile_error!("Both the `std` and `core` features are disabled. Please enable one of them.");
29
30#[cfg(feature = "core")]
31extern crate alloc;
32
33pub mod lib {
36 #[cfg(feature = "core")]
38 pub mod std {
39 pub use alloc::{borrow, boxed, format, iter, rc, slice, string, vec};
40 pub use core::{any, cell, cmp, convert, fmt, hash, marker, mem, ops, ptr, sync};
41 }
42
43 #[cfg(feature = "std")]
45 pub mod std {
46 pub use std::{
47 any, borrow, boxed, cell, cmp, convert, fmt, format, hash, iter, marker, mem, ops, ptr,
48 rc, slice, string, sync, vec,
49 };
50 }
51}
52
53pub mod error;
54mod features;
55mod indexes;
56mod initializers;
57mod libcalls;
58mod memory;
59mod module;
60mod module_hash;
61mod serialize;
62mod stack;
63mod store_id;
64mod table;
65mod trapcode;
66mod types;
67mod units;
68mod utils;
69mod value;
70mod vmoffsets;
71
72pub use error::{
73 CompileError, DeserializeError, ImportError, MemoryError, MiddlewareError,
74 ParseCpuFeatureError, PreInstantiationError, SerializeError, WasmError, WasmResult,
75};
76
77pub mod entity;
79pub use crate::features::Features;
80pub use crate::indexes::{
81 CustomSectionIndex, DataIndex, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, ImportIndex,
82 LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, LocalTagIndex,
83 MemoryIndex, SignatureIndex, TableIndex, Tag, TagIndex,
84};
85pub use crate::initializers::{
86 ArchivedDataInitializerLocation, ArchivedOwnedDataInitializer, DataInitializer,
87 DataInitializerLike, DataInitializerLocation, DataInitializerLocationLike,
88 OwnedDataInitializer, TableInitializer,
89};
90pub use crate::memory::{Memory32, Memory64, MemorySize};
91pub use crate::module::{ExportsIterator, ImportKey, ImportsIterator, ModuleInfo};
92pub use crate::module_hash::{HashAlgorithm, ModuleHash};
93pub use crate::units::{
94 Bytes, PageCountOutOfRange, Pages, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE,
95};
96pub use types::{
97 ExportType, ExternType, FunctionType, GlobalInit, GlobalType, ImportType, MemoryType,
98 Mutability, TableType, TagKind, TagType, Type, V128,
99};
100pub use value::{RawValue, ValueType};
101
102pub use crate::libcalls::LibCall;
103pub use crate::memory::MemoryStyle;
104pub use crate::table::TableStyle;
105pub use serialize::MetadataHeader;
106pub use crate::stack::{FrameInfo, SourceLoc, TrapInformation};
108pub use crate::store_id::StoreId;
109pub use crate::trapcode::{OnCalledAction, TrapCode};
110pub use crate::utils::is_wasm;
111pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
112
113pub type CodeOffset = u32;
115
116pub type Addend = i64;
118
119pub const VERSION: &str = env!("CARGO_PKG_VERSION");
121
122mod native {
123 use super::Type;
124 use crate::memory::{Memory32, Memory64, MemorySize};
125 use std::fmt;
126
127 pub trait NativeWasmType: Sized {
143 type Abi: Copy + fmt::Debug;
145
146 const WASM_TYPE: Type;
148 }
149
150 impl NativeWasmType for u32 {
151 const WASM_TYPE: Type = Type::I32;
152 type Abi = Self;
153 }
154
155 impl NativeWasmType for i32 {
156 const WASM_TYPE: Type = Type::I32;
157 type Abi = Self;
158 }
159
160 impl NativeWasmType for i64 {
161 const WASM_TYPE: Type = Type::I64;
162 type Abi = Self;
163 }
164
165 impl NativeWasmType for u64 {
166 const WASM_TYPE: Type = Type::I64;
167 type Abi = Self;
168 }
169
170 impl NativeWasmType for f32 {
171 const WASM_TYPE: Type = Type::F32;
172 type Abi = Self;
173 }
174
175 impl NativeWasmType for f64 {
176 const WASM_TYPE: Type = Type::F64;
177 type Abi = Self;
178 }
179
180 impl NativeWasmType for u128 {
181 const WASM_TYPE: Type = Type::V128;
182 type Abi = Self;
183 }
184
185 impl NativeWasmType for Memory32 {
186 const WASM_TYPE: Type = <<Self as MemorySize>::Native as NativeWasmType>::WASM_TYPE;
187 type Abi = <<Self as MemorySize>::Native as NativeWasmType>::Abi;
188 }
189
190 impl NativeWasmType for Memory64 {
191 const WASM_TYPE: Type = <<Self as MemorySize>::Native as NativeWasmType>::WASM_TYPE;
192 type Abi = <<Self as MemorySize>::Native as NativeWasmType>::Abi;
193 }
194
195 impl<T: NativeWasmType> NativeWasmType for Option<T> {
196 const WASM_TYPE: Type = T::WASM_TYPE;
197 type Abi = T::Abi;
198 }
199}
200
201pub use crate::native::*;