Some cleanups.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
use cranelift_codegen::ir::{types, AbiParam, FuncRef, Function, Signature};
|
||||
use cranelift_codegen::isa::CallConv;
|
||||
use cranelift_jit::JITBuilder;
|
||||
use cranelift_module::{FuncId, Linkage, Module, ModuleResult};
|
||||
use std::collections::HashMap;
|
||||
use std::ffi::CStr;
|
||||
use target_lexicon::Triple;
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -16,6 +18,12 @@ pub enum RuntimeFunctionError {
|
||||
CannotFindRuntimeFunction(String),
|
||||
}
|
||||
|
||||
extern "C" fn runtime_print(name: *const i8, value: u64) {
|
||||
let cstr = unsafe { CStr::from_ptr(name) };
|
||||
let reconstituted = cstr.to_string_lossy();
|
||||
println!("{} = {}", reconstituted, value);
|
||||
}
|
||||
|
||||
impl RuntimeFunctions {
|
||||
pub fn new<M: Module>(platform: &Triple, module: &mut M) -> ModuleResult<RuntimeFunctions> {
|
||||
let mut builtin_functions = HashMap::new();
|
||||
@@ -54,4 +62,9 @@ impl RuntimeFunctions {
|
||||
Some(func_id) => Ok(module.declare_func_in_func(*func_id, func)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn register_jit_implementations(builder: &mut JITBuilder) {
|
||||
builder.symbol("print", runtime_print as *const u8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user