4 extern crate rustc_driver;
7 use self::miri::eval_main;
8 use self::rustc::session::Session;
9 use self::rustc_driver::{driver, CompilerCalls, Compilation};
10 use std::cell::RefCell;
14 pub struct MiriCompilerCalls<'a>(Rc<RefCell<&'a mut Bencher>>);
16 fn find_sysroot() -> String {
17 // Taken from https://github.com/Manishearth/rust-clippy/pull/911.
18 let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
19 let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
20 match (home, toolchain) {
21 (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
22 _ => option_env!("RUST_SYSROOT")
23 .expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
28 pub fn run(filename: &str, bencher: &mut Bencher) {
31 format!("benches/helpers/{}.rs", filename),
32 "--sysroot".to_string(),
35 let compiler_calls = &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher)));
36 rustc_driver::run_compiler(args, compiler_calls, None, None);
39 impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
44 ) -> driver::CompileController<'a> {
45 let mut control: driver::CompileController<'a> = driver::CompileController::basic();
47 let bencher = self.0.clone();
49 control.after_analysis.stop = Compilation::Stop;
50 control.after_analysis.callback = Box::new(move |state| {
51 state.session.abort_if_errors();
53 let tcx = state.tcx.unwrap();
54 let (entry_node_id, _) = state.session.entry_fn.borrow()
55 .expect("no main or start function found");
56 let entry_def_id = tcx.map.local_def_id(entry_node_id);
58 let memory_size = 100*1024*1024; // 100MB
59 let step_limit = 1000_000;
60 let stack_limit = 100;
61 bencher.borrow_mut().iter(|| { eval_main(tcx, entry_def_id, memory_size, step_limit, stack_limit); });
63 state.session.abort_if_errors();