forked from M-Labs/nac3
1
0
Fork 0

[artiq] Fix obtaining ndarray struct from NDArrayType

This commit is contained in:
David Mak 2024-11-25 14:59:10 +08:00
parent 5651e00688
commit 5f940f86d9
1 changed files with 21 additions and 14 deletions

View File

@ -14,7 +14,10 @@ use pyo3::{
};
use nac3core::{
codegen::{types::NDArrayType, CodeGenContext, CodeGenerator},
codegen::{
types::{NDArrayType, ProxyType},
CodeGenContext, CodeGenerator,
},
inkwell::{
module::Linkage,
types::{BasicType, BasicTypeEnum},
@ -1093,7 +1096,7 @@ impl InnerResolver {
if self.global_value_ids.read().contains_key(&id) {
let global = ctx.module.get_global(&id_str).unwrap_or_else(|| {
ctx.module.add_global(
ndarray_llvm_ty.element_type().into_struct_type(),
ndarray_llvm_ty.as_base_type().get_element_type().into_struct_type(),
Some(AddressSpace::default()),
&id_str,
)
@ -1187,20 +1190,24 @@ impl InnerResolver {
data_global.set_initializer(&data);
// create a global for the ndarray object and initialize it
let value = ndarray_llvm_ty.element_type().into_struct_type().const_named_struct(&[
llvm_usize.const_int(ndarray_ndims, false).into(),
shape_global
.as_pointer_value()
.const_cast(llvm_usize.ptr_type(AddressSpace::default()))
.into(),
data_global
.as_pointer_value()
.const_cast(ndarray_dtype_llvm_ty.ptr_type(AddressSpace::default()))
.into(),
]);
let value = ndarray_llvm_ty
.as_base_type()
.get_element_type()
.into_struct_type()
.const_named_struct(&[
llvm_usize.const_int(ndarray_ndims, false).into(),
shape_global
.as_pointer_value()
.const_cast(llvm_usize.ptr_type(AddressSpace::default()))
.into(),
data_global
.as_pointer_value()
.const_cast(ndarray_dtype_llvm_ty.ptr_type(AddressSpace::default()))
.into(),
]);
let ndarray = ctx.module.add_global(
ndarray_llvm_ty.element_type().into_struct_type(),
ndarray_llvm_ty.as_base_type().get_element_type().into_struct_type(),
Some(AddressSpace::default()),
&id_str,
);