use inkwell::context::Context;
use inkwell::types::{
BasicMetadataTypeEnum, BasicType, BasicTypeEnum, FloatType, FunctionType, IntType, PointerType,
StructType, VoidType,
};
use inkwell::AddressSpace;
pub struct TypeMapper<'ctx> {
context: &'ctx Context,
}
impl<'ctx> TypeMapper<'ctx> {
pub fn new(context: &'ctx Context) -> Self {
Self { context }
}
#[must_use]
pub fn context(&self) -> &'ctx Context {
self.context
}
#[must_use]
pub fn void_type(&self) -> VoidType<'ctx> {
self.context.void_type()
}
#[must_use]
pub fn bool_type(&self) -> IntType<'ctx> {
self.context.bool_type()
}
#[must_use]
pub fn i8_type(&self) -> IntType<'ctx> {
self.context.i8_type()
}
#[must_use]
pub fn i16_type(&self) -> IntType<'ctx> {
self.context.i16_type()
}
#[must_use]
pub fn i32_type(&self) -> IntType<'ctx> {
self.context.i32_type()
}
#[must_use]
pub fn i64_type(&self) -> IntType<'ctx> {
self.context.i64_type()
}
#[must_use]
pub fn isize_type(&self) -> IntType<'ctx> {
self.context.i64_type()
}
#[must_use]
pub fn f32_type(&self) -> FloatType<'ctx> {
self.context.f32_type()
}
#[must_use]
pub fn f64_type(&self) -> FloatType<'ctx> {
self.context.f64_type()
}
#[must_use]
pub fn ptr_type(&self) -> PointerType<'ctx> {
self.context.ptr_type(AddressSpace::default())
}
#[must_use]
pub fn i8_ptr_type(&self) -> PointerType<'ctx> {
self.context.ptr_type(AddressSpace::default())
}
#[must_use]
pub fn obj_header_type(&self) -> StructType<'ctx> {
self.context.struct_type(
&[self.ptr_type().into()], false,
)
}
#[must_use]
pub fn boxed_int_type(&self) -> StructType<'ctx> {
self.context.struct_type(
&[self.obj_header_type().into(), self.i64_type().into()],
false,
)
}
#[must_use]
pub fn closure_type(&self) -> StructType<'ctx> {
self.context.struct_type(
&[
self.obj_header_type().into(),
self.ptr_type().into(), self.i64_type().into(), ],
false,
)
}
#[must_use]
pub fn thunk_type(&self) -> StructType<'ctx> {
self.context.struct_type(
&[
self.obj_header_type().into(),
self.ptr_type().into(), ],
false,
)
}
pub fn fn_type(
&self,
ret_type: BasicTypeEnum<'ctx>,
param_types: &[BasicMetadataTypeEnum<'ctx>],
is_var_arg: bool,
) -> FunctionType<'ctx> {
ret_type.fn_type(param_types, is_var_arg)
}
pub fn void_fn_type(
&self,
param_types: &[BasicMetadataTypeEnum<'ctx>],
is_var_arg: bool,
) -> FunctionType<'ctx> {
self.void_type().fn_type(param_types, is_var_arg)
}
#[must_use]
pub fn io_unit_fn_type(&self) -> FunctionType<'ctx> {
self.void_type().fn_type(&[], false)
}
#[must_use]
pub fn int_fn_type(&self) -> FunctionType<'ctx> {
self.i64_type().fn_type(&[], false)
}
}