diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index c110d0c..5102049 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -42,6 +42,7 @@ use itertools::{chain, izip, Itertools, Either}; use nac3parser::ast::{ self, Boolop, Comprehension, Constant, Expr, ExprKind, Location, Operator, StrRef, }; +use crate::codegen::classes::ArraySliceValue; use super::{CodeGenerator, llvm_intrinsics::call_memcpy_generic, need_sret}; @@ -1265,12 +1266,14 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>( } else { return Ok(None) }; + let index_addr = generator.gen_var_alloc(ctx, index.get_type().into(), None)?; + ctx.builder.build_store(index_addr, index).unwrap(); Ok(Some(v.data() .get( ctx, generator, - ctx.ctx.i32_type().const_array(&[index]), + ArraySliceValue::from_ptr_val(index_addr, llvm_usize.const_int(1, false), None), None, ) .into())) @@ -1286,6 +1289,8 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>( } else { return Ok(None) }; + let index_addr = generator.gen_var_alloc(ctx, index.get_type().into(), None)?; + ctx.builder.build_store(index_addr, index).unwrap(); // Create a new array, remove the top dimension from the dimension-size-list, and copy the // elements over @@ -1340,7 +1345,7 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>( let v_data_src_ptr = v.data().ptr_offset( ctx, generator, - ctx.ctx.i32_type().const_array(&[index]), + ArraySliceValue::from_ptr_val(index_addr, llvm_usize.const_int(1, false), None), None ); call_memcpy_generic( diff --git a/nac3core/src/codegen/irrt/mod.rs b/nac3core/src/codegen/irrt/mod.rs index 005de18..6da048f 100644 --- a/nac3core/src/codegen/irrt/mod.rs +++ b/nac3core/src/codegen/irrt/mod.rs @@ -8,7 +8,6 @@ use super::{ ListValue, NDArrayValue, TypedArrayLikeAdapter, - UntypedArrayLikeMutator, }, CodeGenContext, CodeGenerator, @@ -19,7 +18,7 @@ use inkwell::{ memory_buffer::MemoryBuffer, module::Module, types::{BasicTypeEnum, IntType}, - values::{ArrayValue, BasicValueEnum, CallSiteValue, FloatValue, IntValue}, + values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue}, AddressSpace, IntPredicate, }; use itertools::Either; @@ -784,47 +783,4 @@ pub fn call_ndarray_flatten_index<'ctx, G, Index>( ndarray, indices, ) -} -/// Generates a call to `__nac3_ndarray_flatten_index`. Returns the flattened index for the -/// multidimensional index. -/// -/// * `ndarray` - LLVM pointer to the `NDArray`. This value must be the LLVM representation of an -/// `NDArray`. -/// * `indices` - The multidimensional index to compute the flattened index for. -pub fn call_ndarray_flatten_index_const<'ctx, G: CodeGenerator + ?Sized>( - generator: &mut G, - ctx: &mut CodeGenContext<'ctx, '_>, - ndarray: NDArrayValue<'ctx>, - indices: ArrayValue<'ctx>, -) -> IntValue<'ctx> { - let llvm_usize = generator.get_size_type(ctx.ctx); - - let indices_size = indices.get_type().len(); - let indices_alloca = generator.gen_array_var_alloc( - ctx, - indices.get_type().get_element_type(), - llvm_usize.const_int(indices_size as u64, false), - None, - ).unwrap(); - for i in 0..indices_size { - let v = ctx.builder.build_extract_value(indices, i, "") - .unwrap() - .into_int_value(); - - unsafe { - indices_alloca.set_unchecked( - ctx, - generator, - ctx.ctx.i32_type().const_int(i as u64, false), - v.into(), - ); - } - } - - call_ndarray_flatten_index_impl( - generator, - ctx, - ndarray, - &indices_alloca, - ) } \ No newline at end of file