use crate::checker::types::TypeStore;
use crate::ir::{self};
use crate::source::Source;
use env::Env;
use inkwell::{builder::Builder, context::Context, module::Module};
mod llvm_cmp_utils;
mod llvm_compile_cmp_eq;
mod llvm_compile_cmp_ge;
mod llvm_compile_cmp_gt;
mod llvm_compile_cmp_le;
mod llvm_compile_cmp_lt;
mod llvm_compile_string;
mod llvm_compile_and;
mod llvm_compile_or;
mod llvm_compile_shl;
mod llvm_compile_shr;
mod llvm_compile_add;
mod llvm_compile_div;
mod llvm_compile_mod;
mod llvm_compile_mul;
mod llvm_compile_sub;
mod llvm_compile_block;
mod llvm_compile_call;
mod llvm_compile_function;
mod llvm_compile_instr;
mod llvm_compile_jmp;
mod llvm_compile_jmp_if;
mod llvm_compile_drop;
mod llvm_compile_getptr;
mod llvm_compile_halloc;
mod llvm_compile_load;
mod llvm_compile_ret;
mod llvm_compile_salloc;
mod llvm_compile_set;
mod llvm_memory;
mod llvm_compile_struct;
mod env;
mod llvm_compile_type;
mod llvm_compile_value;
pub fn create_module_from_source<'ll>(ctx: &'ll Context, source: &Source) -> Module<'ll> {
let module = ctx.create_module(source.file_name());
module
}
pub struct Llvm<'ll> {
pub ctx: &'ll Context,
pub module: Module<'ll>,
pub builder: Builder<'ll>,
pub env: Env<'ll>,
pub type_store: &'ll TypeStore,
}
impl<'ll> Llvm<'ll> {
pub fn new(ctx: &'ll Context, module: Module<'ll>, type_store: &'ll TypeStore) -> Self {
let builder = ctx.create_builder();
let env = Env::new();
Self { ctx, module, builder, type_store, env }
}
pub fn compile_ir(&mut self, root: &ir::IR) {
root.structs.iter().for_each(|struct_def| {
self.llvm_compile_struct(struct_def);
});
root.functions.iter().for_each(|function| {
self.llvm_compile_function(function);
});
}
}