basic structures work in the jit

This commit is contained in:
2024-04-11 08:57:50 -07:00
parent 5f2fc7cb34
commit 8479a84e07
4 changed files with 19 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ use cranelift_codegen::isa::CallConv;
use cranelift_jit::JITBuilder;
use cranelift_module::{FuncId, Linkage, Module, ModuleResult};
use std::collections::HashMap;
use std::alloc::Layout;
use std::ffi::CStr;
use std::fmt::Write;
use target_lexicon::Triple;
@@ -93,12 +94,17 @@ impl RuntimeFunctions {
pub fn register_jit_implementations(builder: &mut JITBuilder) {
let allocation_pointer = unsafe {
std::alloc::alloc_zeroed(
std::alloc::Layout::from_size_align(1024 * 1024, 1024 * 1024)
Layout::from_size_align(1024 * 1024, 1024 * 1024)
.expect("reasonable layout is reasonable"),
)
};
let allocation_pointer_pointer = unsafe {
let res = std::alloc::alloc(Layout::for_value(&allocation_pointer)) as *mut *mut u8;
*res = allocation_pointer;
res as *const u8
};
builder.symbol("print", runtime_print as *const u8);
builder.symbol("__global_allocation_pointer__", allocation_pointer);
builder.symbol("__global_allocation_pointer__", allocation_pointer_pointer);
}
}