2016-04-22 07:38:46 -05:00
|
|
|
#![feature(rustc_private, custom_attribute)]
|
|
|
|
#![allow(unused_attributes)]
|
2015-11-12 15:50:58 -06:00
|
|
|
|
2016-05-09 16:30:47 -05:00
|
|
|
extern crate getopts;
|
2015-11-21 21:20:06 -06:00
|
|
|
extern crate miri;
|
2015-11-12 15:50:58 -06:00
|
|
|
extern crate rustc;
|
|
|
|
extern crate rustc_driver;
|
2016-05-30 11:09:52 -05:00
|
|
|
extern crate env_logger;
|
|
|
|
extern crate log_settings;
|
|
|
|
extern crate log;
|
2015-11-12 15:50:58 -06:00
|
|
|
|
2015-11-21 21:20:06 -06:00
|
|
|
use miri::interpreter;
|
2015-11-12 15:50:58 -06:00
|
|
|
use rustc::session::Session;
|
2016-04-22 03:34:14 -05:00
|
|
|
use rustc_driver::{driver, CompilerCalls};
|
2015-11-12 15:50:58 -06:00
|
|
|
|
|
|
|
struct MiriCompilerCalls;
|
|
|
|
|
|
|
|
impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
|
2016-05-09 16:30:47 -05:00
|
|
|
fn build_controller(
|
|
|
|
&mut self,
|
|
|
|
_: &Session,
|
|
|
|
_: &getopts::Matches
|
|
|
|
) -> driver::CompileController<'a> {
|
2015-11-12 15:50:58 -06:00
|
|
|
let mut control = driver::CompileController::basic();
|
|
|
|
|
|
|
|
control.after_analysis.callback = Box::new(|state| {
|
2016-03-21 03:54:20 -05:00
|
|
|
state.session.abort_if_errors();
|
2015-11-12 15:50:58 -06:00
|
|
|
interpreter::interpret_start_points(state.tcx.unwrap(), state.mir_map.unwrap());
|
|
|
|
});
|
|
|
|
|
|
|
|
control
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
#[miri_run]
|
2015-11-12 15:50:58 -06:00
|
|
|
fn main() {
|
2016-05-30 11:09:52 -05:00
|
|
|
init_logger();
|
2015-11-12 15:50:58 -06:00
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
|
|
rustc_driver::run_compiler(&args, &mut MiriCompilerCalls);
|
|
|
|
}
|
2016-05-30 11:09:52 -05:00
|
|
|
|
|
|
|
#[miri_run]
|
|
|
|
fn init_logger() {
|
2016-06-01 11:33:29 -05:00
|
|
|
const NSPACES: usize = 40;
|
2016-05-30 11:09:52 -05:00
|
|
|
let format = |record: &log::LogRecord| {
|
|
|
|
// prepend spaces to indent the final string
|
|
|
|
let indentation = log_settings::settings().indentation;
|
2016-06-01 11:42:57 -05:00
|
|
|
format!("{lvl}:{module}{depth:2}{indent:<indentation$} {text}",
|
2016-06-01 11:33:29 -05:00
|
|
|
lvl = record.level(),
|
|
|
|
module = record.location().module_path(),
|
2016-06-01 11:42:57 -05:00
|
|
|
depth = indentation / NSPACES,
|
|
|
|
indentation = indentation % NSPACES,
|
2016-06-01 11:33:29 -05:00
|
|
|
indent = "",
|
|
|
|
text = record.args())
|
2016-05-30 11:09:52 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut builder = env_logger::LogBuilder::new();
|
|
|
|
builder.format(format).filter(None, log::LogLevelFilter::Info);
|
|
|
|
|
2016-06-01 10:32:57 -05:00
|
|
|
if std::env::var("MIRI_LOG").is_ok() {
|
|
|
|
builder.parse(&std::env::var("MIRI_LOG").unwrap());
|
2016-05-30 11:09:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
builder.init().unwrap();
|
|
|
|
}
|