core/classes: Rename get_* functions to remove prefix

As suggested by Rust API Guidelines.
This commit is contained in:
David Mak 2024-03-13 11:41:25 +08:00
parent 84a888758a
commit c8866b1534
5 changed files with 89 additions and 89 deletions

View File

@ -67,19 +67,19 @@ impl<'ctx> ListValue<'ctx> {
/// Returns the underlying [`PointerValue`] pointing to the `list` instance. /// Returns the underlying [`PointerValue`] pointing to the `list` instance.
#[must_use] #[must_use]
pub fn get_ptr(&self) -> PointerValue<'ctx> { pub fn as_ptr_value(&self) -> PointerValue<'ctx> {
self.0 self.0
} }
/// Returns the double-indirection pointer to the `data` array, as if by calling `getelementptr` /// Returns the double-indirection pointer to the `data` array, as if by calling `getelementptr`
/// on the field. /// on the field.
fn get_data_pptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { fn pptr_to_data(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let var_name = self.1.map(|v| format!("{v}.data.addr")).unwrap_or_default(); let var_name = self.1.map(|v| format!("{v}.data.addr")).unwrap_or_default();
unsafe { unsafe {
ctx.builder.build_in_bounds_gep( ctx.builder.build_in_bounds_gep(
self.get_ptr(), self.as_ptr_value(),
&[llvm_i32.const_zero(), llvm_i32.const_zero()], &[llvm_i32.const_zero(), llvm_i32.const_zero()],
var_name.as_str(), var_name.as_str(),
).unwrap() ).unwrap()
@ -87,7 +87,7 @@ impl<'ctx> ListValue<'ctx> {
} }
/// Returns the pointer to the field storing the size of this `list`. /// Returns the pointer to the field storing the size of this `list`.
fn get_size_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { fn ptr_to_size(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let var_name = self.1.map(|v| format!("{v}.size.addr")).unwrap_or_default(); let var_name = self.1.map(|v| format!("{v}.size.addr")).unwrap_or_default();
@ -102,7 +102,7 @@ impl<'ctx> ListValue<'ctx> {
/// Stores the array of data elements `data` into this instance. /// Stores the array of data elements `data` into this instance.
fn store_data(&self, ctx: &CodeGenContext<'ctx, '_>, data: PointerValue<'ctx>) { fn store_data(&self, ctx: &CodeGenContext<'ctx, '_>, data: PointerValue<'ctx>) {
ctx.builder.build_store(self.get_data_pptr(ctx), data).unwrap(); ctx.builder.build_store(self.pptr_to_data(ctx), data).unwrap();
} }
/// Convenience method for creating a new array storing data elements with the given element /// Convenience method for creating a new array storing data elements with the given element
@ -122,7 +122,7 @@ impl<'ctx> ListValue<'ctx> {
/// Returns the double-indirection pointer to the `data` array, as if by calling `getelementptr` /// Returns the double-indirection pointer to the `data` array, as if by calling `getelementptr`
/// on the field. /// on the field.
#[must_use] #[must_use]
pub fn get_data(&self) -> ListDataProxy<'ctx> { pub fn data(&self) -> ListDataProxy<'ctx> {
ListDataProxy(*self) ListDataProxy(*self)
} }
@ -135,13 +135,13 @@ impl<'ctx> ListValue<'ctx> {
) { ) {
debug_assert_eq!(size.get_type(), generator.get_size_type(ctx.ctx)); debug_assert_eq!(size.get_type(), generator.get_size_type(ctx.ctx));
let psize = self.get_size_ptr(ctx); let psize = self.ptr_to_size(ctx);
ctx.builder.build_store(psize, size).unwrap(); ctx.builder.build_store(psize, size).unwrap();
} }
/// Returns the size of this `list` as a value. /// Returns the size of this `list` as a value.
pub fn load_size(&self, ctx: &CodeGenContext<'ctx, '_>, name: Option<&str>) -> IntValue<'ctx> { pub fn load_size(&self, ctx: &CodeGenContext<'ctx, '_>, name: Option<&str>) -> IntValue<'ctx> {
let psize = self.get_size_ptr(ctx); let psize = self.ptr_to_size(ctx);
let var_name = name let var_name = name
.map(ToString::to_string) .map(ToString::to_string)
.or_else(|| self.1.map(|v| format!("{v}.size"))) .or_else(|| self.1.map(|v| format!("{v}.size")))
@ -155,7 +155,7 @@ impl<'ctx> ListValue<'ctx> {
impl<'ctx> From<ListValue<'ctx>> for PointerValue<'ctx> { impl<'ctx> From<ListValue<'ctx>> for PointerValue<'ctx> {
fn from(value: ListValue<'ctx>) -> Self { fn from(value: ListValue<'ctx>) -> Self {
value.get_ptr() value.as_ptr_value()
} }
} }
@ -165,10 +165,10 @@ pub struct ListDataProxy<'ctx>(ListValue<'ctx>);
impl<'ctx> ListDataProxy<'ctx> { impl<'ctx> ListDataProxy<'ctx> {
/// Returns the single-indirection pointer to the array. /// Returns the single-indirection pointer to the array.
pub fn get_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { pub fn as_ptr_value(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let var_name = self.0.1.map(|v| format!("{v}.data")).unwrap_or_default(); let var_name = self.0.1.map(|v| format!("{v}.data")).unwrap_or_default();
ctx.builder.build_load(self.0.get_data_pptr(ctx), var_name.as_str()) ctx.builder.build_load(self.0.pptr_to_data(ctx), var_name.as_str())
.map(BasicValueEnum::into_pointer_value) .map(BasicValueEnum::into_pointer_value)
.unwrap() .unwrap()
} }
@ -187,7 +187,7 @@ impl<'ctx> ListDataProxy<'ctx> {
.unwrap_or_default(); .unwrap_or_default();
ctx.builder.build_in_bounds_gep( ctx.builder.build_in_bounds_gep(
self.get_ptr(ctx), self.as_ptr_value(ctx),
&[idx], &[idx],
var_name.as_str(), var_name.as_str(),
).unwrap() ).unwrap()
@ -295,11 +295,11 @@ impl<'ctx> RangeValue<'ctx> {
/// Returns the underlying [`PointerValue`] pointing to the `range` instance. /// Returns the underlying [`PointerValue`] pointing to the `range` instance.
#[must_use] #[must_use]
pub fn get_ptr(&self) -> PointerValue<'ctx> { pub fn as_ptr_value(&self) -> PointerValue<'ctx> {
self.0 self.0
} }
fn get_start_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { fn ptr_to_start(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let var_name = self.1.map(|v| format!("{v}.start.addr")).unwrap_or_default(); let var_name = self.1.map(|v| format!("{v}.start.addr")).unwrap_or_default();
@ -312,7 +312,7 @@ impl<'ctx> RangeValue<'ctx> {
} }
} }
fn get_end_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { fn ptr_to_end(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let var_name = self.1.map(|v| format!("{v}.end.addr")).unwrap_or_default(); let var_name = self.1.map(|v| format!("{v}.end.addr")).unwrap_or_default();
@ -325,7 +325,7 @@ impl<'ctx> RangeValue<'ctx> {
} }
} }
fn get_step_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { fn ptr_to_step(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let var_name = self.1.map(|v| format!("{v}.step.addr")).unwrap_or_default(); let var_name = self.1.map(|v| format!("{v}.step.addr")).unwrap_or_default();
@ -346,13 +346,13 @@ impl<'ctx> RangeValue<'ctx> {
) { ) {
debug_assert_eq!(start.get_type().get_bit_width(), 32); debug_assert_eq!(start.get_type().get_bit_width(), 32);
let pstart = self.get_start_ptr(ctx); let pstart = self.ptr_to_start(ctx);
ctx.builder.build_store(pstart, start).unwrap(); ctx.builder.build_store(pstart, start).unwrap();
} }
/// Returns the `start` value of this `range`. /// Returns the `start` value of this `range`.
pub fn load_start(&self, ctx: &CodeGenContext<'ctx, '_>, name: Option<&str>) -> IntValue<'ctx> { pub fn load_start(&self, ctx: &CodeGenContext<'ctx, '_>, name: Option<&str>) -> IntValue<'ctx> {
let pstart = self.get_start_ptr(ctx); let pstart = self.ptr_to_start(ctx);
let var_name = name let var_name = name
.map(ToString::to_string) .map(ToString::to_string)
.or_else(|| self.1.map(|v| format!("{v}.start"))) .or_else(|| self.1.map(|v| format!("{v}.start")))
@ -371,13 +371,13 @@ impl<'ctx> RangeValue<'ctx> {
) { ) {
debug_assert_eq!(end.get_type().get_bit_width(), 32); debug_assert_eq!(end.get_type().get_bit_width(), 32);
let pend = self.get_start_ptr(ctx); let pend = self.ptr_to_start(ctx);
ctx.builder.build_store(pend, end).unwrap(); ctx.builder.build_store(pend, end).unwrap();
} }
/// Returns the `end` value of this `range`. /// Returns the `end` value of this `range`.
pub fn load_end(&self, ctx: &CodeGenContext<'ctx, '_>, name: Option<&str>) -> IntValue<'ctx> { pub fn load_end(&self, ctx: &CodeGenContext<'ctx, '_>, name: Option<&str>) -> IntValue<'ctx> {
let pend = self.get_end_ptr(ctx); let pend = self.ptr_to_end(ctx);
let var_name = name let var_name = name
.map(ToString::to_string) .map(ToString::to_string)
.or_else(|| self.1.map(|v| format!("{v}.end"))) .or_else(|| self.1.map(|v| format!("{v}.end")))
@ -396,13 +396,13 @@ impl<'ctx> RangeValue<'ctx> {
) { ) {
debug_assert_eq!(step.get_type().get_bit_width(), 32); debug_assert_eq!(step.get_type().get_bit_width(), 32);
let pstep = self.get_start_ptr(ctx); let pstep = self.ptr_to_start(ctx);
ctx.builder.build_store(pstep, step).unwrap(); ctx.builder.build_store(pstep, step).unwrap();
} }
/// Returns the `step` value of this `range`. /// Returns the `step` value of this `range`.
pub fn load_step(&self, ctx: &CodeGenContext<'ctx, '_>, name: Option<&str>) -> IntValue<'ctx> { pub fn load_step(&self, ctx: &CodeGenContext<'ctx, '_>, name: Option<&str>) -> IntValue<'ctx> {
let pstep = self.get_step_ptr(ctx); let pstep = self.ptr_to_step(ctx);
let var_name = name let var_name = name
.map(ToString::to_string) .map(ToString::to_string)
.or_else(|| self.1.map(|v| format!("{v}.step"))) .or_else(|| self.1.map(|v| format!("{v}.step")))
@ -416,7 +416,7 @@ impl<'ctx> RangeValue<'ctx> {
impl<'ctx> From<RangeValue<'ctx>> for PointerValue<'ctx> { impl<'ctx> From<RangeValue<'ctx>> for PointerValue<'ctx> {
fn from(value: RangeValue<'ctx>) -> Self { fn from(value: RangeValue<'ctx>) -> Self {
value.get_ptr() value.as_ptr_value()
} }
} }
@ -494,12 +494,12 @@ impl<'ctx> NDArrayValue<'ctx> {
/// Returns the underlying [`PointerValue`] pointing to the `NDArray` instance. /// Returns the underlying [`PointerValue`] pointing to the `NDArray` instance.
#[must_use] #[must_use]
pub fn get_ptr(&self) -> PointerValue<'ctx> { pub fn as_ptr_value(&self) -> PointerValue<'ctx> {
self.0 self.0
} }
/// Returns the pointer to the field storing the number of dimensions of this `NDArray`. /// Returns the pointer to the field storing the number of dimensions of this `NDArray`.
fn get_ndims(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { fn ptr_to_ndims(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let var_name = self.1.map(|v| format!("{v}.ndims.addr")).unwrap_or_default(); let var_name = self.1.map(|v| format!("{v}.ndims.addr")).unwrap_or_default();
@ -521,13 +521,13 @@ impl<'ctx> NDArrayValue<'ctx> {
) { ) {
debug_assert_eq!(ndims.get_type(), generator.get_size_type(ctx.ctx)); debug_assert_eq!(ndims.get_type(), generator.get_size_type(ctx.ctx));
let pndims = self.get_ndims(ctx); let pndims = self.ptr_to_ndims(ctx);
ctx.builder.build_store(pndims, ndims).unwrap(); ctx.builder.build_store(pndims, ndims).unwrap();
} }
/// Returns the number of dimensions of this `NDArray` as a value. /// Returns the number of dimensions of this `NDArray` as a value.
pub fn load_ndims(&self, ctx: &CodeGenContext<'ctx, '_>) -> IntValue<'ctx> { pub fn load_ndims(&self, ctx: &CodeGenContext<'ctx, '_>) -> IntValue<'ctx> {
let pndims = self.get_ndims(ctx); let pndims = self.ptr_to_ndims(ctx);
ctx.builder.build_load(pndims, "") ctx.builder.build_load(pndims, "")
.map(BasicValueEnum::into_int_value) .map(BasicValueEnum::into_int_value)
.unwrap() .unwrap()
@ -535,13 +535,13 @@ impl<'ctx> NDArrayValue<'ctx> {
/// Returns the double-indirection pointer to the `dims` array, as if by calling `getelementptr` /// Returns the double-indirection pointer to the `dims` array, as if by calling `getelementptr`
/// on the field. /// on the field.
fn get_dims_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { fn ptr_to_dims(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let var_name = self.1.map(|v| format!("{v}.dims.addr")).unwrap_or_default(); let var_name = self.1.map(|v| format!("{v}.dims.addr")).unwrap_or_default();
unsafe { unsafe {
ctx.builder.build_in_bounds_gep( ctx.builder.build_in_bounds_gep(
self.get_ptr(), self.as_ptr_value(),
&[llvm_i32.const_zero(), llvm_i32.const_int(1, true)], &[llvm_i32.const_zero(), llvm_i32.const_int(1, true)],
var_name.as_str(), var_name.as_str(),
).unwrap() ).unwrap()
@ -549,35 +549,35 @@ impl<'ctx> NDArrayValue<'ctx> {
} }
/// Stores the array of dimension sizes `dims` into this instance. /// Stores the array of dimension sizes `dims` into this instance.
fn store_dims(&self, ctx: &CodeGenContext<'ctx, '_>, dims: PointerValue<'ctx>) { fn store_dim_sizes(&self, ctx: &CodeGenContext<'ctx, '_>, dims: PointerValue<'ctx>) {
ctx.builder.build_store(self.get_dims_ptr(ctx), dims).unwrap(); ctx.builder.build_store(self.ptr_to_dims(ctx), dims).unwrap();
} }
/// Convenience method for creating a new array storing dimension sizes with the given `size`. /// Convenience method for creating a new array storing dimension sizes with the given `size`.
pub fn create_dims( pub fn create_dim_sizes(
&self, &self,
ctx: &CodeGenContext<'ctx, '_>, ctx: &CodeGenContext<'ctx, '_>,
llvm_usize: IntType<'ctx>, llvm_usize: IntType<'ctx>,
size: IntValue<'ctx>, size: IntValue<'ctx>,
) { ) {
self.store_dims(ctx, ctx.builder.build_array_alloca(llvm_usize, size, "").unwrap()); self.store_dim_sizes(ctx, ctx.builder.build_array_alloca(llvm_usize, size, "").unwrap());
} }
/// Returns a proxy object to the field storing the size of each dimension of this `NDArray`. /// Returns a proxy object to the field storing the size of each dimension of this `NDArray`.
#[must_use] #[must_use]
pub fn get_dims(&self) -> NDArrayDimsProxy<'ctx> { pub fn dim_sizes(&self) -> NDArrayDimsProxy<'ctx> {
NDArrayDimsProxy(*self) NDArrayDimsProxy(*self)
} }
/// Returns the double-indirection pointer to the `data` array, as if by calling `getelementptr` /// Returns the double-indirection pointer to the `data` array, as if by calling `getelementptr`
/// on the field. /// on the field.
fn get_data_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { fn ptr_to_data(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let llvm_i32 = ctx.ctx.i32_type(); let llvm_i32 = ctx.ctx.i32_type();
let var_name = self.1.map(|v| format!("{v}.data.addr")).unwrap_or_default(); let var_name = self.1.map(|v| format!("{v}.data.addr")).unwrap_or_default();
unsafe { unsafe {
ctx.builder.build_in_bounds_gep( ctx.builder.build_in_bounds_gep(
self.get_ptr(), self.as_ptr_value(),
&[llvm_i32.const_zero(), llvm_i32.const_int(2, true)], &[llvm_i32.const_zero(), llvm_i32.const_int(2, true)],
var_name.as_str(), var_name.as_str(),
).unwrap() ).unwrap()
@ -586,7 +586,7 @@ impl<'ctx> NDArrayValue<'ctx> {
/// Stores the array of data elements `data` into this instance. /// Stores the array of data elements `data` into this instance.
fn store_data(&self, ctx: &CodeGenContext<'ctx, '_>, data: PointerValue<'ctx>) { fn store_data(&self, ctx: &CodeGenContext<'ctx, '_>, data: PointerValue<'ctx>) {
ctx.builder.build_store(self.get_data_ptr(ctx), data).unwrap(); ctx.builder.build_store(self.ptr_to_data(ctx), data).unwrap();
} }
/// Convenience method for creating a new array storing data elements with the given element /// Convenience method for creating a new array storing data elements with the given element
@ -602,14 +602,14 @@ impl<'ctx> NDArrayValue<'ctx> {
/// Returns a proxy object to the field storing the data of this `NDArray`. /// Returns a proxy object to the field storing the data of this `NDArray`.
#[must_use] #[must_use]
pub fn get_data(&self) -> NDArrayDataProxy<'ctx> { pub fn data(&self) -> NDArrayDataProxy<'ctx> {
NDArrayDataProxy(*self) NDArrayDataProxy(*self)
} }
} }
impl<'ctx> From<NDArrayValue<'ctx>> for PointerValue<'ctx> { impl<'ctx> From<NDArrayValue<'ctx>> for PointerValue<'ctx> {
fn from(value: NDArrayValue<'ctx>) -> Self { fn from(value: NDArrayValue<'ctx>) -> Self {
value.get_ptr() value.as_ptr_value()
} }
} }
@ -619,10 +619,10 @@ pub struct NDArrayDimsProxy<'ctx>(NDArrayValue<'ctx>);
impl<'ctx> NDArrayDimsProxy<'ctx> { impl<'ctx> NDArrayDimsProxy<'ctx> {
/// Returns the single-indirection pointer to the array. /// Returns the single-indirection pointer to the array.
pub fn get_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { pub fn as_ptr_value(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let var_name = self.0.1.map(|v| format!("{v}.dims")).unwrap_or_default(); let var_name = self.0.1.map(|v| format!("{v}.dims")).unwrap_or_default();
ctx.builder.build_load(self.0.get_dims_ptr(ctx), var_name.as_str()) ctx.builder.build_load(self.0.ptr_to_dims(ctx), var_name.as_str())
.map(BasicValueEnum::into_pointer_value) .map(BasicValueEnum::into_pointer_value)
.unwrap() .unwrap()
} }
@ -656,7 +656,7 @@ impl<'ctx> NDArrayDimsProxy<'ctx> {
unsafe { unsafe {
ctx.builder.build_in_bounds_gep( ctx.builder.build_in_bounds_gep(
self.get_ptr(ctx), self.as_ptr_value(ctx),
&[idx], &[idx],
var_name.as_str(), var_name.as_str(),
).unwrap() ).unwrap()
@ -684,10 +684,10 @@ pub struct NDArrayDataProxy<'ctx>(NDArrayValue<'ctx>);
impl<'ctx> NDArrayDataProxy<'ctx> { impl<'ctx> NDArrayDataProxy<'ctx> {
/// Returns the single-indirection pointer to the array. /// Returns the single-indirection pointer to the array.
pub fn get_ptr(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { pub fn as_ptr_value(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let var_name = self.0.1.map(|v| format!("{v}.data")).unwrap_or_default(); let var_name = self.0.1.map(|v| format!("{v}.data")).unwrap_or_default();
ctx.builder.build_load(self.0.get_data_ptr(ctx), var_name.as_str()) ctx.builder.build_load(self.0.ptr_to_data(ctx), var_name.as_str())
.map(BasicValueEnum::into_pointer_value) .map(BasicValueEnum::into_pointer_value)
.unwrap() .unwrap()
} }
@ -702,7 +702,7 @@ impl<'ctx> NDArrayDataProxy<'ctx> {
name: Option<&str>, name: Option<&str>,
) -> PointerValue<'ctx> { ) -> PointerValue<'ctx> {
ctx.builder.build_in_bounds_gep( ctx.builder.build_in_bounds_gep(
self.get_ptr(ctx), self.as_ptr_value(ctx),
&[idx], &[idx],
name.unwrap_or_default(), name.unwrap_or_default(),
).unwrap() ).unwrap()
@ -717,7 +717,7 @@ impl<'ctx> NDArrayDataProxy<'ctx> {
name: Option<&str>, name: Option<&str>,
) -> PointerValue<'ctx> { ) -> PointerValue<'ctx> {
let ndims = self.0.load_ndims(ctx); let ndims = self.0.load_ndims(ctx);
let dims = self.0.get_dims().get_ptr(ctx); let dims = self.0.dim_sizes().as_ptr_value(ctx);
let data_sz = call_ndarray_calc_size(generator, ctx, ndims, dims); let data_sz = call_ndarray_calc_size(generator, ctx, ndims, dims);
let in_range = ctx.builder.build_int_compare( let in_range = ctx.builder.build_int_compare(
@ -775,7 +775,7 @@ impl<'ctx> NDArrayDataProxy<'ctx> {
indices: ListValue<'ctx>, indices: ListValue<'ctx>,
name: Option<&str>, name: Option<&str>,
) -> PointerValue<'ctx> { ) -> PointerValue<'ctx> {
let indices_elem_ty = indices.get_data().get_ptr(ctx).get_type().get_element_type(); let indices_elem_ty = indices.data().as_ptr_value(ctx).get_type().get_element_type();
let Ok(indices_elem_ty) = IntType::try_from(indices_elem_ty) else { let Ok(indices_elem_ty) = IntType::try_from(indices_elem_ty) else {
panic!("Expected list[int32] but got {indices_elem_ty}") panic!("Expected list[int32] but got {indices_elem_ty}")
}; };
@ -790,7 +790,7 @@ impl<'ctx> NDArrayDataProxy<'ctx> {
unsafe { unsafe {
ctx.builder.build_in_bounds_gep( ctx.builder.build_in_bounds_gep(
self.get_ptr(ctx), self.as_ptr_value(ctx),
&[index], &[index],
name.unwrap_or_default(), name.unwrap_or_default(),
).unwrap() ).unwrap()
@ -816,7 +816,7 @@ impl<'ctx> NDArrayDataProxy<'ctx> {
unsafe { unsafe {
ctx.builder.build_in_bounds_gep( ctx.builder.build_in_bounds_gep(
self.get_ptr(ctx), self.as_ptr_value(ctx),
&[index], &[index],
name.unwrap_or_default(), name.unwrap_or_default(),
) )
@ -862,7 +862,7 @@ impl<'ctx> NDArrayDataProxy<'ctx> {
.map(BasicValueEnum::into_int_value) .map(BasicValueEnum::into_int_value)
.map(|v| ctx.builder.build_int_z_extend_or_bit_cast(v, llvm_usize, "").unwrap()) .map(|v| ctx.builder.build_int_z_extend_or_bit_cast(v, llvm_usize, "").unwrap())
.unwrap(); .unwrap();
let dim_sz = self.0.get_dims().get(ctx, generator, i, None); let dim_sz = self.0.dim_sizes().get(ctx, generator, i, None);
let dim_lt = ctx.builder.build_int_compare( let dim_lt = ctx.builder.build_int_compare(
IntPredicate::SLT, IntPredicate::SLT,
@ -937,8 +937,8 @@ impl<'ctx> NDArrayDataProxy<'ctx> {
.unwrap(); .unwrap();
let (dim_idx, dim_sz) = unsafe { let (dim_idx, dim_sz) = unsafe {
( (
indices.get_data().get_unchecked(ctx, i, None).into_int_value(), indices.data().get_unchecked(ctx, i, None).into_int_value(),
self.0.get_dims().get(ctx, generator, i, None), self.0.dim_sizes().get(ctx, generator, i, None),
) )
}; };

View File

@ -978,7 +978,7 @@ pub fn gen_comprehension<'ctx, G: CodeGenerator>(
list_alloc_size.into_int_value(), list_alloc_size.into_int_value(),
Some("listcomp.addr") Some("listcomp.addr")
); );
list_content = list.get_data().get_ptr(ctx); list_content = list.data().as_ptr_value(ctx);
let i = generator.gen_store_target(ctx, target, Some("i.addr"))?.unwrap(); let i = generator.gen_store_target(ctx, target, Some("i.addr"))?.unwrap();
ctx.builder ctx.builder
@ -1011,7 +1011,7 @@ pub fn gen_comprehension<'ctx, G: CodeGenerator>(
) )
.into_int_value(); .into_int_value();
list = allocate_list(generator, ctx, elem_ty, length, Some("listcomp")); list = allocate_list(generator, ctx, elem_ty, length, Some("listcomp"));
list_content = list.get_data().get_ptr(ctx); list_content = list.data().as_ptr_value(ctx);
let counter = generator.gen_var_alloc(ctx, size_t.into(), Some("counter.addr"))?; let counter = generator.gen_var_alloc(ctx, size_t.into(), Some("counter.addr"))?;
// counter = -1 // counter = -1
ctx.builder.build_store(counter, size_t.const_int(u64::MAX, true)).unwrap(); ctx.builder.build_store(counter, size_t.const_int(u64::MAX, true)).unwrap();
@ -1075,7 +1075,7 @@ pub fn gen_comprehension<'ctx, G: CodeGenerator>(
emit_cont_bb(ctx, generator, list); emit_cont_bb(ctx, generator, list);
Ok(Some(list.get_ptr().into())) Ok(Some(list.as_ptr_value().into()))
} }
/// Generates LLVM IR for a [binary operator expression][expr]. /// Generates LLVM IR for a [binary operator expression][expr].
@ -1255,7 +1255,7 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
return Ok(None) return Ok(None)
}; };
Ok(Some(v.get_data() Ok(Some(v.data()
.get_const( .get_const(
ctx, ctx,
generator, generator,
@ -1297,10 +1297,10 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
); );
let ndarray_num_dims = ndarray.load_ndims(ctx); let ndarray_num_dims = ndarray.load_ndims(ctx);
ndarray.create_dims(ctx, llvm_usize, ndarray_num_dims); ndarray.create_dim_sizes(ctx, llvm_usize, ndarray_num_dims);
let ndarray_num_dims = ndarray.load_ndims(ctx); let ndarray_num_dims = ndarray.load_ndims(ctx);
let v_dims_src_ptr = v.get_dims().ptr_offset( let v_dims_src_ptr = v.dim_sizes().ptr_offset(
ctx, ctx,
generator, generator,
llvm_usize.const_int(1, false), llvm_usize.const_int(1, false),
@ -1308,7 +1308,7 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
); );
call_memcpy_generic( call_memcpy_generic(
ctx, ctx,
ndarray.get_dims().get_ptr(ctx), ndarray.dim_sizes().as_ptr_value(ctx),
v_dims_src_ptr, v_dims_src_ptr,
ctx.builder ctx.builder
.build_int_mul(ndarray_num_dims, llvm_usize.size_of(), "") .build_int_mul(ndarray_num_dims, llvm_usize.size_of(), "")
@ -1321,11 +1321,11 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
generator, generator,
ctx, ctx,
ndarray.load_ndims(ctx), ndarray.load_ndims(ctx),
ndarray.get_dims().get_ptr(ctx), ndarray.dim_sizes().as_ptr_value(ctx),
); );
ndarray.create_data(ctx, llvm_ndarray_data_t, ndarray_num_elems); ndarray.create_data(ctx, llvm_ndarray_data_t, ndarray_num_elems);
let v_data_src_ptr = v.get_data().ptr_offset_const( let v_data_src_ptr = v.data().ptr_offset_const(
ctx, ctx,
generator, generator,
ctx.ctx.i32_type().const_array(&[index]), ctx.ctx.i32_type().const_array(&[index]),
@ -1333,7 +1333,7 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
); );
call_memcpy_generic( call_memcpy_generic(
ctx, ctx,
ndarray.get_data().get_ptr(ctx), ndarray.data().as_ptr_value(ctx),
v_data_src_ptr, v_data_src_ptr,
ctx.builder ctx.builder
.build_int_mul(ndarray_num_elems, llvm_ndarray_data_t.size_of().unwrap(), "") .build_int_mul(ndarray_num_elems, llvm_ndarray_data_t.size_of().unwrap(), "")
@ -1342,7 +1342,7 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
llvm_i1.const_zero(), llvm_i1.const_zero(),
); );
Ok(Some(ndarray.get_ptr().into())) Ok(Some(ndarray.as_ptr_value().into()))
} }
} }
@ -1425,13 +1425,13 @@ pub fn gen_expr<'ctx, G: CodeGenerator>(
}; };
let length = generator.get_size_type(ctx.ctx).const_int(elements.len() as u64, false); let length = generator.get_size_type(ctx.ctx).const_int(elements.len() as u64, false);
let arr_str_ptr = allocate_list(generator, ctx, ty, length, Some("list")); let arr_str_ptr = allocate_list(generator, ctx, ty, length, Some("list"));
let arr_ptr = arr_str_ptr.get_data(); let arr_ptr = arr_str_ptr.data();
for (i, v) in elements.iter().enumerate() { for (i, v) in elements.iter().enumerate() {
let elem_ptr = arr_ptr let elem_ptr = arr_ptr
.ptr_offset(ctx, generator, usize.const_int(i as u64, false), Some("elem_ptr")); .ptr_offset(ctx, generator, usize.const_int(i as u64, false), Some("elem_ptr"));
ctx.builder.build_store(elem_ptr, *v).unwrap(); ctx.builder.build_store(elem_ptr, *v).unwrap();
} }
arr_str_ptr.get_ptr().into() arr_str_ptr.as_ptr_value().into()
} }
ExprKind::Tuple { elts, .. } => { ExprKind::Tuple { elts, .. } => {
let elements_val = elts let elements_val = elts
@ -1924,7 +1924,7 @@ pub fn gen_expr<'ctx, G: CodeGenerator>(
v, v,
(start, end, step), (start, end, step),
); );
res_array_ret.get_ptr().into() res_array_ret.as_ptr_value().into()
} else { } else {
let len = v.load_size(ctx, Some("len")); let len = v.load_size(ctx, Some("len"));
let raw_index = if let Some(v) = generator.gen_expr(ctx, slice)? { let raw_index = if let Some(v) = generator.gen_expr(ctx, slice)? {
@ -1966,7 +1966,7 @@ pub fn gen_expr<'ctx, G: CodeGenerator>(
[Some(raw_index), Some(len), None], [Some(raw_index), Some(len), None],
expr.location, expr.location,
); );
v.get_data().get(ctx, generator, index, None).into() v.data().get(ctx, generator, index, None).into()
} }
} }
TypeEnum::TObj { obj_id, params, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => { TypeEnum::TObj { obj_id, params, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {

View File

@ -338,7 +338,7 @@ pub fn list_slice_assignment<'ctx>(
let zero = int32.const_zero(); let zero = int32.const_zero();
let one = int32.const_int(1, false); let one = int32.const_int(1, false);
let dest_arr_ptr = dest_arr.get_data().get_ptr(ctx); let dest_arr_ptr = dest_arr.data().as_ptr_value(ctx);
let dest_arr_ptr = ctx.builder.build_pointer_cast( let dest_arr_ptr = ctx.builder.build_pointer_cast(
dest_arr_ptr, dest_arr_ptr,
elem_ptr_type, elem_ptr_type,
@ -346,7 +346,7 @@ pub fn list_slice_assignment<'ctx>(
).unwrap(); ).unwrap();
let dest_len = dest_arr.load_size(ctx, Some("dest.len")); let dest_len = dest_arr.load_size(ctx, Some("dest.len"));
let dest_len = ctx.builder.build_int_truncate_or_bit_cast(dest_len, int32, "srclen32").unwrap(); let dest_len = ctx.builder.build_int_truncate_or_bit_cast(dest_len, int32, "srclen32").unwrap();
let src_arr_ptr = src_arr.get_data().get_ptr(ctx); let src_arr_ptr = src_arr.data().as_ptr_value(ctx);
let src_arr_ptr = ctx.builder.build_pointer_cast( let src_arr_ptr = ctx.builder.build_pointer_cast(
src_arr_ptr, src_arr_ptr,
elem_ptr_type, elem_ptr_type,
@ -653,7 +653,7 @@ pub fn call_ndarray_calc_nd_indices<'ctx>(
}); });
let ndarray_num_dims = ndarray.load_ndims(ctx); let ndarray_num_dims = ndarray.load_ndims(ctx);
let ndarray_dims = ndarray.get_dims(); let ndarray_dims = ndarray.dim_sizes();
let indices = ctx.builder.build_array_alloca( let indices = ctx.builder.build_array_alloca(
llvm_usize, llvm_usize,
@ -666,7 +666,7 @@ pub fn call_ndarray_calc_nd_indices<'ctx>(
ndarray_calc_nd_indices_fn, ndarray_calc_nd_indices_fn,
&[ &[
index.into(), index.into(),
ndarray_dims.get_ptr(ctx).into(), ndarray_dims.as_ptr_value(ctx).into(),
ndarray_num_dims.into(), ndarray_num_dims.into(),
indices.into(), indices.into(),
], ],
@ -723,13 +723,13 @@ fn call_ndarray_flatten_index_impl<'ctx>(
}); });
let ndarray_num_dims = ndarray.load_ndims(ctx); let ndarray_num_dims = ndarray.load_ndims(ctx);
let ndarray_dims = ndarray.get_dims(); let ndarray_dims = ndarray.dim_sizes();
let index = ctx.builder let index = ctx.builder
.build_call( .build_call(
ndarray_flatten_index_fn, ndarray_flatten_index_fn,
&[ &[
ndarray_dims.get_ptr(ctx).into(), ndarray_dims.as_ptr_value(ctx).into(),
ndarray_num_dims.into(), ndarray_num_dims.into(),
indices.into(), indices.into(),
indices_size.into(), indices_size.into(),
@ -757,13 +757,13 @@ pub fn call_ndarray_flatten_index<'ctx>(
indices: ListValue<'ctx>, indices: ListValue<'ctx>,
) -> IntValue<'ctx> { ) -> IntValue<'ctx> {
let indices_size = indices.load_size(ctx, None); let indices_size = indices.load_size(ctx, None);
let indices_data = indices.get_data(); let indices_data = indices.data();
call_ndarray_flatten_index_impl( call_ndarray_flatten_index_impl(
generator, generator,
ctx, ctx,
ndarray, ndarray,
indices_data.get_ptr(ctx), indices_data.as_ptr_value(ctx),
indices_size, indices_size,
) )
} }

View File

@ -188,7 +188,7 @@ pub fn gen_store_target<'ctx, G: CodeGenerator>(
[Some(raw_index), Some(len), None], [Some(raw_index), Some(len), None],
slice.location, slice.location,
); );
v.get_data().ptr_offset(ctx, generator, index, name) v.data().ptr_offset(ctx, generator, index, name)
} }
TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => { TypeEnum::TObj { obj_id, .. } if *obj_id == PRIMITIVE_DEF_IDS.ndarray => {

View File

@ -170,7 +170,7 @@ fn create_ndarray_dyn_shape<'ctx, 'a, V, LenFn, DataFn>(
ndarray.store_ndims(ctx, generator, num_dims); ndarray.store_ndims(ctx, generator, num_dims);
let ndarray_num_dims = ndarray.load_ndims(ctx); let ndarray_num_dims = ndarray.load_ndims(ctx);
ndarray.create_dims(ctx, llvm_usize, ndarray_num_dims); ndarray.create_dim_sizes(ctx, llvm_usize, ndarray_num_dims);
// Copy the dimension sizes from shape to ndarray.dims // Copy the dimension sizes from shape to ndarray.dims
gen_for_callback( gen_for_callback(
@ -203,7 +203,7 @@ fn create_ndarray_dyn_shape<'ctx, 'a, V, LenFn, DataFn>(
.build_int_z_extend(shape_dim, llvm_usize, "") .build_int_z_extend(shape_dim, llvm_usize, "")
.unwrap(); .unwrap();
let ndarray_pdim = ndarray.get_dims().ptr_offset(ctx, generator, i, None); let ndarray_pdim = ndarray.dim_sizes().ptr_offset(ctx, generator, i, None);
ctx.builder.build_store(ndarray_pdim, shape_dim).unwrap(); ctx.builder.build_store(ndarray_pdim, shape_dim).unwrap();
@ -225,7 +225,7 @@ fn create_ndarray_dyn_shape<'ctx, 'a, V, LenFn, DataFn>(
generator, generator,
ctx, ctx,
ndarray.load_ndims(ctx), ndarray.load_ndims(ctx),
ndarray.get_dims().get_ptr(ctx), ndarray.dim_sizes().as_ptr_value(ctx),
); );
ndarray.create_data(ctx, llvm_ndarray_data_t, ndarray_num_elems); ndarray.create_data(ctx, llvm_ndarray_data_t, ndarray_num_elems);
@ -282,11 +282,11 @@ fn create_ndarray_const_shape<'ctx>(
ndarray.store_ndims(ctx, generator, num_dims); ndarray.store_ndims(ctx, generator, num_dims);
let ndarray_num_dims = ndarray.load_ndims(ctx); let ndarray_num_dims = ndarray.load_ndims(ctx);
ndarray.create_dims(ctx, llvm_usize, ndarray_num_dims); ndarray.create_dim_sizes(ctx, llvm_usize, ndarray_num_dims);
for i in 0..shape.get_type().len() { for i in 0..shape.get_type().len() {
let ndarray_dim = ndarray let ndarray_dim = ndarray
.get_dims() .dim_sizes()
.ptr_offset(ctx, generator, llvm_usize.const_int(i as u64, true), None); .ptr_offset(ctx, generator, llvm_usize.const_int(i as u64, true), None);
let shape_dim = ctx.builder.build_extract_value(shape, i, "") let shape_dim = ctx.builder.build_extract_value(shape, i, "")
.map(BasicValueEnum::into_int_value) .map(BasicValueEnum::into_int_value)
@ -295,7 +295,7 @@ fn create_ndarray_const_shape<'ctx>(
ctx.builder.build_store(ndarray_dim, shape_dim).unwrap(); ctx.builder.build_store(ndarray_dim, shape_dim).unwrap();
} }
let ndarray_dims = ndarray.get_dims().get_ptr(ctx); let ndarray_dims = ndarray.dim_sizes().as_ptr_value(ctx);
let ndarray_num_elems = call_ndarray_calc_size( let ndarray_num_elems = call_ndarray_calc_size(
generator, generator,
ctx, ctx,
@ -368,7 +368,7 @@ fn call_ndarray_empty_impl<'ctx>(
Ok(shape.load_size(ctx, None)) Ok(shape.load_size(ctx, None))
}, },
|generator, ctx, shape, idx| { |generator, ctx, shape, idx| {
Ok(shape.get_data().get(ctx, generator, idx, None).into_int_value()) Ok(shape.data().get(ctx, generator, idx, None).into_int_value())
}, },
) )
} }
@ -390,7 +390,7 @@ fn ndarray_fill_flattened<'ctx, 'a, ValueFn>(
generator, generator,
ctx, ctx,
ndarray.load_ndims(ctx), ndarray.load_ndims(ctx),
ndarray.get_dims().get_ptr(ctx), ndarray.dim_sizes().as_ptr_value(ctx),
); );
gen_for_callback( gen_for_callback(
@ -416,7 +416,7 @@ fn ndarray_fill_flattened<'ctx, 'a, ValueFn>(
.map(BasicValueEnum::into_int_value) .map(BasicValueEnum::into_int_value)
.unwrap(); .unwrap();
let elem = unsafe { let elem = unsafe {
ndarray.get_data().ptr_to_data_flattened_unchecked(ctx, i, None) ndarray.data().ptr_to_data_flattened_unchecked(ctx, i, None)
}; };
let value = value_fn(generator, ctx, i)?; let value = value_fn(generator, ctx, i)?;
@ -674,7 +674,7 @@ fn ndarray_copy_impl<'ctx>(
Ok(shape.load_ndims(ctx)) Ok(shape.load_ndims(ctx))
}, },
|generator, ctx, shape, idx| { |generator, ctx, shape, idx| {
Ok(shape.get_dims().get(ctx, generator, idx, None)) Ok(shape.dim_sizes().get(ctx, generator, idx, None))
}, },
)?; )?;
@ -682,7 +682,7 @@ fn ndarray_copy_impl<'ctx>(
generator, generator,
ctx, ctx,
ndarray.load_ndims(ctx), ndarray.load_ndims(ctx),
ndarray.get_dims().get_ptr(ctx), ndarray.dim_sizes().as_ptr_value(ctx),
); );
let sizeof_ty = ctx.get_llvm_type(generator, elem_ty); let sizeof_ty = ctx.get_llvm_type(generator, elem_ty);
let len_bytes = ctx.builder let len_bytes = ctx.builder
@ -695,8 +695,8 @@ fn ndarray_copy_impl<'ctx>(
call_memcpy_generic( call_memcpy_generic(
ctx, ctx,
ndarray.get_data().get_ptr(ctx), ndarray.data().as_ptr_value(ctx),
this.get_data().get_ptr(ctx), this.data().as_ptr_value(ctx),
len_bytes, len_bytes,
llvm_i1.const_zero(), llvm_i1.const_zero(),
); );