Commit 3d948653 authored by John Zhang's avatar John Zhang

compile_to_sharedlib now compiles the whole bundle, with a specified library name

parent 3575d4da
Pipeline #14 failed with stage
in 60 minutes and 6 seconds
......@@ -243,14 +243,12 @@ extern fn _forwarder__MuVM__set_trap_handler(mvm: *mut CMuVM, trap_handler: CMuT
};
}
extern fn _forwarder__MuVM__compile_to_sharedlib(mvm: *mut CMuVM, fnc_id: CMuID) -> CMuCString {
extern fn _forwarder__MuVM__compile_to_sharedlib(mvm: *mut CMuVM, lib_name: CMuCString) {
let mut _arg_mvm = from_MuVM_ptr(mvm);
let mut _arg_fnc_id = fnc_id as MuID;
let _rv = unsafe {
(*_arg_mvm).compile_to_sharedlib(_arg_fnc_id)
let mut _arg_lib_name = from_MuCString(lib_name);
unsafe {
(*_arg_mvm).compile_to_sharedlib(&_arg_lib_name)
};
let _rv_prep = _rv;
_rv_prep
}
extern fn _forwarder__MuCtx__id_of(ctx: *mut CMuCtx, name: CMuName) -> CMuID {
......
......@@ -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, CMuID) -> CMuCString,
pub compile_to_sharedlib: extern fn(*mut CMuVM, CMuCString),
}
#[repr(C)]
......
......@@ -70,7 +70,7 @@ impl MuVM {
panic!("Not implemented")
}
pub fn compile_to_sharedlib(&self, fnc_id: MuID) -> CMuCString {
pub fn compile_to_sharedlib(&self, lib_name: &str) {
extern crate libloading as ll;
use compiler::*;
......@@ -78,18 +78,18 @@ impl MuVM {
let compiler = Compiler::new(CompilerPolicy::default(), self.vm.clone());
let funcs = self.vm.funcs().read().unwrap();
let mut func_names = vec![];
// NOTE: this fails because load() API call is not properly implemented yet.
let func = funcs.get(&fnc_id).unwrap().read().unwrap();
{
for (func_id, ref f) in funcs.iter() {
let func = f.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);
func_names.push(func.name().unwrap());
}
let func_name = func.name().unwrap();
backend::emit_context(&self.vm);
let libname = &format!("lib{}.dylib", func_name);
let dylib = aot::link_dylib(vec![func_name], libname);
dylib.to_str().unwrap().as_ptr() as CMuCString
let libname = &format!("lib{}.dylib", lib_name);
aot::link_dylib(func_names, libname);
}
}
......
......@@ -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, MuID fnc_id);
void (*compile_to_sharedlib)(MuVM *mvm, MuCString lib_name);
};
// 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