core: Minor changes to IRRT

Add missing documentation, remove redundant lifetime variables, and fix
typos.
This commit is contained in:
David Mak 2024-01-24 18:11:09 +08:00
parent af95ba5012
commit f1581299fc
1 changed files with 19 additions and 14 deletions

View File

@ -552,9 +552,9 @@ pub fn call_j0<'ctx>(
/// ///
/// * `num_dims` - An [IntValue] containing the number of dimensions. /// * `num_dims` - An [IntValue] containing the number of dimensions.
/// * `dims` - A [PointerValue] to an array containing the size of each dimensions. /// * `dims` - A [PointerValue] to an array containing the size of each dimensions.
pub fn call_ndarray_calc_size<'ctx, 'a>( pub fn call_ndarray_calc_size<'ctx>(
generator: &mut dyn CodeGenerator, generator: &dyn CodeGenerator,
ctx: &mut CodeGenContext<'ctx, 'a>, ctx: &mut CodeGenContext<'ctx, '_>,
num_dims: IntValue<'ctx>, num_dims: IntValue<'ctx>,
dims: PointerValue<'ctx>, dims: PointerValue<'ctx>,
) -> IntValue<'ctx> { ) -> IntValue<'ctx> {
@ -563,7 +563,7 @@ pub fn call_ndarray_calc_size<'ctx, 'a>(
let llvm_pi64 = llvm_i64.ptr_type(AddressSpace::default()); let llvm_pi64 = llvm_i64.ptr_type(AddressSpace::default());
let ndarray_calc_size_fn_name = match generator.get_size_type(ctx.ctx).get_bit_width() { let ndarray_calc_size_fn_name = match llvm_usize.get_bit_width() {
32 => "__nac3_ndarray_calc_size", 32 => "__nac3_ndarray_calc_size",
64 => "__nac3_ndarray_calc_size64", 64 => "__nac3_ndarray_calc_size64",
bw => unreachable!("Unsupported size type bit width: {}", bw) bw => unreachable!("Unsupported size type bit width: {}", bw)
@ -600,9 +600,9 @@ pub fn call_ndarray_calc_size<'ctx, 'a>(
/// `NDArray`. /// `NDArray`.
/// * `shape` - LLVM pointer to the `shape` of the NDArray. This value must be the LLVM /// * `shape` - LLVM pointer to the `shape` of the NDArray. This value must be the LLVM
/// representation of a `list`. /// representation of a `list`.
pub fn call_ndarray_init_dims<'ctx, 'a>( pub fn call_ndarray_init_dims<'ctx>(
generator: &mut dyn CodeGenerator, generator: &dyn CodeGenerator,
ctx: &mut CodeGenContext<'ctx, 'a>, ctx: &mut CodeGenContext<'ctx, '_>,
ndarray: PointerValue<'ctx>, ndarray: PointerValue<'ctx>,
shape: PointerValue<'ctx>, shape: PointerValue<'ctx>,
) { ) {
@ -616,7 +616,7 @@ pub fn call_ndarray_init_dims<'ctx, 'a>(
let llvm_pi32 = llvm_i32.ptr_type(AddressSpace::default()); let llvm_pi32 = llvm_i32.ptr_type(AddressSpace::default());
let llvm_pusize = llvm_usize.ptr_type(AddressSpace::default()); let llvm_pusize = llvm_usize.ptr_type(AddressSpace::default());
let ndarray_init_dims_fn_name = match generator.get_size_type(ctx.ctx).get_bit_width() { let ndarray_init_dims_fn_name = match llvm_usize.get_bit_width() {
32 => "__nac3_ndarray_init_dims", 32 => "__nac3_ndarray_init_dims",
64 => "__nac3_ndarray_init_dims64", 64 => "__nac3_ndarray_init_dims64",
bw => unreachable!("Unsupported size type bit width: {}", bw) bw => unreachable!("Unsupported size type bit width: {}", bw)
@ -661,9 +661,14 @@ pub fn call_ndarray_init_dims<'ctx, 'a>(
); );
} }
pub fn call_ndarray_calc_nd_indices<'ctx, 'a>( /// Generates a call to `__nac3_ndarray_calc_nd_indices`.
generator: &mut dyn CodeGenerator, ///
ctx: &mut CodeGenContext<'ctx, 'a>, /// * `index` - The index to compute the multidimensional index for.
/// * `ndarray` - LLVM pointer to the NDArray. This value must be the LLVM representation of an
/// `NDArray`.
pub fn call_ndarray_calc_nd_indices<'ctx>(
generator: &dyn CodeGenerator,
ctx: &mut CodeGenContext<'ctx, '_>,
index: IntValue<'ctx>, index: IntValue<'ctx>,
ndarray: PointerValue<'ctx>, ndarray: PointerValue<'ctx>,
) -> Result<PointerValue<'ctx>, String> { ) -> Result<PointerValue<'ctx>, String> {
@ -675,12 +680,12 @@ pub fn call_ndarray_calc_nd_indices<'ctx, 'a>(
let llvm_pusize = llvm_usize.ptr_type(AddressSpace::default()); let llvm_pusize = llvm_usize.ptr_type(AddressSpace::default());
let ndarray_calc_nd_indices_dn_name = match generator.get_size_type(ctx.ctx).get_bit_width() { let ndarray_calc_nd_indices_fn_name = match llvm_usize.get_bit_width() {
32 => "__nac3_ndarray_calc_nd_indices", 32 => "__nac3_ndarray_calc_nd_indices",
64 => "__nac3_ndarray_calc_nd_indices64", 64 => "__nac3_ndarray_calc_nd_indices64",
bw => unreachable!("Unsupported size type bit width: {}", bw) bw => unreachable!("Unsupported size type bit width: {}", bw)
}; };
let ndarray_calc_nd_indices_fn = ctx.module.get_function(ndarray_calc_nd_indices_dn_name).unwrap_or_else(|| { let ndarray_calc_nd_indices_fn = ctx.module.get_function(ndarray_calc_nd_indices_fn_name).unwrap_or_else(|| {
let fn_type = llvm_void.fn_type( let fn_type = llvm_void.fn_type(
&[ &[
llvm_usize.into(), llvm_usize.into(),
@ -691,7 +696,7 @@ pub fn call_ndarray_calc_nd_indices<'ctx, 'a>(
false, false,
); );
ctx.module.add_function(ndarray_calc_nd_indices_dn_name, fn_type, None) ctx.module.add_function(ndarray_calc_nd_indices_fn_name, fn_type, None)
}); });
let ndarray_num_dims = ctx.build_gep_and_load( let ndarray_num_dims = ctx.build_gep_and_load(