diff --git a/nac3core/src/codegen/model/core.rs b/nac3core/src/codegen/model/core.rs index bcc4a6b7..117b1352 100644 --- a/nac3core/src/codegen/model/core.rs +++ b/nac3core/src/codegen/model/core.rs @@ -1,10 +1,10 @@ use inkwell::{ context::Context, types::{AnyTypeEnum, BasicTypeEnum}, - values::{AnyValue, AnyValueEnum, BasicValueEnum}, + values::{AnyValue, AnyValueEnum, BasicValueEnum, PointerValue}, }; -use crate::codegen::CodeGenContext; +use crate::codegen::{CodeGenContext, CodeGenerator}; use super::{slice::ArraySlice, Int, Pointer}; @@ -89,4 +89,30 @@ pub trait Model<'ctx>: Clone + Copy + CanCheckLLVMType<'ctx> + Sized { }, } } + + /// Do [`CodeGenerator::gen_var_alloc`] with the LLVM type of this [`Model<'ctx>`]. + fn var_alloc( + &self, + generator: &mut G, + ctx: &mut CodeGenContext<'ctx, '_>, + name: Option<&str>, + ) -> Result, String> { + let value = generator.gen_var_alloc(ctx, self.get_llvm_type(ctx.ctx), name)?; + Ok(Pointer { element: *self, value }) + } + + /// Do [`CodeGenerator::gen_array_var_alloc`] with the LLVM type of this [`Model<'ctx>`]. + fn array_var_alloc( + &self, + generator: &mut G, + ctx: &mut CodeGenContext<'ctx, '_>, + size: Int<'ctx>, + name: Option<&'ctx str>, + ) -> Result, String> { + let slice = + generator.gen_array_var_alloc(ctx, self.get_llvm_type(ctx.ctx), size.0, name)?; + let ptr = PointerValue::from(slice); // TODO: Remove ArraySliceValue + + Ok(Pointer { element: *self, value: ptr }) + } }