Commit 9de89b6a authored by John Zhang's avatar John Zhang

compile_to_sharedlib function takes MuID rather than string.

parent e22d6980
......@@ -243,11 +243,11 @@ extern fn _forwarder__MuVM__set_trap_handler(mvm: *mut CMuVM, trap_handler: CMuT
};
}
extern fn _forwarder__MuVM__compile_to_sharedlib(mvm: *mut CMuVM, fncname: CMuCString) -> CMuCString {
extern fn _forwarder__MuVM__compile_to_sharedlib(mvm: *mut CMuVM, fnc_id: CMuID) -> CMuCString {
let mut _arg_mvm = from_MuVM_ptr(mvm);
let mut _arg_fncname = from_MuCString(fncname);
let mut _arg_fnc_id = fnc_id as MuID;
let _rv = unsafe {
(*_arg_mvm).compile_to_sharedlib(_arg_fncname)
(*_arg_mvm).compile_to_sharedlib(_arg_fnc_id)
};
let _rv_prep = _rv;
_rv_prep
......
......@@ -110,7 +110,7 @@ pub struct CMuVM {
pub name_of: extern fn(*mut CMuVM, CMuID) -> CMuName,
pub set_trap_handler: extern fn(*mut CMuVM, CMuTrapHandler, CMuCPtr),
// this function is only used in testing jit
pub compile_to_sharedlib: extern fn(*mut CMuVM, CMuCString) -> CMuCString,
pub compile_to_sharedlib: extern fn(*mut CMuVM, CMuID) -> CMuCString,
}
#[repr(C)]
......
......@@ -70,24 +70,26 @@ impl MuVM {
panic!("Not implemented")
}
pub fn compile_to_sharedlib(&self, fnc_name: String) -> CMuCString {
pub fn compile_to_sharedlib(&self, fnc_id: MuID) -> CMuCString {
extern crate libloading as ll;
use compiler::*;
use testutil::aot;
let compiler = Compiler::new(CompilerPolicy::default(), self.vm.clone());
let fnc_id = self.vm.id_of(&fnc_name);
let funcs = self.vm.funcs().read().unwrap();
// NOTE: this fails because load() API call is not properly implemented yet.
let func = funcs.get(&fnc_id).unwrap().read().unwrap();
{
let funcs = self.vm.funcs().read().unwrap();
let func = funcs.get(&fnc_id).unwrap().read().unwrap();
let func_vers = self.vm.func_vers().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
let func_name = func.name().unwrap();
let asm_filename = backend::get_asm_filename(&func_name);
backend::emit_context(&self.vm);
let libname = &format!("lib{}.dylib", fnc_name);
let dylib = aot::link_dylib(vec![fnc_name], libname);
let libname = &format!("lib{}.dylib", func_name);
let dylib = aot::link_asm_to_dylib(vec![asm_filename], libname);
dylib.to_str().unwrap().as_ptr() as CMuCString
}
......
......@@ -271,7 +271,7 @@ struct MuVM {
// Set handlers
void (*set_trap_handler)(MuVM *mvm, MuTrapHandler trap_handler, MuCPtr userdata);
MuCString (*compile_to_sharedlib)(MuVM *mvm, MuCString fncname);
MuCString (*compile_to_sharedlib)(MuVM *mvm, MuID fnc_id);
};
// A local context. It can only be used by one thread at a time. It holds many
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment