rust/compiler/rustc_mir_transform/src/dump_mir.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1 KiB
Rust
Raw Normal View History

//! This pass just dumps MIR at a specified point.
2017-02-16 16:59:09 -05:00
use std::fs::File;
use std::io;
use rustc_middle::mir::{Body, write_mir_pretty};
2020-03-29 16:41:09 +02:00
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{OutFileName, OutputType};
pub(super) struct Marker(pub &'static str);
impl<'tcx> crate::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
}
fn run_pass(&self, _tcx: TyCtxt<'tcx>, _body: &mut Body<'tcx>) {}
fn is_required(&self) -> bool {
false
}
}
pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
match tcx.output_filenames(()).path(OutputType::Mir) {
OutFileName::Stdout => {
let mut f = io::stdout();
write_mir_pretty(tcx, None, &mut f)?;
}
OutFileName::Real(path) => {
2024-09-24 14:25:16 -07:00
let mut f = File::create_buffered(&path)?;
write_mir_pretty(tcx, None, &mut f)?;
if tcx.sess.opts.json_artifact_notifications {
tcx.dcx().emit_artifact_notification(&path, "mir");
}
}
}
2017-02-16 16:59:09 -05:00
Ok(())
}