mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Add llvm_alignment_bytes and memcpy function
This commit is contained in:
parent
75c290273d
commit
f95cef8086
5 changed files with 222 additions and 104 deletions
23
crates/compiler/gen_llvm/src/llvm/memcpy.rs
Normal file
23
crates/compiler/gen_llvm/src/llvm/memcpy.rs
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue