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
use cranelift_codegen::ir;
use cranelift_wasm::{
FunctionIndex, Global, GlobalIndex, Memory, MemoryIndex, SignatureIndex, Table, TableIndex,
};
use std::collections::HashMap;
#[derive(Clone, Debug)]
pub struct TableElements {
pub table_index: TableIndex,
pub base: Option<GlobalIndex>,
pub offset: usize,
pub elements: Vec<FunctionIndex>,
}
#[derive(Clone, Debug)]
pub enum Export {
Function(FunctionIndex),
Table(TableIndex),
Memory(MemoryIndex),
Global(GlobalIndex),
}
#[derive(Debug)]
pub struct Module {
pub signatures: Vec<ir::Signature>,
pub imported_funcs: Vec<(String, String)>,
pub functions: Vec<SignatureIndex>,
pub tables: Vec<Table>,
pub memories: Vec<Memory>,
pub globals: Vec<Global>,
pub exports: HashMap<String, Export>,
pub start_func: Option<FunctionIndex>,
pub table_elements: Vec<TableElements>,
}
impl Module {
pub fn new() -> Self {
Self {
signatures: Vec::new(),
imported_funcs: Vec::new(),
functions: Vec::new(),
tables: Vec::new(),
memories: Vec::new(),
globals: Vec::new(),
exports: HashMap::new(),
start_func: None,
table_elements: Vec::new(),
}
}
}
pub struct DataInitializer<'data> {
pub memory_index: MemoryIndex,
pub base: Option<GlobalIndex>,
pub offset: usize,
pub data: &'data [u8],
}
pub struct LazyContents<'data> {
pub function_body_inputs: Vec<&'data [u8]>,
pub data_initializers: Vec<DataInitializer<'data>>,
}
impl<'data> LazyContents<'data> {
pub fn new() -> Self {
Self {
function_body_inputs: Vec::new(),
data_initializers: Vec::new(),
}
}
}