Call roc_alloc and friends from llvm

This commit is contained in:
Richard Feldman 2021-05-23 01:02:23 -04:00
parent a4209a84e6
commit d1a561c30f
2 changed files with 5 additions and 9 deletions

View file

@ -1912,11 +1912,7 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>(
"add_extra_bytes",
);
env.builder
.build_array_malloc(ctx.i8_type(), number_of_bytes, "create_ptr")
.unwrap()
// TODO check if malloc returned null; if so, runtime error for OOM!
env.call_alloc(layout.alignment_bytes(env.ptr_bytes), number_of_bytes)
};
// We must return a pointer to the first element:

View file

@ -197,7 +197,7 @@ impl<'ctx> PointerToRefcount<'ctx> {
fn _build_decrement_function_body<'a, 'env>(
env: &Env<'a, 'ctx, 'env>,
parent: FunctionValue<'ctx>,
extra_bytes: u32,
alignment: u32,
) {
let builder = env.builder;
let ctx = env.context;
@ -269,15 +269,15 @@ impl<'ctx> PointerToRefcount<'ctx> {
{
builder.position_at_end(then_block);
if !env.leak {
match extra_bytes {
match alignment {
n if env.ptr_bytes == n => {
// the refcount ptr is also the ptr to the malloced region
builder.build_free(refcount_ptr.value);
env.call_dealloc(alignment, refcount_ptr.value);
}
n if 2 * env.ptr_bytes == n => {
// we need to step back another ptr_bytes to get the malloced ptr
let malloced = Self::from_ptr_to_data(env, refcount_ptr.value);
builder.build_free(malloced.value);
env.call_dealloc(alignment, malloced.value);
}
n => unreachable!("invalid extra_bytes {:?}", n),
}