Commit 9f1d81ec authored by qinsoon's avatar qinsoon

generating lib___.dylib/.so depends on os

parent 36d38ac7
......@@ -48,6 +48,16 @@ pub fn exec_nocheck (mut cmd: Command) -> Output {
output
}
#[cfg(target_os = "macos")]
pub fn get_dylib_name(name: &'static str) -> String {
format!("lib{}.dylib", name)
}
#[cfg(target_os = "linux")]
pub fn get_dylib_name(name: &'static str) -> String {
format!("lib{}.so", name)
}
pub fn compile_fnc<'a>(fnc_name: &'static str, build_fnc: &'a Fn() -> VM) -> ll::Library {
VM::start_logging_trace();
......@@ -62,7 +72,7 @@ pub fn compile_fnc<'a>(fnc_name: &'static str, build_fnc: &'a Fn() -> VM) -> ll:
compiler.compile(&mut func_ver);
}
backend::emit_context(&vm);
let libname = &format!("lib{}.dylib", fnc_name);
let libname = &get_dylib_name(fnc_name);
let dylib = aot::link_dylib(vec![Mu(fnc_name)], libname, &vm);
ll::Library::new(dylib.as_os_str()).unwrap()
}
......@@ -84,7 +94,7 @@ pub fn compile_fncs<'a>(entry: &'static str, fnc_names: Vec<&'static str>, build
backend::emit_context(&vm);
let libname = &format!("lib{}.dylib", entry);
let libname = &get_dylib_name(entry);
let dylib = aot::link_dylib(fnc_names.iter().map(|x| Mu(x)).collect(), libname, &vm);
ll::Library::new(dylib.as_os_str()).unwrap()
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ use self::mu::utils::LinkedHashMap;
use std::sync::Arc;
use std::sync::RwLock;
use self::mu::testutil;
use self::mu::testutil::aot;
#[test]
......@@ -65,7 +66,7 @@ fn test_instruction_new_on_cur_thread() {
backend::emit_context(&vm);
// link
let libname = &format!("liballoc_new_on_cur_thraed.dylib");
let libname = &testutil::get_dylib_name("alloc_new_on_cur_thread");
let dylib = aot::link_dylib(vec![Mu("alloc_new")], libname, &vm);
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
......
......@@ -17,28 +17,8 @@ use mu::testutil::aot;
#[test]
fn test_fp_add() {
VM::start_logging_trace();
let lib = testutil::compile_fnc("fp_add", &fp_add);
let vm = Arc::new(fp_add());
let compiler = Compiler::new(CompilerPolicy::default(), vm.clone());
let func_id = vm.id_of("fp_add");
{
let funcs = vm.funcs().read().unwrap();
let func = funcs.get(&func_id).unwrap().read().unwrap();
let func_vers = vm.func_vers().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
compiler.compile(&mut func_ver);
}
backend::emit_context(&vm);
let dylib = aot::link_dylib(vec![Mu("fp_add")], "libfp_add.dylib", &vm);
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
unsafe {
let fp_add : libloading::Symbol<unsafe extern fn(f64, f64) -> f64> = lib.get(b"fp_add").unwrap();
......
extern crate mu;
extern crate libloading;
use mu::testutil;
use mu::testutil::aot;
use mu::utils::LinkedHashMap;
use test_ir::test_ir::factorial;
......@@ -109,7 +110,7 @@ fn test_spill1() {
backend::emit_context(&vm);
let dylib = aot::link_dylib(vec![Mu("spill1")], "libspill1.dylib", &vm);
let dylib = aot::link_dylib(vec![Mu("spill1")], &testutil::get_dylib_name("spill1"), &vm);
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
unsafe {
......@@ -311,7 +312,7 @@ fn test_simple_spill() {
backend::emit_context(&vm);
let dylib = aot::link_dylib(vec![Mu("simple_spill")], "libsimple_spill.dylib", &vm);
let dylib = aot::link_dylib(vec![Mu("simple_spill")], &testutil::get_dylib_name("simple_spill"), &vm);
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
unsafe {
......@@ -737,7 +738,7 @@ fn test_coalesce_branch2_moves() {
backend::emit_context(&vm);
let dylib = aot::link_dylib(vec![Mu("coalesce_branch2_moves")], "libcoalesce_branch2_moves.dylib", &vm);
let dylib = aot::link_dylib(vec![Mu("coalesce_branch2_moves")], &testutil::get_dylib_name("coalesce_branch2_moves"), &vm);
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
unsafe {
......
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