Add llvm_alignment_bytes and memcpy function

This commit is contained in:
Ayaz Hafiz 2023-06-15 16:49:20 -05:00
parent 75c290273d
commit f95cef8086
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
5 changed files with 222 additions and 104 deletions

View file

@ -0,0 +1,23 @@
use inkwell::{types::BasicType, values::PointerValue};
use roc_mono::layout::{LayoutRepr, STLayoutInterner};
use super::{align::LlvmAlignment, build::Env, convert::basic_type_from_layout_repr};
pub fn build_memcpy<'a, 'ctx>(
env: &Env<'a, 'ctx, '_>,
layout_interner: &STLayoutInterner<'a>,
layout: LayoutRepr<'a>,
destination: PointerValue<'ctx>,
source: PointerValue<'ctx>,
) {
let align_bytes = layout.llvm_alignment_bytes(layout_interner);
let width = basic_type_from_layout_repr(env, layout_interner, layout)
.size_of()
.unwrap();
if align_bytes > 0 {
// There is actually something to memcpy.
env.builder
.build_memcpy(destination, align_bytes, source, align_bytes, width)
.unwrap();
}
}