forked from M-Labs/nac3
Add string registration in NAC
This commit is contained in:
parent
3d087160ca
commit
29130d3ef4
@ -1081,10 +1081,7 @@ impl InnerResolver {
|
|||||||
arr_global.set_initializer(&arr);
|
arr_global.set_initializer(&arr);
|
||||||
|
|
||||||
let val = arr_ty.const_named_struct(&[
|
let val = arr_ty.const_named_struct(&[
|
||||||
arr_global
|
arr_global.as_pointer_value().const_cast(ty.ptr_type(AddressSpace::default())).into(),
|
||||||
.as_pointer_value()
|
|
||||||
.const_cast(ty.ptr_type(AddressSpace::default()))
|
|
||||||
.into(),
|
|
||||||
size_t.const_int(len as u64, false).into(),
|
size_t.const_int(len as u64, false).into(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -1144,10 +1141,8 @@ impl InnerResolver {
|
|||||||
super::CompileError::new_err(format!("Error getting element {i}: {e}"))
|
super::CompileError::new_err(format!("Error getting element {i}: {e}"))
|
||||||
})?
|
})?
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let value = ctx
|
let value =
|
||||||
.builder
|
ctx.builder.build_int_z_extend(value.into_int_value(), llvm_usize, "").unwrap();
|
||||||
.build_int_z_extend(value.into_int_value(), llvm_usize, "")
|
|
||||||
.unwrap();
|
|
||||||
Ok(value)
|
Ok(value)
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, PyErr>>()?;
|
.collect::<Result<Vec<_>, PyErr>>()?;
|
||||||
@ -1178,9 +1173,7 @@ impl InnerResolver {
|
|||||||
let value = self
|
let value = self
|
||||||
.get_obj_value(py, elem, ctx, generator, ndarray_dtype)
|
.get_obj_value(py, elem, ctx, generator, ndarray_dtype)
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
super::CompileError::new_err(format!(
|
super::CompileError::new_err(format!("Error getting element {i}: {e}"))
|
||||||
"Error getting element {i}: {e}"
|
|
||||||
))
|
|
||||||
})?
|
})?
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -1286,17 +1279,16 @@ impl InnerResolver {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
let ndarray = llvm_ndarray
|
let ndarray =
|
||||||
.as_base_type()
|
llvm_ndarray.as_base_type().get_element_type().into_struct_type().const_named_struct(
|
||||||
.get_element_type()
|
&[
|
||||||
.into_struct_type()
|
|
||||||
.const_named_struct(&[
|
|
||||||
ndarray_itemsize.into(),
|
ndarray_itemsize.into(),
|
||||||
ndarray_ndims.into(),
|
ndarray_ndims.into(),
|
||||||
ndarray_shape.into(),
|
ndarray_shape.into(),
|
||||||
ndarray_strides.into(),
|
ndarray_strides.into(),
|
||||||
ndarray_data.into(),
|
ndarray_data.into(),
|
||||||
]);
|
],
|
||||||
|
);
|
||||||
|
|
||||||
let ndarray_global = ctx.module.add_global(
|
let ndarray_global = ctx.module.add_global(
|
||||||
llvm_ndarray.as_base_type().get_element_type().into_struct_type(),
|
llvm_ndarray.as_base_type().get_element_type().into_struct_type(),
|
||||||
@ -1363,8 +1355,7 @@ impl InnerResolver {
|
|||||||
let global_str = format!("{id}_option");
|
let global_str = format!("{id}_option");
|
||||||
{
|
{
|
||||||
if self.global_value_ids.read().contains_key(&id) {
|
if self.global_value_ids.read().contains_key(&id) {
|
||||||
let global =
|
let global = ctx.module.get_global(&global_str).unwrap_or_else(|| {
|
||||||
ctx.module.get_global(&global_str).unwrap_or_else(|| {
|
|
||||||
ctx.module.add_global(
|
ctx.module.add_global(
|
||||||
v.get_type(),
|
v.get_type(),
|
||||||
Some(AddressSpace::default()),
|
Some(AddressSpace::default()),
|
||||||
@ -1419,13 +1410,7 @@ impl InnerResolver {
|
|||||||
let values: Result<Option<Vec<_>>, _> = fields
|
let values: Result<Option<Vec<_>>, _> = fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(name, ty, _)| {
|
.map(|(name, ty, _)| {
|
||||||
self.get_obj_value(
|
self.get_obj_value(py, obj.getattr(name.to_string().as_str())?, ctx, generator, *ty)
|
||||||
py,
|
|
||||||
obj.getattr(name.to_string().as_str())?,
|
|
||||||
ctx,
|
|
||||||
generator,
|
|
||||||
*ty,
|
|
||||||
)
|
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
super::CompileError::new_err(format!("Error getting field {name}: {e}"))
|
super::CompileError::new_err(format!("Error getting field {name}: {e}"))
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user