2016-05-30 07:05:50 -05:00
|
|
|
extern crate getopts;
|
|
|
|
extern crate miri;
|
|
|
|
extern crate rustc;
|
|
|
|
extern crate rustc_driver;
|
|
|
|
extern crate test;
|
|
|
|
|
2017-05-04 10:42:43 -05:00
|
|
|
use self::miri::eval_main;
|
2018-06-10 04:23:56 -05:00
|
|
|
use self::rustc_driver::{driver, Compilation};
|
2016-05-30 07:05:50 -05:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
2018-11-17 05:24:27 -06:00
|
|
|
use crate::test::Bencher;
|
2016-05-30 07:05:50 -05:00
|
|
|
|
|
|
|
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),
|
2017-08-10 10:48:38 -05:00
|
|
|
_ => {
|
|
|
|
option_env!("RUST_SYSROOT")
|
|
|
|
.expect(
|
|
|
|
"need to specify RUST_SYSROOT env var or use rustup or multirust",
|
|
|
|
)
|
|
|
|
.to_owned()
|
|
|
|
}
|
2016-06-17 22:35:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(),
|
2016-06-17 23:35:34 -05:00
|
|
|
format!("benches/helpers/{}.rs", filename),
|
2016-06-17 22:35:37 -05:00
|
|
|
"--sysroot".to_string(),
|
2017-08-10 10:48:38 -05:00
|
|
|
find_sysroot(),
|
2016-06-17 22:35:37 -05:00
|
|
|
];
|
2018-06-10 04:23:56 -05:00
|
|
|
let bencher = RefCell::new(bencher);
|
2016-05-30 07:05:50 -05:00
|
|
|
|
2018-06-10 04:23:56 -05:00
|
|
|
let mut control = driver::CompileController::basic();
|
2016-06-17 22:35:37 -05:00
|
|
|
|
2018-06-10 04:23:56 -05:00
|
|
|
control.after_analysis.stop = Compilation::Stop;
|
|
|
|
control.after_analysis.callback = Box::new(move |state| {
|
|
|
|
state.session.abort_if_errors();
|
2016-06-17 22:35:37 -05:00
|
|
|
|
2018-06-10 04:23:56 -05:00
|
|
|
let tcx = state.tcx.unwrap();
|
|
|
|
let (entry_node_id, _, _) = state.session.entry_fn.borrow().expect(
|
|
|
|
"no main or start function found",
|
|
|
|
);
|
2018-12-08 03:47:50 -06:00
|
|
|
let entry_def_id = tcx.hir().local_def_id(entry_node_id);
|
2016-06-17 22:35:37 -05:00
|
|
|
|
2018-06-10 04:23:56 -05:00
|
|
|
bencher.borrow_mut().iter(|| {
|
2018-11-17 05:24:27 -06:00
|
|
|
eval_main(tcx, entry_def_id, false);
|
2016-05-30 07:05:50 -05:00
|
|
|
});
|
|
|
|
|
2018-06-10 04:23:56 -05:00
|
|
|
state.session.abort_if_errors();
|
|
|
|
});
|
|
|
|
|
|
|
|
rustc_driver::run_compiler(args, Box::new(control), None, None);
|
2016-05-30 07:05:50 -05:00
|
|
|
}
|