[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

View File

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