1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! This pass just dumps MIR at a specified point.
19 use rustc::session::config::{OutputFilenames, OutputType};
20 use rustc::ty::TyCtxt;
21 use transform::{MirPass, MirSource};
24 pub struct Marker(pub &'static str);
26 impl MirPass for Marker {
27 fn name<'a>(&'a self) -> Cow<'a, str> {
31 fn run_pass<'a, 'tcx>(&self,
32 _tcx: TyCtxt<'a, 'tcx, 'tcx>,
39 pub struct Disambiguator {
43 impl fmt::Display for Disambiguator {
44 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
45 let title = if self.is_after { "after" } else { "before" };
46 write!(formatter, "{}", title)
51 pub fn on_mir_pass<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
52 pass_num: &dyn fmt::Display,
57 if mir_util::dump_enabled(tcx, pass_name, source) {
58 mir_util::dump_mir(tcx,
61 &Disambiguator { is_after },
68 pub fn emit_mir<'a, 'tcx>(
69 tcx: TyCtxt<'a, 'tcx, 'tcx>,
70 outputs: &OutputFilenames)
73 let path = outputs.path(OutputType::Mir);
74 let mut f = File::create(&path)?;
75 mir_util::write_mir_pretty(tcx, None, &mut f)?;