Browse Source

feat: llvm: generate argument types

c_for-loops
Garrit Franke 12 months ago
parent
commit
727c8d1e72
  1. 25
      src/generator/llvm.rs

25
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<BasicTypeEnum> = 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);
}
}

Loading…
Cancel
Save