feat: JIT (WIP)
This commit is contained in:
@@ -50,7 +50,7 @@ impl<'ctx> Helpers<'ctx> {
|
||||
let bool_type = context.bool_type();
|
||||
let ptr_int_type = context.ptr_sized_int_type(execution_engine.get_target_data(), None);
|
||||
let ptr_type = context.ptr_type(AddressSpace::default());
|
||||
let value_type = context.struct_type(&[int_type.into(), int_type.into()], false);
|
||||
let value_type = context.struct_type(&[int_type.into(), int_type.into(), int_type.into()], false);
|
||||
let func_type = value_type.fn_type(&[ptr_type.into()], false);
|
||||
|
||||
let new_thunk = module.add_function(
|
||||
@@ -182,17 +182,20 @@ impl<'ctx> Helpers<'ctx> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_value(&self, tag: ValueTag, data: BasicValueEnum<'ctx>) -> StructValue<'ctx> {
|
||||
self.value_type.const_named_struct(&[
|
||||
self.const_int(tag as i64).into(),
|
||||
data,
|
||||
self.int_type.const_zero().into()
|
||||
])
|
||||
}
|
||||
|
||||
pub fn const_int(&self, int: i64) -> IntValue<'ctx> {
|
||||
self.int_type.const_int(int as _, false)
|
||||
}
|
||||
|
||||
pub fn new_int(&self, int: i64) -> StructValue<'ctx> {
|
||||
self.value_type
|
||||
.const_named_struct(&[
|
||||
self.int_type.const_int(ValueTag::Int as _, false).into(),
|
||||
self.const_int(int).into(),
|
||||
])
|
||||
.into()
|
||||
self.new_value(ValueTag::Int, self.const_int(int).into())
|
||||
}
|
||||
|
||||
pub fn const_float(&self, float: f64) -> FloatValue<'ctx> {
|
||||
@@ -200,39 +203,19 @@ impl<'ctx> Helpers<'ctx> {
|
||||
}
|
||||
|
||||
pub fn new_float(&self, float: f64) -> StructValue<'ctx> {
|
||||
self.value_type
|
||||
.const_named_struct(&[
|
||||
self.int_type.const_int(ValueTag::Float as _, false).into(),
|
||||
self.const_float(float).into(),
|
||||
])
|
||||
.into()
|
||||
self.new_value(ValueTag::Float, self.const_float(float).into())
|
||||
}
|
||||
|
||||
pub fn const_bool(&self, bool: bool) -> IntValue<'ctx> {
|
||||
self.bool_type.const_int(bool as _, false)
|
||||
}
|
||||
|
||||
pub fn new_bool(&self, bool: bool) -> StructValue<'ctx> {
|
||||
self.value_type
|
||||
.const_named_struct(&[
|
||||
self.int_type.const_int(ValueTag::Bool as _, false).into(),
|
||||
self.bool_type.const_int(bool as _, false).into(),
|
||||
])
|
||||
.into()
|
||||
self.new_value(ValueTag::Bool, self.const_bool(bool).into())
|
||||
}
|
||||
|
||||
pub fn new_null(&self) -> StructValue<'ctx> {
|
||||
self.value_type
|
||||
.const_named_struct(&[
|
||||
self.int_type.const_int(ValueTag::Null as _, false).into(),
|
||||
self.int_type.const_zero().into(),
|
||||
])
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn const_string(&self, string: *const u8) -> StructValue<'ctx> {
|
||||
self.value_type
|
||||
.const_named_struct(&[
|
||||
self.int_type.const_int(ValueTag::String as _, false).into(),
|
||||
self.ptr_int_type.const_int(string as _, false).into(),
|
||||
])
|
||||
.into()
|
||||
self.new_value(ValueTag::Null, self.int_type.const_zero().into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user