GitLab will be partched to the latest stable version on 15 July 2020 at 2.00pm (AEDT) to 2.30pm (AEDT) due to Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

mod.rs 1.5 KB
Newer Older
1 2 3 4 5 6 7 8 9
extern crate log;
extern crate simple_logger;
extern crate libloading as ll;

use compiler::*;
use ast::ir::*;
use vm::*;
use std::sync::Arc;

10 11
use std::process::Command;
use std::process::Output;
12

13 14
pub mod aot;
pub mod c_api;
15

16 17
pub fn get_test_clang_path() -> String {
    use std::env;
18

19 20 21
    match env::var("CLANG_FOR_AOT") {
        Ok(val) => val,
        Err(_) => "clang".to_string()
22
    }
23
}
24

25 26 27
pub fn exec (mut cmd: Command) -> Output {
    println!("executing: {:?}", cmd);
    let output = cmd.output().expect("failed to execute");
28

29 30 31 32
    println!("---out---");
    println!("{}", String::from_utf8_lossy(&output.stdout));
    println!("---err---");
    println!("{}", String::from_utf8_lossy(&output.stderr));
33

34
    output
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
}

pub fn compile_fnc<'a>(fnc_name: &'static str, build_fnc: &'a Fn() -> VM) -> ll::Library {
    simple_logger::init_with_level(log::LogLevel::Trace).ok();
    let vm = Arc::new(build_fnc());
    let compiler = Compiler::new(CompilerPolicy::default(), vm.clone());
    let func_id = vm.id_of(fnc_name);
    {
        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 libname = &format!("lib{}.dylib", fnc_name);
    let dylib = aot::link_dylib(vec![Mu(fnc_name)], libname);
    ll::Library::new(dylib.as_os_str()).unwrap()
}