use inkwell::context::Context;
use inkwell::types::{FloatType, FunctionType, IntType, PointerType, VoidType};
pub struct LlvmTypes<'ctx> {
pub vmvalue_ptr: PointerType<'ctx>,
pub i8_type: IntType<'ctx>,
pub i32_type: IntType<'ctx>,
pub i64_type: IntType<'ctx>,
pub f64_type: FloatType<'ctx>,
pub bool_type: IntType<'ctx>,
pub void_type: VoidType<'ctx>,
pub rt_binop_ty: FunctionType<'ctx>,
pub rt_cmp_ty: FunctionType<'ctx>,
pub rt_truthy_ty: FunctionType<'ctx>,
pub rt_call_ty: FunctionType<'ctx>,
pub rt_get_global_ty: FunctionType<'ctx>,
pub rt_set_global_ty: FunctionType<'ctx>,
pub rt_builtin_ty: FunctionType<'ctx>,
pub rt_get_const_ty: FunctionType<'ctx>,
pub rt_make_list_ty: FunctionType<'ctx>,
pub rt_make_map_ty: FunctionType<'ctx>,
pub rt_load_const_ty: FunctionType<'ctx>,
pub rt_get_index_ty: FunctionType<'ctx>,
pub rt_set_index_ty: FunctionType<'ctx>,
pub rt_get_member_ty: FunctionType<'ctx>,
pub rt_set_member_ty: FunctionType<'ctx>,
pub rt_method_call_ty: FunctionType<'ctx>,
pub rt_vm_exec_op_ty: FunctionType<'ctx>,
pub rt_cmp_op_ty: FunctionType<'ctx>,
pub rt_make_closure_ty: FunctionType<'ctx>,
pub rt_unary_ty: FunctionType<'ctx>,
pub tl_fn_ty: FunctionType<'ctx>,
}
impl<'ctx> LlvmTypes<'ctx> {
pub fn new(context: &'ctx Context) -> Self {
let i8_type = context.i8_type();
let i32_type = context.i32_type();
let i64_type = context.i64_type();
let f64_type = context.f64_type();
let bool_type = context.bool_type();
let void_type = context.void_type();
let ptr_type = context.ptr_type(inkwell::AddressSpace::default());
let rt_binop_ty =
void_type.fn_type(&[ptr_type.into(), ptr_type.into(), ptr_type.into()], false);
let rt_cmp_ty = i64_type.fn_type(&[ptr_type.into(), ptr_type.into()], false);
let rt_truthy_ty = i64_type.fn_type(&[ptr_type.into()], false);
let rt_call_ty = i64_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
let rt_get_global_ty = i64_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
let rt_set_global_ty = i64_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
let rt_builtin_ty = i64_type.fn_type(
&[
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
let rt_get_const_ty =
void_type.fn_type(&[ptr_type.into(), i64_type.into(), ptr_type.into()], false);
let rt_make_list_ty =
void_type.fn_type(&[ptr_type.into(), i64_type.into(), ptr_type.into()], false);
let rt_make_map_ty = void_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
let rt_load_const_ty = void_type.fn_type(&[ptr_type.into()], false);
let rt_get_index_ty =
i64_type.fn_type(&[ptr_type.into(), ptr_type.into(), ptr_type.into()], false);
let rt_set_index_ty =
i64_type.fn_type(&[ptr_type.into(), ptr_type.into(), ptr_type.into()], false);
let rt_get_member_ty = i64_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
let rt_set_member_ty = i64_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
let rt_method_call_ty = i64_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
let rt_vm_exec_op_ty = i64_type.fn_type(
&[
ptr_type.into(),
i64_type.into(),
i64_type.into(),
i64_type.into(),
i64_type.into(),
ptr_type.into(),
i64_type.into(),
],
false,
);
let rt_cmp_op_ty =
void_type.fn_type(&[ptr_type.into(), ptr_type.into(), ptr_type.into()], false);
let rt_make_closure_ty = void_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
ptr_type.into(),
],
false,
);
let rt_unary_ty = void_type.fn_type(&[ptr_type.into(), ptr_type.into()], false);
let tl_fn_ty = i64_type.fn_type(
&[
ptr_type.into(),
ptr_type.into(),
i64_type.into(),
ptr_type.into(),
],
false,
);
LlvmTypes {
vmvalue_ptr: ptr_type,
i8_type,
i32_type,
i64_type,
f64_type,
bool_type,
void_type,
rt_binop_ty,
rt_cmp_ty,
rt_truthy_ty,
rt_call_ty,
rt_get_global_ty,
rt_set_global_ty,
rt_builtin_ty,
rt_get_const_ty,
rt_make_list_ty,
rt_make_map_ty,
rt_load_const_ty,
rt_get_index_ty,
rt_set_index_ty,
rt_get_member_ty,
rt_set_member_ty,
rt_method_call_ty,
rt_vm_exec_op_ty,
rt_cmp_op_ty,
rt_make_closure_ty,
rt_unary_ty,
tl_fn_ty,
}
}
}