]> git.lizzy.rs Git - rust.git/blob - src/bin/miri.rs
re-introduce the module name to the logs and show vertical bars
[rust.git] / src / bin / miri.rs
1 #![feature(rustc_private, custom_attribute)]
2 #![allow(unused_attributes)]
3
4 extern crate getopts;
5 extern crate miri;
6 extern crate rustc;
7 extern crate rustc_driver;
8 extern crate env_logger;
9 extern crate log_settings;
10 extern crate log;
11
12 use miri::interpreter;
13 use rustc::session::Session;
14 use rustc_driver::{driver, CompilerCalls};
15
16 struct MiriCompilerCalls;
17
18 impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
19     fn build_controller(
20         &mut self,
21         _: &Session,
22         _: &getopts::Matches
23     ) -> driver::CompileController<'a> {
24         let mut control = driver::CompileController::basic();
25
26         control.after_analysis.callback = Box::new(|state| {
27             state.session.abort_if_errors();
28             interpreter::interpret_start_points(state.tcx.unwrap(), state.mir_map.unwrap());
29         });
30
31         control
32     }
33 }
34
35 #[miri_run]
36 fn main() {
37     init_logger();
38     let args: Vec<String> = std::env::args().collect();
39     rustc_driver::run_compiler(&args, &mut MiriCompilerCalls);
40 }
41
42 #[miri_run]
43 fn init_logger() {
44     let format = |record: &log::LogRecord| {
45         // prepend spaces to indent the final string
46         let indentation = log_settings::settings().indentation;
47         let spaces = "    |    |    |    |    |    |    |    |    ";
48         let indentation = &spaces[..std::cmp::min(indentation, spaces.len())];
49         format!("{}:{}|{} {}", record.level(), record.location().module_path(), indentation, record.args())
50     };
51
52     let mut builder = env_logger::LogBuilder::new();
53     builder.format(format).filter(None, log::LogLevelFilter::Info);
54
55     if std::env::var("RUST_LOG").is_ok() {
56         builder.parse(&std::env::var("RUST_LOG").unwrap());
57     }
58
59     builder.init().unwrap();
60 }