feat: JIT (WIP)

This commit is contained in:
2025-06-14 16:53:45 +08:00
parent 49255948ff
commit 7b6db44207
4 changed files with 96 additions and 39 deletions

View File

@@ -6,8 +6,10 @@ use inkwell::builder::Builder;
use inkwell::context::Context;
use inkwell::execution_engine::ExecutionEngine;
use inkwell::module::Module;
use inkwell::values::{AnyValue, AsValueRef, BasicMetadataValueEnum, BasicValueEnum, IntValue, StructValue};
use crate::env::VmEnv;
use crate::ir::{Ir, UnOpKind};
use crate::ty::internal::Value;
mod compile;
@@ -135,4 +137,30 @@ impl<'ctx> JITContext<'ctx> {
helpers,
}
}
pub fn compile(&self, ir: Ir) -> JITFunc {
}
pub fn get_tag(&self, val: BasicValueEnum<'ctx>) -> IntValue<'ctx> {
let alloca = self
.builder
.build_alloca(self.helpers.value_type, "get_tag_alloca").unwrap();
self.builder.build_store(alloca, val).unwrap();
self.builder
.build_load(
self.context.bool_type(),
self.builder
.build_struct_gep(self.helpers.value_type, alloca, 1, "get_tag_gep").unwrap(),
"get_tag",
).unwrap()
.into_int_value()
}
pub fn call(&self, args: &[BasicMetadataValueEnum<'ctx>]) -> StructValue<'ctx> {
self.builder.build_call(self.helpers.call, args, "call")
.unwrap()
.as_any_value_enum()
.into_struct_value()
}
}