2016-05-30 07:05:50 -05:00
|
|
|
extern crate getopts;
|
|
|
|
extern crate miri;
|
|
|
|
extern crate rustc;
|
|
|
|
extern crate rustc_driver;
|
|
|
|
extern crate test;
|
|
|
|
|
2019-02-08 13:07:49 -06:00
|
|
|
use rustc_driver::{driver, Compilation};
|
2019-01-21 10:29:09 -06:00
|
|
|
use rustc::hir::def_id::LOCAL_CRATE;
|
2016-05-30 07:05:50 -05:00
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
2019-02-08 13:07:49 -06:00
|
|
|
|
|
|
|
use miri::{MiriConfig, eval_main};
|
|
|
|
|
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();
|
2019-01-21 10:29:09 -06:00
|
|
|
let (entry_def_id, _) = tcx.entry_fn(LOCAL_CRATE).expect(
|
2018-06-10 04:23:56 -05:00
|
|
|
"no main or start function found",
|
|
|
|
);
|
2016-06-17 22:35:37 -05:00
|
|
|
|
2018-06-10 04:23:56 -05:00
|
|
|
bencher.borrow_mut().iter(|| {
|
2019-02-08 13:07:49 -06:00
|
|
|
let config = MiriConfig { validate: true, args: vec![] };
|
|
|
|
eval_main(tcx, entry_def_id, config);
|
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
|
|
|
}
|