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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#![deny(missing_docs, unused_extern_crates)]
#![warn(unused_import_braces)]
#![cfg_attr(feature = "std", deny(unstable_features))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default))]
#![cfg_attr(
feature = "cargo-clippy",
warn(
clippy::float_arithmetic,
clippy::mut_mut,
clippy::nonminimal_bool,
clippy::map_unwrap_or,
clippy::print_stdout,
clippy::unicode_not_nfc,
clippy::use_self
)
)]
#[cfg(all(feature = "std", feature = "core"))]
compile_error!(
"The `std` and `core` features are both enabled, which is an error. Please enable only once."
);
#[cfg(all(not(feature = "std"), not(feature = "core")))]
compile_error!("Both the `std` and `core` features are disabled. Please enable one of them.");
#[cfg(feature = "core")]
extern crate alloc;
pub mod lib {
#[cfg(feature = "core")]
pub mod std {
pub use alloc::{borrow, boxed, format, iter, rc, slice, string, vec};
pub use core::{any, cell, cmp, convert, fmt, hash, marker, mem, ops, ptr, sync, u32};
}
#[cfg(feature = "std")]
pub mod std {
pub use std::{
any, borrow, boxed, cell, cmp, convert, fmt, format, hash, iter, marker, mem, ops, ptr,
rc, slice, string, sync, u32, vec,
};
}
}
pub mod compilation;
pub mod error;
mod features;
mod indexes;
mod initializers;
mod libcalls;
mod memory;
mod module;
mod serialize;
mod table;
mod trapcode;
mod types;
mod units;
mod utils;
mod value;
mod vmoffsets;
pub use crate::compilation::target::{
Aarch64Architecture, Architecture, BinaryFormat, CallingConvention, CpuFeature, Endianness,
Environment, OperatingSystem, PointerWidth, Target, Triple, Vendor,
};
pub use crate::serialize::{MetadataHeader, SerializableCompilation, SerializableModule};
pub use error::{
CompileError, DeserializeError, ImportError, MemoryError, MiddlewareError,
ParseCpuFeatureError, PreInstantiationError, SerializeError, WasmError, WasmResult,
};
pub mod entity;
pub use crate::features::Features;
pub use crate::indexes::{
CustomSectionIndex, DataIndex, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, ImportIndex,
LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryIndex,
SignatureIndex, TableIndex,
};
pub use crate::initializers::{
DataInitializer, DataInitializerLocation, OwnedDataInitializer, TableInitializer,
};
pub use crate::memory::{Memory32, Memory64, MemorySize};
pub use crate::module::{ExportsIterator, ImportKey, ImportsIterator, ModuleInfo};
pub use crate::units::{
Bytes, PageCountOutOfRange, Pages, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE,
};
pub use types::{
ExportType, ExternType, FunctionType, GlobalInit, GlobalType, ImportType, MemoryType,
Mutability, TableType, Type, V128,
};
pub use value::{RawValue, ValueType};
pub use crate::libcalls::LibCall;
pub use crate::memory::MemoryStyle;
pub use crate::table::TableStyle;
pub use crate::trapcode::TrapCode;
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
pub use crate::utils::is_wasm;
pub use crate::compilation::relocation::{
Relocation, RelocationKind, RelocationTarget, Relocations,
};
pub use crate::compilation::section::{
CustomSection, CustomSectionProtection, SectionBody, SectionIndex,
};
pub use crate::compilation::address_map::{FunctionAddressMap, InstructionAddressMap};
pub use crate::compilation::function::{
Compilation, CompiledFunction, CompiledFunctionFrameInfo, CustomSections, Dwarf, FunctionBody,
Functions,
};
pub use crate::compilation::module::CompileModuleInfo;
pub use crate::compilation::sourceloc::SourceLoc;
pub use crate::compilation::symbols::{Symbol, SymbolRegistry};
pub use crate::compilation::trap::TrapInformation;
pub use crate::compilation::unwind::CompiledFunctionUnwindInfo;
pub type CodeOffset = u32;
pub type Addend = i64;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
mod native {
use super::Type;
use crate::memory::{Memory32, Memory64, MemorySize};
use std::fmt;
pub trait NativeWasmType: Sized {
type Abi: Copy + fmt::Debug;
const WASM_TYPE: Type;
}
impl NativeWasmType for i32 {
const WASM_TYPE: Type = Type::I32;
type Abi = Self;
}
impl NativeWasmType for i64 {
const WASM_TYPE: Type = Type::I64;
type Abi = Self;
}
impl NativeWasmType for f32 {
const WASM_TYPE: Type = Type::F32;
type Abi = Self;
}
impl NativeWasmType for f64 {
const WASM_TYPE: Type = Type::F64;
type Abi = Self;
}
impl NativeWasmType for u128 {
const WASM_TYPE: Type = Type::V128;
type Abi = Self;
}
impl NativeWasmType for Memory32 {
const WASM_TYPE: Type = <<Self as MemorySize>::Native as NativeWasmType>::WASM_TYPE;
type Abi = <<Self as MemorySize>::Native as NativeWasmType>::Abi;
}
impl NativeWasmType for Memory64 {
const WASM_TYPE: Type = <<Self as MemorySize>::Native as NativeWasmType>::WASM_TYPE;
type Abi = <<Self as MemorySize>::Native as NativeWasmType>::Abi;
}
impl<T: NativeWasmType> NativeWasmType for Option<T> {
const WASM_TYPE: Type = T::WASM_TYPE;
type Abi = T::Abi;
}
}
pub use crate::native::*;