GitLab will continue to be upgraded from 11.4.5-ce.0 on November 25th 2019 at 4.00pm (AEDT) to 5.00pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available.

Commit 7b52143a authored by qinsoon's avatar qinsoon

run generated mu functions from dylib in tests

parent 56967872
......@@ -30,6 +30,9 @@ lazy_static! {
);
}
// consider using libloading crate instead of the raw c functions for dynalic libraries
// however i am not sure if libloading can load symbols from current process (not from an actual dylib)
// so here i use dlopen/dlsym from C
#[link(name="dl")]
extern "C" {
fn dlopen(filename: *const c_char, flags: isize) -> *const c_void;
......
......@@ -201,6 +201,7 @@ pub enum MuStackState {
}
#[repr(C)]
#[allow(improper_ctypes)]
pub struct MuThread {
pub hdr: MuEntityHeader,
allocator: Box<mm::Mutator>,
......@@ -221,7 +222,6 @@ lazy_static! {
#[cfg(target_os = "macos")]
#[link(name = "runtime")]
extern "C" {
#[allow(improper_ctypes)]
fn set_thread_local(thread: *mut MuThread);
pub fn get_thread_local() -> Address;
}
......
......@@ -2,3 +2,4 @@ mod test_pre_instsel;
mod test_instsel;
mod test_regalloc;
mod test_global;
mod test_compiler;
\ No newline at end of file
extern crate mu;
extern crate log;
extern crate simple_logger;
extern crate libloading;
use test_ir::test_ir::sum;
use test_ir::test_ir::factorial;
use self::mu::compiler::*;
use self::mu::ast::ir::*;
use std::sync::Arc;
use aot;
#[test]
fn test_regalloc_fac() {
simple_logger::init_with_level(log::LogLevel::Trace).ok();
let vm = Arc::new(factorial());
let compiler = Compiler::new(CompilerPolicy::default(), vm.clone());
let func_id = vm.id_of("fac");
{
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("fac")], "libfac.dylib");
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
unsafe {
let fac : libloading::Symbol<unsafe extern fn(u64) -> u64> = lib.get(b"fac").unwrap();
let fac5 = fac(5);
println!("fac(5) = {}", fac5);
assert!(fac5 == 120);
}
}
#[test]
fn test_regalloc_sum() {
simple_logger::init_with_level(log::LogLevel::Trace).ok();
let vm = Arc::new(sum());
let compiler = Compiler::new(CompilerPolicy::default(), vm.clone());
let func_id = vm.id_of("sum");
{
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("sum")], "libsum.dylib");
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
unsafe {
let sum : libloading::Symbol<unsafe extern fn(u64) -> u64> = lib.get(b"sum").unwrap();
let sum5 = sum(5);
println!("sum(1..4) = {}", sum5);
assert!(sum5 == 10);
let sum10 = sum(10);
println!("sum(0..9) = {}", sum10);
assert!(sum10 == 45);
}
}
\ No newline at end of file
......@@ -9,7 +9,6 @@ use self::mu::utils::vec_utils;
use self::mu::ast::ir::*;
use std::sync::Arc;
use aot;
#[test]
fn test_ir_liveness_fac() {
......@@ -64,37 +63,4 @@ fn test_ir_liveness_fac() {
let block_2_liveout = cf.mc.get_ir_block_liveout("blk_2").unwrap();
let expect : Vec<MuID> = vec![];
assert!(vec_utils::is_identical_to_str_ignore_order(block_2_liveout, expect));
}
#[test]
fn test_regalloc_fac() {
simple_logger::init_with_level(log::LogLevel::Trace).ok();
let vm = Arc::new(factorial());
let compiler = Compiler::new(CompilerPolicy::default(), vm.clone());
let func_id = vm.id_of("fac");
{
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!["fac".to_string()], "libfac.dylib");
let lib = libloading::Library::new(dylib.as_os_str()).unwrap();
unsafe {
let fac : libloading::Symbol<unsafe extern fn(u64) -> u64> = lib.get(b"fac").unwrap();
let fac5 = fac(5);
println!("fac(5) = {}", fac5);
assert!(fac5 == 120);
}
}
}
\ No newline at end of file
......@@ -4,7 +4,6 @@ use mu::runtime::mm::heap::immix::ImmixMutatorLocal;
use mu::runtime::mm::heap::immix::ImmixSpace;
use mu::runtime::mm::heap::freelist::FreeListSpace;
use mu::runtime::mm::common::Address;
use mu::runtime::mm::common::ObjectReference;
use mu::runtime::mm::objectmodel;
use std::sync::RwLock;
......
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