2016-06-05 09:00:17 +03:00
|
|
|
//! This pass just dumps MIR at a specified point.
|
|
|
|
|
2017-02-16 16:59:09 -05:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io;
|
2016-06-08 21:03:06 +03:00
|
|
|
|
2021-01-01 01:53:25 +01:00
|
|
|
use crate::MirPass;
|
2021-10-14 15:26:59 -05:00
|
|
|
use rustc_middle::mir::write_mir_pretty;
|
2020-04-12 10:31:00 -07:00
|
|
|
use rustc_middle::mir::Body;
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::ty::TyCtxt;
|
2023-02-26 15:27:27 -05:00
|
|
|
use rustc_session::config::{OutFileName, OutputType};
|
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
|
|
|
|
2019-08-04 16:20:00 -04:00
|
|
|
impl<'tcx> MirPass<'tcx> for Marker {
|
2023-05-15 20:23:34 +00:00
|
|
|
fn name(&self) -> &'static str {
|
2022-12-01 08:38:47 +00:00
|
|
|
self.0
|
2017-04-25 18:23:33 -04:00
|
|
|
}
|
2016-06-08 21:03:06 +03:00
|
|
|
|
2020-10-04 11:01:38 -07:00
|
|
|
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {}
|
2016-06-08 21:03:06 +03:00
|
|
|
}
|
|
|
|
|
2022-12-03 12:28:01 +00:00
|
|
|
pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
|
2023-02-26 15:27:27 -05:00
|
|
|
match tcx.output_filenames(()).path(OutputType::Mir) {
|
|
|
|
OutFileName::Stdout => {
|
|
|
|
let mut f = io::stdout();
|
|
|
|
write_mir_pretty(tcx, None, &mut f)?;
|
|
|
|
}
|
|
|
|
OutFileName::Real(path) => {
|
|
|
|
let mut f = io::BufWriter::new(File::create(&path)?);
|
|
|
|
write_mir_pretty(tcx, None, &mut f)?;
|
|
|
|
}
|
|
|
|
}
|
2017-02-16 16:59:09 -05:00
|
|
|
Ok(())
|
|
|
|
}
|