2016-06-05 09:00:17 +03:00
|
|
|
//! This pass just dumps MIR at a specified point.
|
|
|
|
|
2017-04-25 18:23:33 -04:00
|
|
|
use std::borrow::Cow;
|
2016-06-08 21:03:06 +03:00
|
|
|
use std::fmt;
|
2017-02-16 16:59:09 -05:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io;
|
2016-06-08 21:03:06 +03:00
|
|
|
|
2019-05-17 23:55:04 +02:00
|
|
|
use rustc::mir::Body;
|
2017-02-16 16:59:09 -05:00
|
|
|
use rustc::session::config::{OutputFilenames, OutputType};
|
2016-06-05 09:00:17 +03:00
|
|
|
use rustc::ty::TyCtxt;
|
2019-02-08 06:28:15 +09:00
|
|
|
use crate::transform::{MirPass, MirSource};
|
|
|
|
use crate::util as mir_util;
|
2016-06-05 09:00:17 +03:00
|
|
|
|
2017-04-25 18:23:33 -04:00
|
|
|
pub struct Marker(pub &'static str);
|
2016-06-08 21:03:06 +03:00
|
|
|
|
2017-05-01 13:46:35 -04:00
|
|
|
impl MirPass for Marker {
|
2017-04-25 18:23:33 -04:00
|
|
|
fn name<'a>(&'a self) -> Cow<'a, str> {
|
|
|
|
Cow::Borrowed(self.0)
|
|
|
|
}
|
2016-06-08 21:03:06 +03:00
|
|
|
|
2019-06-12 00:11:55 +03:00
|
|
|
fn run_pass<'tcx>(
|
|
|
|
&self,
|
|
|
|
_tcx: TyCtxt<'tcx, 'tcx>,
|
|
|
|
_source: MirSource<'tcx>,
|
|
|
|
_body: &mut Body<'tcx>,
|
|
|
|
) {
|
2017-04-25 18:23:33 -04:00
|
|
|
}
|
2016-06-08 21:03:06 +03:00
|
|
|
}
|
|
|
|
|
2017-04-25 18:23:33 -04:00
|
|
|
pub struct Disambiguator {
|
2016-06-08 21:03:06 +03:00
|
|
|
is_after: bool
|
|
|
|
}
|
|
|
|
|
2017-04-25 18:23:33 -04:00
|
|
|
impl fmt::Display for Disambiguator {
|
2019-02-08 06:28:15 +09:00
|
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2016-06-08 21:03:06 +03:00
|
|
|
let title = if self.is_after { "after" } else { "before" };
|
2017-04-25 18:23:33 -04:00
|
|
|
write!(formatter, "{}", title)
|
2016-06-08 21:03:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 00:11:55 +03:00
|
|
|
pub fn on_mir_pass<'tcx>(
|
|
|
|
tcx: TyCtxt<'tcx, 'tcx>,
|
|
|
|
pass_num: &dyn fmt::Display,
|
|
|
|
pass_name: &str,
|
|
|
|
source: MirSource<'tcx>,
|
|
|
|
body: &Body<'tcx>,
|
|
|
|
is_after: bool,
|
|
|
|
) {
|
2017-11-10 13:58:06 +02:00
|
|
|
if mir_util::dump_enabled(tcx, pass_name, source) {
|
|
|
|
mir_util::dump_mir(tcx,
|
|
|
|
Some(pass_num),
|
|
|
|
pass_name,
|
|
|
|
&Disambiguator { is_after },
|
|
|
|
source,
|
2019-06-03 18:26:48 -04:00
|
|
|
body,
|
2017-11-10 13:58:06 +02:00
|
|
|
|_, _| Ok(()) );
|
2016-06-05 09:00:17 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-12 00:11:55 +03:00
|
|
|
pub fn emit_mir<'tcx>(tcx: TyCtxt<'tcx, 'tcx>, outputs: &OutputFilenames) -> io::Result<()> {
|
2017-02-16 16:59:09 -05:00
|
|
|
let path = outputs.path(OutputType::Mir);
|
|
|
|
let mut f = File::create(&path)?;
|
2017-04-25 15:56:02 -04:00
|
|
|
mir_util::write_mir_pretty(tcx, None, &mut f)?;
|
2017-02-16 16:59:09 -05:00
|
|
|
Ok(())
|
|
|
|
}
|