core: Remove ArrayValue variants of accessors
This commit is contained in:
parent
2b0beea8c0
commit
1de2e9a4be
|
@ -42,6 +42,7 @@ use itertools::{chain, izip, Itertools, Either};
|
||||||
use nac3parser::ast::{
|
use nac3parser::ast::{
|
||||||
self, Boolop, Comprehension, Constant, Expr, ExprKind, Location, Operator, StrRef,
|
self, Boolop, Comprehension, Constant, Expr, ExprKind, Location, Operator, StrRef,
|
||||||
};
|
};
|
||||||
|
use crate::codegen::classes::ArraySliceValue;
|
||||||
|
|
||||||
use super::{CodeGenerator, llvm_intrinsics::call_memcpy_generic, need_sret};
|
use super::{CodeGenerator, llvm_intrinsics::call_memcpy_generic, need_sret};
|
||||||
|
|
||||||
|
@ -1265,12 +1266,14 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
|
||||||
} else {
|
} else {
|
||||||
return Ok(None)
|
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()
|
Ok(Some(v.data()
|
||||||
.get(
|
.get(
|
||||||
ctx,
|
ctx,
|
||||||
generator,
|
generator,
|
||||||
ctx.ctx.i32_type().const_array(&[index]),
|
ArraySliceValue::from_ptr_val(index_addr, llvm_usize.const_int(1, false), None),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
.into()))
|
.into()))
|
||||||
|
@ -1286,6 +1289,8 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
|
||||||
} else {
|
} else {
|
||||||
return Ok(None)
|
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
|
// Create a new array, remove the top dimension from the dimension-size-list, and copy the
|
||||||
// elements over
|
// elements over
|
||||||
|
@ -1340,7 +1345,7 @@ fn gen_ndarray_subscript_expr<'ctx, G: CodeGenerator>(
|
||||||
let v_data_src_ptr = v.data().ptr_offset(
|
let v_data_src_ptr = v.data().ptr_offset(
|
||||||
ctx,
|
ctx,
|
||||||
generator,
|
generator,
|
||||||
ctx.ctx.i32_type().const_array(&[index]),
|
ArraySliceValue::from_ptr_val(index_addr, llvm_usize.const_int(1, false), None),
|
||||||
None
|
None
|
||||||
);
|
);
|
||||||
call_memcpy_generic(
|
call_memcpy_generic(
|
||||||
|
|
|
@ -8,7 +8,6 @@ use super::{
|
||||||
ListValue,
|
ListValue,
|
||||||
NDArrayValue,
|
NDArrayValue,
|
||||||
TypedArrayLikeAdapter,
|
TypedArrayLikeAdapter,
|
||||||
UntypedArrayLikeMutator,
|
|
||||||
},
|
},
|
||||||
CodeGenContext,
|
CodeGenContext,
|
||||||
CodeGenerator,
|
CodeGenerator,
|
||||||
|
@ -19,7 +18,7 @@ use inkwell::{
|
||||||
memory_buffer::MemoryBuffer,
|
memory_buffer::MemoryBuffer,
|
||||||
module::Module,
|
module::Module,
|
||||||
types::{BasicTypeEnum, IntType},
|
types::{BasicTypeEnum, IntType},
|
||||||
values::{ArrayValue, BasicValueEnum, CallSiteValue, FloatValue, IntValue},
|
values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue},
|
||||||
AddressSpace, IntPredicate,
|
AddressSpace, IntPredicate,
|
||||||
};
|
};
|
||||||
use itertools::Either;
|
use itertools::Either;
|
||||||
|
@ -785,46 +784,3 @@ pub fn call_ndarray_flatten_index<'ctx, G, Index>(
|
||||||
indices,
|
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,
|
|
||||||
)
|
|
||||||
}
|
|
Loading…
Reference in New Issue