[core] codegen: Update raw_alloca to return PointerValue

Better match the expected behavior of alloca.
This commit is contained in:
David Mak 2024-12-16 13:44:14 +08:00
parent 1b1cb775af
commit 155002629b
8 changed files with 18 additions and 13 deletions

View File

@ -1,7 +1,7 @@
use inkwell::{ use inkwell::{
context::Context, context::Context,
types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType}, types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType},
values::IntValue, values::{IntValue, PointerValue},
AddressSpace, AddressSpace,
}; };
@ -167,7 +167,7 @@ impl<'ctx> ProxyType<'ctx> for ListType<'ctx> {
generator: &mut G, generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>, ctx: &mut CodeGenContext<'ctx, '_>,
name: Option<&'ctx str>, name: Option<&'ctx str>,
) -> <Self::Value as ProxyValue<'ctx>>::Base { ) -> PointerValue<'ctx> {
generator generator
.gen_var_alloc( .gen_var_alloc(
ctx, ctx,

View File

@ -16,7 +16,11 @@
//! the returned object. This is similar to a `new` expression in C++ but the object is allocated //! the returned object. This is similar to a `new` expression in C++ but the object is allocated
//! on the stack. //! on the stack.
use inkwell::{context::Context, types::BasicType, values::IntValue}; use inkwell::{
context::Context,
types::BasicType,
values::{IntValue, PointerValue},
};
use super::{ use super::{
values::{ArraySliceValue, ProxyValue}, values::{ArraySliceValue, ProxyValue},
@ -53,13 +57,14 @@ pub trait ProxyType<'ctx>: Into<Self::Base> {
llvm_ty: Self::Base, llvm_ty: Self::Base,
) -> Result<(), String>; ) -> Result<(), String>;
/// Creates a new value of this type, returning the LLVM instance of this value. /// Creates a new value of this type by invoking `alloca`, returning a [`PointerValue`] instance
/// representing the allocated value.
fn raw_alloca<G: CodeGenerator + ?Sized>( fn raw_alloca<G: CodeGenerator + ?Sized>(
&self, &self,
generator: &mut G, generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>, ctx: &mut CodeGenContext<'ctx, '_>,
name: Option<&'ctx str>, name: Option<&'ctx str>,
) -> <Self::Value as ProxyValue<'ctx>>::Base; ) -> PointerValue<'ctx>;
/// Creates a new array value of this type, returning an [`ArraySliceValue`] encapsulating the /// Creates a new array value of this type, returning an [`ArraySliceValue`] encapsulating the
/// resulting array. /// resulting array.

View File

@ -218,7 +218,7 @@ impl<'ctx> ProxyType<'ctx> for ContiguousNDArrayType<'ctx> {
generator: &mut G, generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>, ctx: &mut CodeGenContext<'ctx, '_>,
name: Option<&'ctx str>, name: Option<&'ctx str>,
) -> <Self::Value as ProxyValue<'ctx>>::Base { ) -> PointerValue<'ctx> {
generator generator
.gen_var_alloc( .gen_var_alloc(
ctx, ctx,

View File

@ -176,7 +176,7 @@ impl<'ctx> ProxyType<'ctx> for NDIndexType<'ctx> {
generator: &mut G, generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>, ctx: &mut CodeGenContext<'ctx, '_>,
name: Option<&'ctx str>, name: Option<&'ctx str>,
) -> <Self::Value as ProxyValue<'ctx>>::Base { ) -> PointerValue<'ctx> {
generator generator
.gen_var_alloc( .gen_var_alloc(
ctx, ctx,

View File

@ -430,7 +430,7 @@ impl<'ctx> ProxyType<'ctx> for NDArrayType<'ctx> {
generator: &mut G, generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>, ctx: &mut CodeGenContext<'ctx, '_>,
name: Option<&'ctx str>, name: Option<&'ctx str>,
) -> <Self::Value as ProxyValue<'ctx>>::Base { ) -> PointerValue<'ctx> {
generator generator
.gen_var_alloc( .gen_var_alloc(
ctx, ctx,

View File

@ -203,7 +203,7 @@ impl<'ctx> ProxyType<'ctx> for NDIterType<'ctx> {
generator: &mut G, generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>, ctx: &mut CodeGenContext<'ctx, '_>,
name: Option<&'ctx str>, name: Option<&'ctx str>,
) -> <Self::Value as ProxyValue<'ctx>>::Base { ) -> PointerValue<'ctx> {
generator generator
.gen_var_alloc( .gen_var_alloc(
ctx, ctx,

View File

@ -1,7 +1,7 @@
use inkwell::{ use inkwell::{
context::Context, context::Context,
types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType}, types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType},
values::IntValue, values::{IntValue, PointerValue},
AddressSpace, AddressSpace,
}; };
@ -131,7 +131,7 @@ impl<'ctx> ProxyType<'ctx> for RangeType<'ctx> {
generator: &mut G, generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>, ctx: &mut CodeGenContext<'ctx, '_>,
name: Option<&'ctx str>, name: Option<&'ctx str>,
) -> <Self::Value as ProxyValue<'ctx>>::Base { ) -> PointerValue<'ctx> {
generator generator
.gen_var_alloc( .gen_var_alloc(
ctx, ctx,

View File

@ -1,7 +1,7 @@
use inkwell::{ use inkwell::{
context::{AsContextRef, Context, ContextRef}, context::{AsContextRef, Context, ContextRef},
types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType}, types::{AnyTypeEnum, BasicType, BasicTypeEnum, IntType, PointerType},
values::IntValue, values::{IntValue, PointerValue},
AddressSpace, AddressSpace,
}; };
use itertools::Itertools; use itertools::Itertools;
@ -215,7 +215,7 @@ impl<'ctx> ProxyType<'ctx> for SliceType<'ctx> {
generator: &mut G, generator: &mut G,
ctx: &mut CodeGenContext<'ctx, '_>, ctx: &mut CodeGenContext<'ctx, '_>,
name: Option<&'ctx str>, name: Option<&'ctx str>,
) -> <Self::Value as ProxyValue<'ctx>>::Base { ) -> PointerValue<'ctx> {
generator generator
.gen_var_alloc( .gen_var_alloc(
ctx, ctx,