2016-06-05 06:00:17 +00:00
|
|
|
//! This pass just dumps MIR at a specified point.
|
|
|
|
|
2017-04-25 22:23:33 +00:00
|
|
|
use std::borrow::Cow;
|
2016-06-08 18:03:06 +00:00
|
|
|
use std::fmt;
|
2017-02-16 21:59:09 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io;
|
2016-06-08 18:03:06 +00:00
|
|
|
|
2021-01-01 00:53:25 +00:00
|
|
|
use crate::MirPass;
|
2020-04-12 17:31:00 +00:00
|
|
|
use rustc_middle::mir::Body;
|
2021-10-08 15:56:15 +00:00
|
|
|
use rustc_middle::mir::{dump_mir, write_mir_pretty};
|
2020-03-29 14:41:09 +00:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2020-03-11 11:49:08 +00:00
|
|
|
use rustc_session::config::{OutputFilenames, OutputType};
|
2016-06-05 06:00:17 +00:00
|
|
|
|
2017-04-25 22:23:33 +00:00
|
|
|
pub struct Marker(pub &'static str);
|
2016-06-08 18:03:06 +00:00
|
|
|
|
2019-08-04 20:20:00 +00:00
|
|
|
impl<'tcx> MirPass<'tcx> for Marker {
|
2019-06-21 16:12:39 +00:00
|
|
|
fn name(&self) -> Cow<'_, str> {
|
2017-04-25 22:23:33 +00:00
|
|
|
Cow::Borrowed(self.0)
|
|
|
|
}
|
2016-06-08 18:03:06 +00:00
|
|
|
|
2020-10-04 18:01:38 +00:00
|
|
|
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {}
|
2016-06-08 18:03:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:23:33 +00:00
|
|
|
pub struct Disambiguator {
|
2019-12-22 22:42:04 +00:00
|
|
|
is_after: bool,
|
2016-06-08 18:03:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 22:23:33 +00:00
|
|
|
impl fmt::Display for Disambiguator {
|
2019-02-07 21:28:15 +00:00
|
|
|
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2016-06-08 18:03:06 +00:00
|
|
|
let title = if self.is_after { "after" } else { "before" };
|
2017-04-25 22:23:33 +00:00
|
|
|
write!(formatter, "{}", title)
|
2016-06-08 18:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 21:11:55 +00:00
|
|
|
pub fn on_mir_pass<'tcx>(
|
2019-06-13 21:48:52 +00:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2019-06-11 21:11:55 +00:00
|
|
|
pass_num: &dyn fmt::Display,
|
|
|
|
pass_name: &str,
|
|
|
|
body: &Body<'tcx>,
|
|
|
|
is_after: bool,
|
|
|
|
) {
|
2021-10-08 15:56:15 +00:00
|
|
|
dump_mir(tcx, Some(pass_num), pass_name, &Disambiguator { is_after }, body, |_, _| Ok(()));
|
2016-06-05 06:00:17 +00:00
|
|
|
}
|
|
|
|
|
2019-06-21 16:12:39 +00:00
|
|
|
pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> {
|
2017-02-16 21:59:09 +00:00
|
|
|
let path = outputs.path(OutputType::Mir);
|
2020-01-22 15:22:46 +00:00
|
|
|
let mut f = io::BufWriter::new(File::create(&path)?);
|
2021-01-05 18:53:07 +00:00
|
|
|
write_mir_pretty(tcx, None, &mut f)?;
|
2017-02-16 21:59:09 +00:00
|
|
|
Ok(())
|
|
|
|
}
|