diff --git a/src/generator/llvm.rs b/src/generator/llvm.rs index 7d54c0b..f2e71c3 100644 --- a/src/generator/llvm.rs +++ b/src/generator/llvm.rs @@ -4,6 +4,7 @@ use inkwell::builder::Builder; use inkwell::context::Context; use inkwell::module::Module; use inkwell::targets::{InitializationConfig, Target}; +use inkwell::types::*; pub struct LLVMGenerator<'ctx> { ctx: &'ctx Context, @@ -27,13 +28,25 @@ impl<'ctx> Generator for LLVMGenerator<'ctx> { impl<'ctx> LLVMGenerator<'ctx> { fn generate_function(&mut self, func: Function) { - dbg!(&func); - let ret_type = match func.ret_type { - Some(Type::Int) => self.ctx.i32_type().fn_type(&[], false), - Some(Type::Bool) => self.ctx.bool_type().fn_type(&[], false), - None => self.ctx.void_type().fn_type(&[], false), + let arg_types: Vec = func + .arguments + .iter() + .map(|arg| match arg.ty { + Some(Type::Int) => self.ctx.i32_type().as_basic_type_enum(), + Some(Type::Bool) => self.ctx.bool_type().as_basic_type_enum(), + Some(Type::Any) => todo!(), + Some(Type::Str) => todo!(), + Some(Type::Array(_)) => todo!(), + None => panic!("Function argument has no type"), + }) + .collect(); + + let func_type = match func.ret_type { + Some(Type::Int) => self.ctx.i32_type().fn_type(&arg_types, false), + Some(Type::Bool) => self.ctx.bool_type().fn_type(&arg_types, false), + None => self.ctx.void_type().fn_type(&arg_types, false), _ => todo!(), }; - self.module.add_function(&func.name, ret_type, None); + self.module.add_function(&func.name, func_type, None); } }