From 5f940f86d9c2ae928fb7a0f5754f331d42640fc6 Mon Sep 17 00:00:00 2001 From: David Mak Date: Mon, 25 Nov 2024 14:59:10 +0800 Subject: [PATCH] [artiq] Fix obtaining ndarray struct from NDArrayType --- nac3artiq/src/symbol_resolver.rs | 35 +++++++++++++++++++------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/nac3artiq/src/symbol_resolver.rs b/nac3artiq/src/symbol_resolver.rs index 4aeaaf15..9e29acf8 100644 --- a/nac3artiq/src/symbol_resolver.rs +++ b/nac3artiq/src/symbol_resolver.rs @@ -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, );