cardinal_codegen/
module.rs1use crate::entities::{AbiType, GlobalVariable};
6use crate::function::{Function, FunctionSignature};
7use std::collections::HashMap;
8
9pub struct Module {
11
12 pub functions: HashMap<String, Function>,
14
15 pub data: HashMap<String, AbiType>,
17
18}
19
20impl Module {
21
22 pub fn new() -> Self {
24 Self {
25 functions: HashMap::new(),
26 data: HashMap::new(),
27 }
28 }
29
30 pub fn declare_function(&mut self, name: String) {
32 let func = Function::new(name.to_string(), FunctionSignature::new());
33 self.functions.insert(name, func);
34 }
35
36 pub fn define_function(&mut self, func: Function) {
38 self.functions.insert(func.name.to_string(), func);
39 }
40
41 pub fn declare_variable(&mut self, name: String, val_type: AbiType) -> GlobalVariable {
43 self.data.insert(name.to_string(), val_type);
44 GlobalVariable(name)
45 }
46
47}