forked from M-Labs/nac3
1
0
Fork 0

core/model: add util.rs & gen_model_memcpy

This commit is contained in:
lyken 2024-07-30 15:19:45 +08:00
parent 7e056b9747
commit 7436513b64
2 changed files with 24 additions and 0 deletions

View File

@ -3,6 +3,7 @@ mod int;
mod ptr;
mod slice;
mod structure;
pub mod util;
pub use core::*;
pub use int::*;

View File

@ -0,0 +1,23 @@
use inkwell::{types::BasicType, values::IntValue};
use crate::codegen::{llvm_intrinsics::call_memcpy_generic, CodeGenContext};
use super::*;
pub fn gen_model_memcpy<'ctx, M: Model>(
tyctx: TypeContext<'ctx>,
ctx: &CodeGenContext<'ctx, '_>,
dst: Ptr<'ctx, M>,
src: Ptr<'ctx, M>,
num_elements: IntValue<'ctx>,
volatile: bool,
) {
let bool_model = IntModel(Bool);
let itemsize = M::default().get_type(tyctx, ctx.ctx).size_of().unwrap();
let totalsize =
ctx.builder.build_int_mul(itemsize, num_elements, "model_memcpy_totalsize").unwrap();
let is_volatile = bool_model.constant(tyctx, ctx.ctx, u64::from(volatile));
call_memcpy_generic(ctx, dst.value, src.value, totalsize, is_volatile.value);
}