mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-13 23:36:29 +00:00
llvm types for erasure, function pointer
This commit is contained in:
parent
2c826ea898
commit
74d0f8d2e5
4 changed files with 44 additions and 8 deletions
|
@ -6021,7 +6021,7 @@ impl<'ctx> FunctionSpec<'ctx> {
|
|||
}
|
||||
|
||||
/// Fastcc calling convention
|
||||
fn fastcc<'a, 'env>(
|
||||
pub fn fastcc<'a, 'env>(
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
roc_return: RocReturn,
|
||||
return_type: BasicTypeEnum<'ctx>,
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
use crate::llvm::build::{BuilderExt, Env};
|
||||
use crate::llvm::build::{BuilderExt, Env, FunctionSpec, RocReturn};
|
||||
use crate::llvm::erased;
|
||||
use crate::llvm::memcpy::build_memcpy;
|
||||
use bumpalo::collections::Vec as AVec;
|
||||
use bumpalo::collections::{CollectIn, Vec as AVec};
|
||||
use inkwell::context::Context;
|
||||
use inkwell::types::{BasicType, BasicTypeEnum, FloatType, IntType, StructType};
|
||||
use inkwell::values::PointerValue;
|
||||
use inkwell::AddressSpace;
|
||||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
use roc_error_macros::todo_lambda_erasure;
|
||||
use roc_mono::layout::{
|
||||
round_up_to_alignment, Builtin, InLayout, Layout, LayoutInterner, LayoutRepr, STLayoutInterner,
|
||||
UnionLayout,
|
||||
round_up_to_alignment, Builtin, FunctionPointer, InLayout, Layout, LayoutInterner, LayoutRepr,
|
||||
STLayoutInterner, UnionLayout,
|
||||
};
|
||||
use roc_target::TargetInfo;
|
||||
|
||||
|
@ -49,8 +49,21 @@ pub fn basic_type_from_layout<'a, 'ctx>(
|
|||
.ptr_type(AddressSpace::default())
|
||||
.as_basic_type_enum(),
|
||||
|
||||
FunctionPointer(_) => todo_lambda_erasure!(),
|
||||
Erased(_) => todo_lambda_erasure!(),
|
||||
FunctionPointer(self::FunctionPointer { args, ret }) => {
|
||||
let args = args.iter().map(|arg| {
|
||||
basic_type_from_layout(env, layout_interner, layout_interner.get_repr(*arg))
|
||||
});
|
||||
|
||||
let ret_repr = layout_interner.get_repr(ret);
|
||||
let ret = basic_type_from_layout(env, layout_interner, ret_repr);
|
||||
|
||||
let roc_return = RocReturn::from_layout(layout_interner, ret_repr);
|
||||
|
||||
let fn_spec = FunctionSpec::fastcc(env, roc_return, ret, args.collect_in(env.arena));
|
||||
|
||||
fn_spec.typ.ptr_type(AddressSpace::default()).into()
|
||||
}
|
||||
Erased(_) => erased::basic_type(env).into(),
|
||||
|
||||
Builtin(builtin) => basic_type_from_builtin(env, &builtin),
|
||||
}
|
||||
|
|
22
crates/compiler/gen_llvm/src/llvm/erased.rs
Normal file
22
crates/compiler/gen_llvm/src/llvm/erased.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use inkwell::{
|
||||
types::{BasicTypeEnum, StructType},
|
||||
AddressSpace,
|
||||
};
|
||||
|
||||
use super::build::Env;
|
||||
|
||||
/// Erased is laid out like
|
||||
///
|
||||
/// ```text
|
||||
/// struct Erased {
|
||||
/// value: void*,
|
||||
/// callee: void*,
|
||||
/// refcounter: void*,
|
||||
/// }
|
||||
/// ```
|
||||
pub fn basic_type<'a, 'ctx>(env: &Env<'a, 'ctx, '_>) -> StructType<'ctx> {
|
||||
let ptr_ty = env.context.i8_type().ptr_type(AddressSpace::default());
|
||||
|
||||
env.context
|
||||
.struct_type(&[ptr_ty.into(), ptr_ty.into(), ptr_ty.into()], false)
|
||||
}
|
|
@ -11,6 +11,7 @@ mod lowlevel;
|
|||
pub mod refcounting;
|
||||
|
||||
mod align;
|
||||
mod erased;
|
||||
mod memcpy;
|
||||
mod scope;
|
||||
mod struct_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue