forked from M-Labs/nac3
core/model: add util.rs & gen_model_memcpy
This commit is contained in:
parent
7e056b9747
commit
7436513b64
@ -3,6 +3,7 @@ mod int;
|
||||
mod ptr;
|
||||
mod slice;
|
||||
mod structure;
|
||||
pub mod util;
|
||||
|
||||
pub use core::*;
|
||||
pub use int::*;
|
||||
|
23
nac3core/src/codegen/model/util.rs
Normal file
23
nac3core/src/codegen/model/util.rs
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user