forked from M-Labs/nac3
core/model: add var_alloc & array_var_alloc
This commit is contained in:
parent
2525369760
commit
db9e9586b5
|
@ -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<G: CodeGenerator + ?Sized>(
|
||||
&self,
|
||||
generator: &mut G,
|
||||
ctx: &mut CodeGenContext<'ctx, '_>,
|
||||
name: Option<&str>,
|
||||
) -> Result<Pointer<'ctx, Self>, 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<G: CodeGenerator + ?Sized>(
|
||||
&self,
|
||||
generator: &mut G,
|
||||
ctx: &mut CodeGenContext<'ctx, '_>,
|
||||
size: Int<'ctx>,
|
||||
name: Option<&'ctx str>,
|
||||
) -> Result<Pointer<'ctx, Self>, 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 })
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue