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
use crate::error::CompileError;
use crate::function::Compilation;
use crate::lib::std::boxed::Box;
use crate::lib::std::sync::Arc;
use crate::module::CompileModuleInfo;
use crate::target::Target;
use crate::translator::ModuleMiddleware;
use crate::FunctionBodyData;
use crate::ModuleTranslationState;
use crate::SectionIndex;
use loupe::MemoryUsage;
use wasmer_types::entity::PrimaryMap;
use wasmer_types::{Features, FunctionIndex, LocalFunctionIndex, SignatureIndex};
use wasmparser::{Validator, WasmFeatures};
pub trait CompilerConfig {
fn enable_pic(&mut self) {
}
fn enable_verifier(&mut self) {
}
#[deprecated(note = "Please use the canonicalize_nans instead")]
fn enable_nan_canonicalization(&mut self) {
}
fn canonicalize_nans(&mut self, _enable: bool) {
}
fn compiler(self: Box<Self>) -> Box<dyn Compiler>;
fn default_features_for_target(&self, _target: &Target) -> Features {
Features::default()
}
fn push_middleware(&mut self, middleware: Arc<dyn ModuleMiddleware>);
}
impl<T> From<T> for Box<dyn CompilerConfig + 'static>
where
T: CompilerConfig + 'static,
{
fn from(other: T) -> Self {
Box::new(other)
}
}
pub trait Compiler: Send + MemoryUsage {
fn validate_module<'data>(
&self,
features: &Features,
data: &'data [u8],
) -> Result<(), CompileError> {
let mut validator = Validator::new();
let wasm_features = WasmFeatures {
bulk_memory: features.bulk_memory,
threads: features.threads,
reference_types: features.reference_types,
multi_value: features.multi_value,
simd: features.simd,
tail_call: features.tail_call,
module_linking: features.module_linking,
multi_memory: features.multi_memory,
memory64: features.memory64,
exceptions: features.exceptions,
deterministic_only: false,
};
validator.wasm_features(wasm_features);
validator
.validate_all(data)
.map_err(|e| CompileError::Validate(format!("{}", e)))?;
Ok(())
}
fn compile_module<'data, 'module>(
&self,
target: &Target,
module: &'module CompileModuleInfo,
module_translation: &ModuleTranslationState,
function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'data>>,
) -> Result<Compilation, CompileError>;
fn experimental_native_compile_module<'data, 'module>(
&self,
_target: &Target,
_module: &'module CompileModuleInfo,
_module_translation: &ModuleTranslationState,
_function_body_inputs: &PrimaryMap<LocalFunctionIndex, FunctionBodyData<'data>>,
_symbol_registry: &dyn SymbolRegistry,
_wasmer_metadata: &[u8],
) -> Option<Result<Vec<u8>, CompileError>> {
None
}
fn get_middlewares(&self) -> &[Arc<dyn ModuleMiddleware>];
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Symbol {
LocalFunction(LocalFunctionIndex),
Section(SectionIndex),
FunctionCallTrampoline(SignatureIndex),
DynamicFunctionTrampoline(FunctionIndex),
}
pub trait SymbolRegistry: Send + Sync {
fn symbol_to_name(&self, symbol: Symbol) -> String;
fn name_to_symbol(&self, name: &str) -> Option<Symbol>;
}