[core] codegen: Rename classes/functions for consistency

- ContiguousNDArrayFields -> ContiguousNDArrayStructFields
- ndarray/nditer: Add _field suffix to field accessors
This commit is contained in:
David Mak 2024-12-13 16:35:34 +08:00
parent 318371a509
commit 19122e2905
2 changed files with 14 additions and 11 deletions

View File

@ -31,7 +31,7 @@ pub struct ContiguousNDArrayType<'ctx> {
} }
#[derive(PartialEq, Eq, Clone, Copy, StructFields)] #[derive(PartialEq, Eq, Clone, Copy, StructFields)]
pub struct ContiguousNDArrayFields<'ctx> { pub struct ContiguousNDArrayStructFields<'ctx> {
#[value_type(usize)] #[value_type(usize)]
pub ndims: StructField<'ctx, IntValue<'ctx>>, pub ndims: StructField<'ctx, IntValue<'ctx>>,
#[value_type(usize.ptr_type(AddressSpace::default()))] #[value_type(usize.ptr_type(AddressSpace::default()))]
@ -40,12 +40,12 @@ pub struct ContiguousNDArrayFields<'ctx> {
pub data: StructField<'ctx, PointerValue<'ctx>>, pub data: StructField<'ctx, PointerValue<'ctx>>,
} }
impl<'ctx> ContiguousNDArrayFields<'ctx> { impl<'ctx> ContiguousNDArrayStructFields<'ctx> {
#[must_use] #[must_use]
pub fn new_typed(item: BasicTypeEnum<'ctx>, llvm_usize: IntType<'ctx>) -> Self { pub fn new_typed(item: BasicTypeEnum<'ctx>, llvm_usize: IntType<'ctx>) -> Self {
let mut counter = FieldIndexCounter::default(); let mut counter = FieldIndexCounter::default();
ContiguousNDArrayFields { ContiguousNDArrayStructFields {
ndims: StructField::create(&mut counter, "ndims", llvm_usize), ndims: StructField::create(&mut counter, "ndims", llvm_usize),
shape: StructField::create( shape: StructField::create(
&mut counter, &mut counter,
@ -72,7 +72,7 @@ impl<'ctx> ContiguousNDArrayType<'ctx> {
)); ));
}; };
let fields = ContiguousNDArrayFields::new(ctx, llvm_usize); let fields = ContiguousNDArrayStructFields::new(ctx, llvm_usize);
check_struct_type_matches_fields( check_struct_type_matches_fields(
fields, fields,
@ -93,14 +93,14 @@ impl<'ctx> ContiguousNDArrayType<'ctx> {
fn fields( fn fields(
item: BasicTypeEnum<'ctx>, item: BasicTypeEnum<'ctx>,
llvm_usize: IntType<'ctx>, llvm_usize: IntType<'ctx>,
) -> ContiguousNDArrayFields<'ctx> { ) -> ContiguousNDArrayStructFields<'ctx> {
ContiguousNDArrayFields::new_typed(item, llvm_usize) ContiguousNDArrayStructFields::new_typed(item, llvm_usize)
} }
/// See [`NDArrayType::fields`]. /// See [`NDArrayType::fields`].
// TODO: Move this into e.g. StructProxyType // TODO: Move this into e.g. StructProxyType
#[must_use] #[must_use]
pub fn get_fields(&self) -> ContiguousNDArrayFields<'ctx> { pub fn get_fields(&self) -> ContiguousNDArrayStructFields<'ctx> {
Self::fields(self.item, self.llvm_usize) Self::fields(self.item, self.llvm_usize)
} }

View File

@ -69,7 +69,10 @@ impl<'ctx> NDIterValue<'ctx> {
irrt::ndarray::call_nac3_nditer_next(generator, ctx, *self); irrt::ndarray::call_nac3_nditer_next(generator, ctx, *self);
} }
fn element(&self, ctx: &CodeGenContext<'ctx, '_>) -> StructField<'ctx, PointerValue<'ctx>> { fn element_field(
&self,
ctx: &CodeGenContext<'ctx, '_>,
) -> StructField<'ctx, PointerValue<'ctx>> {
self.get_type().get_fields(ctx.ctx).element self.get_type().get_fields(ctx.ctx).element
} }
@ -78,7 +81,7 @@ impl<'ctx> NDIterValue<'ctx> {
pub fn get_pointer(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> { pub fn get_pointer(&self, ctx: &CodeGenContext<'ctx, '_>) -> PointerValue<'ctx> {
let elem_ty = self.parent.dtype; let elem_ty = self.parent.dtype;
let p = self.element(ctx).get(ctx, self.as_base_value(), self.name); let p = self.element_field(ctx).get(ctx, self.as_base_value(), self.name);
ctx.builder ctx.builder
.build_pointer_cast(p, elem_ty.ptr_type(AddressSpace::default()), "element") .build_pointer_cast(p, elem_ty.ptr_type(AddressSpace::default()), "element")
.unwrap() .unwrap()
@ -91,14 +94,14 @@ impl<'ctx> NDIterValue<'ctx> {
ctx.builder.build_load(p, "value").unwrap() ctx.builder.build_load(p, "value").unwrap()
} }
fn nth(&self, ctx: &CodeGenContext<'ctx, '_>) -> StructField<'ctx, IntValue<'ctx>> { fn nth_field(&self, ctx: &CodeGenContext<'ctx, '_>) -> StructField<'ctx, IntValue<'ctx>> {
self.get_type().get_fields(ctx.ctx).nth self.get_type().get_fields(ctx.ctx).nth
} }
/// Get the index of the current element if this ndarray were a flat ndarray. /// Get the index of the current element if this ndarray were a flat ndarray.
#[must_use] #[must_use]
pub fn get_index(&self, ctx: &CodeGenContext<'ctx, '_>) -> IntValue<'ctx> { pub fn get_index(&self, ctx: &CodeGenContext<'ctx, '_>) -> IntValue<'ctx> {
self.nth(ctx).get(ctx, self.as_base_value(), self.name) self.nth_field(ctx).get(ctx, self.as_base_value(), self.name)
} }
/// Get the indices of the current element. /// Get the indices of the current element.