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
use crate::entities::{AbiType, GlobalVariable};
use crate::function::{Function, FunctionSignature};
use std::collections::HashMap;
pub struct Module {
pub functions: HashMap<String, Function>,
pub data: HashMap<String, AbiType>,
}
impl Module {
pub fn new() -> Self {
Self {
functions: HashMap::new(),
data: HashMap::new(),
}
}
pub fn declare_function(&mut self, name: String) {
let func = Function::new(name.to_string(), FunctionSignature::new());
self.functions.insert(name, func);
}
pub fn define_function(&mut self, func: Function) {
self.functions.insert(func.name.to_string(), func);
}
pub fn declare_variable(&mut self, name: String, val_type: AbiType) -> GlobalVariable {
self.data.insert(name.to_string(), val_type);
GlobalVariable(name)
}
}