diff --git a/hercules_cg/src/rt.rs b/hercules_cg/src/rt.rs index f758fed34daa5359d767ae7b30c7e8b893d9040f..8c5775d86e7dc3e475e6378bbd9efb74509b0402 100644 --- a/hercules_cg/src/rt.rs +++ b/hercules_cg/src/rt.rs @@ -622,9 +622,26 @@ impl<'a> RTContext<'a> { } => { let block = &mut blocks.get_mut(&bb).unwrap().data; let collect_ty = self.typing[collect.idx()]; - let out_size = self.codegen_type_size(self.typing[id.idx()]); + let self_ty = self.typing[id.idx()]; let offset = self.codegen_index_math(collect_ty, indices, bb)?; - todo!(); + if self.module.types[self_ty.idx()].is_primitive() { + write!( + block, + "{} = ({}.byte_add({} as usize).0 as *mut {}).read();", + self.get_value(id, bb, true), + self.get_value(collect, bb, false), + offset, + self.get_type(self_ty) + )?; + } else { + write!( + block, + "{} = {}.byte_add({} as usize);", + self.get_value(id, bb, true), + self.get_value(collect, bb, false), + offset, + )?; + } } Node::Write { collect, @@ -633,11 +650,18 @@ impl<'a> RTContext<'a> { } => { let block = &mut blocks.get_mut(&bb).unwrap().data; let collect_ty = self.typing[collect.idx()]; - let data_size = self.codegen_type_size(self.typing[data.idx()]); - let offset = self.codegen_index_math(collect_ty, indices, bb)?; let data_ty = self.typing[data.idx()]; + let data_size = self.codegen_type_size(data_ty); + let offset = self.codegen_index_math(collect_ty, indices, bb)?; if self.module.types[data_ty.idx()].is_primitive() { - todo!(); + write!( + block, + "({}.byte_add({} as usize).0 as *mut {}).write({});", + self.get_value(collect, bb, false), + offset, + self.get_type(data_ty), + self.get_value(data, bb, false), + )?; } else { // If the data item being written is not a primitive type, // then perform a memcpy from the data collection to the