mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
Call roc_alloc and friends from llvm
This commit is contained in:
parent
a4209a84e6
commit
d1a561c30f
2 changed files with 5 additions and 9 deletions
|
@ -1912,11 +1912,7 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>(
|
||||||
"add_extra_bytes",
|
"add_extra_bytes",
|
||||||
);
|
);
|
||||||
|
|
||||||
env.builder
|
env.call_alloc(layout.alignment_bytes(env.ptr_bytes), number_of_bytes)
|
||||||
.build_array_malloc(ctx.i8_type(), number_of_bytes, "create_ptr")
|
|
||||||
.unwrap()
|
|
||||||
|
|
||||||
// TODO check if malloc returned null; if so, runtime error for OOM!
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// We must return a pointer to the first element:
|
// We must return a pointer to the first element:
|
||||||
|
|
|
@ -197,7 +197,7 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
||||||
fn _build_decrement_function_body<'a, 'env>(
|
fn _build_decrement_function_body<'a, 'env>(
|
||||||
env: &Env<'a, 'ctx, 'env>,
|
env: &Env<'a, 'ctx, 'env>,
|
||||||
parent: FunctionValue<'ctx>,
|
parent: FunctionValue<'ctx>,
|
||||||
extra_bytes: u32,
|
alignment: u32,
|
||||||
) {
|
) {
|
||||||
let builder = env.builder;
|
let builder = env.builder;
|
||||||
let ctx = env.context;
|
let ctx = env.context;
|
||||||
|
@ -269,15 +269,15 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
||||||
{
|
{
|
||||||
builder.position_at_end(then_block);
|
builder.position_at_end(then_block);
|
||||||
if !env.leak {
|
if !env.leak {
|
||||||
match extra_bytes {
|
match alignment {
|
||||||
n if env.ptr_bytes == n => {
|
n if env.ptr_bytes == n => {
|
||||||
// the refcount ptr is also the ptr to the malloced region
|
// 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 => {
|
n if 2 * env.ptr_bytes == n => {
|
||||||
// we need to step back another ptr_bytes to get the malloced ptr
|
// we need to step back another ptr_bytes to get the malloced ptr
|
||||||
let malloced = Self::from_ptr_to_data(env, refcount_ptr.value);
|
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),
|
n => unreachable!("invalid extra_bytes {:?}", n),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue