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
use crate::vmcontext::{
VMContext, VMFunctionBody, VMGlobalDefinition, VMMemoryDefinition, VMTableDefinition,
};
use cranelift_codegen::ir;
use cranelift_wasm::Global;
use wasmtime_environ::{MemoryPlan, TablePlan};
/// The value of an export passed from one instance to another.
#[derive(Debug, Clone)]
pub enum Export {
/// A function export value.
Function {
/// The address of the native-code function.
address: *const VMFunctionBody,
/// Pointer to the containing `VMContext`.
vmctx: *mut VMContext,
/// The function signature declaration, used for compatibilty checking.
signature: ir::Signature,
},
/// A table export value.
Table {
/// The address of the table descriptor.
definition: *mut VMTableDefinition,
/// Pointer to the containing `VMContext`.
vmctx: *mut VMContext,
/// The table declaration, used for compatibilty checking.
table: TablePlan,
},
/// A memory export value.
Memory {
/// The address of the memory descriptor.
definition: *mut VMMemoryDefinition,
/// Pointer to the containing `VMContext`.
vmctx: *mut VMContext,
/// The memory declaration, used for compatibilty checking.
memory: MemoryPlan,
},
/// A global export value.
Global {
/// The address of the global storage.
definition: *mut VMGlobalDefinition,
/// Pointer to the containing `VMContext`.
vmctx: *mut VMContext,
/// The global declaration, used for compatibilty checking.
global: Global,
},
}
impl Export {
/// Construct a function export value.
pub fn function(
address: *const VMFunctionBody,
vmctx: *mut VMContext,
signature: ir::Signature,
) -> Self {
Export::Function {
address,
vmctx,
signature,
}
}
/// Construct a table export value.
pub fn table(
definition: *mut VMTableDefinition,
vmctx: *mut VMContext,
table: TablePlan,
) -> Self {
Export::Table {
definition,
vmctx,
table,
}
}
/// Construct a memory export value.
pub fn memory(
definition: *mut VMMemoryDefinition,
vmctx: *mut VMContext,
memory: MemoryPlan,
) -> Self {
Export::Memory {
definition,
vmctx,
memory,
}
}
/// Construct a global export value.
pub fn global(
definition: *mut VMGlobalDefinition,
vmctx: *mut VMContext,
global: Global,
) -> Self {
Export::Global {
definition,
vmctx,
global,
}
}
}