2016-05-30 07:05:50 -05:00
|
|
|
#![feature(custom_attribute, test)]
|
|
|
|
#![feature(rustc_private)]
|
|
|
|
#![allow(unused_attributes)]
|
|
|
|
|
|
|
|
extern crate getopts;
|
|
|
|
extern crate miri;
|
|
|
|
extern crate rustc;
|
|
|
|
extern crate rustc_driver;
|
|
|
|
extern crate test;
|
|
|
|
|
2016-06-17 22:35:37 -05:00
|
|
|
use self::miri::eval_main;
|
2016-05-30 07:05:50 -05:00
|
|
|
use self::rustc::session::Session;
|
2016-06-03 10:14:36 -05:00
|
|
|
use self::rustc_driver::{driver, CompilerCalls, Compilation};
|
2016-05-30 07:05:50 -05:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use test::Bencher;
|
|
|
|
|
|
|
|
pub struct MiriCompilerCalls<'a>(Rc<RefCell<&'a mut Bencher>>);
|
|
|
|
|
2016-06-17 22:35:37 -05:00
|
|
|
fn find_sysroot() -> String {
|
|
|
|
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
|
|
|
|
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
|
|
|
|
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
|
|
|
|
match (home, toolchain) {
|
|
|
|
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
|
|
|
|
_ => option_env!("RUST_SYSROOT")
|
|
|
|
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
|
|
|
|
.to_owned(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-30 07:05:50 -05:00
|
|
|
pub fn run(filename: &str, bencher: &mut Bencher) {
|
2016-06-17 22:35:37 -05:00
|
|
|
let args = &[
|
|
|
|
"miri".to_string(),
|
|
|
|
format!("benches/{}.rs", filename),
|
|
|
|
"--sysroot".to_string(),
|
|
|
|
find_sysroot()
|
|
|
|
];
|
|
|
|
let compiler_calls = &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher)));
|
|
|
|
rustc_driver::run_compiler(args, compiler_calls);
|
2016-05-30 07:05:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> {
|
|
|
|
fn build_controller(
|
|
|
|
&mut self,
|
|
|
|
_: &Session,
|
|
|
|
_: &getopts::Matches
|
|
|
|
) -> driver::CompileController<'a> {
|
|
|
|
let mut control: driver::CompileController<'a> = driver::CompileController::basic();
|
|
|
|
|
|
|
|
let bencher = self.0.clone();
|
|
|
|
|
2016-06-03 10:14:36 -05:00
|
|
|
control.after_analysis.stop = Compilation::Stop;
|
2016-05-30 07:05:50 -05:00
|
|
|
control.after_analysis.callback = Box::new(move |state| {
|
|
|
|
state.session.abort_if_errors();
|
2016-06-17 22:35:37 -05:00
|
|
|
|
|
|
|
let tcx = state.tcx.unwrap();
|
|
|
|
let mir_map = state.mir_map.unwrap();
|
|
|
|
let (node_id, _) = state.session.entry_fn.borrow()
|
|
|
|
.expect("no main or start function found");
|
|
|
|
|
|
|
|
bencher.borrow_mut().iter(|| { eval_main(tcx, mir_map, node_id); });
|
|
|
|
|
|
|
|
state.session.abort_if_errors();
|
2016-05-30 07:05:50 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
control
|
|
|
|
}
|
|
|
|
}
|