Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use rustc_borrowck::graphviz as borrowck_dot;
use rustc_resolve as resolve;
use rustc_metadata::cstore::CStore;

use rustc_mir::pretty::write_mir_pretty;

use syntax::ast::{self, BlockCheckMode};
use syntax::codemap;
use syntax::fold::{self, Folder};
Expand Down Expand Up @@ -77,6 +79,7 @@ pub enum PpMode {
PpmSource(PpSourceMode),
PpmHir(PpSourceMode),
PpmFlowGraph(PpFlowGraphMode),
PpmMir,
}

pub fn parse_pretty(sess: &Session,
Expand All @@ -96,14 +99,15 @@ pub fn parse_pretty(sess: &Session,
("hir", true) => PpmHir(PpmNormal),
("hir,identified", true) => PpmHir(PpmIdentified),
("hir,typed", true) => PpmHir(PpmTyped),
("mir", true) => PpmMir,
("flowgraph", true) => PpmFlowGraph(PpFlowGraphMode::Default),
("flowgraph,unlabelled", true) => PpmFlowGraph(PpFlowGraphMode::UnlabelledEdges),
_ => {
if extended {
sess.fatal(&format!("argument to `unpretty` must be one of `normal`, \
`expanded`, `flowgraph[,unlabelled]=<nodeid>`, \
`identified`, `expanded,identified`, `everybody_loops`, \
`hir`, `hir,identified`, or `hir,typed`; got {}",
`hir`, `hir,identified`, `hir,typed`, or `mir`; got {}",
name));
} else {
sess.fatal(&format!("argument to `pretty` must be one of `normal`, `expanded`, \
Expand Down Expand Up @@ -569,6 +573,7 @@ fn needs_ast_map(ppm: &PpMode, opt_uii: &Option<UserIdentifiedItem>) -> bool {
PpmSource(PpmExpandedIdentified) |
PpmSource(PpmExpandedHygiene) |
PpmHir(_) |
PpmMir |
PpmFlowGraph(_) => true,
PpmSource(PpmTyped) => panic!("invalid state"),
}
Expand All @@ -584,6 +589,7 @@ fn needs_expansion(ppm: &PpMode) -> bool {
PpmSource(PpmExpandedIdentified) |
PpmSource(PpmExpandedHygiene) |
PpmHir(_) |
PpmMir |
PpmFlowGraph(_) => true,
PpmSource(PpmTyped) => panic!("invalid state"),
}
Expand Down Expand Up @@ -801,6 +807,48 @@ pub fn pretty_print_input(sess: Session,
})
}

(PpmMir, None) => {
debug!("pretty printing MIR for whole crate");
let ast_map = ast_map.expect("--unpretty mir missing ast_map");
abort_on_err(driver::phase_3_run_analysis_passes(&sess,
&cstore,
ast_map,
&arenas,
&id,
resolve::MakeGlobMap::No,
|tcx, mir_map, _, _| {
let mir_map = mir_map.unwrap();

for (nodeid, mir) in &mir_map.map {
try!(writeln!(out, "MIR for {}", tcx.map.node_to_string(*nodeid)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I personally think the MIR pretty writer should be adapted to somehow work on MIR maps by e.g. outputting

fn main::main() -> ... {
...
}

for functions and

λ main::main::1(... {
}

for closures as well as improving the way closures are printed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. That would require passing both the HIR and MIR map, as well as some custom formatting, so I'll leave that to another PR.

try!(write_mir_pretty(mir, &mut out));
}

Ok(())
}), &sess)
}

(PpmMir, Some(uii)) => {
debug!("pretty printing MIR for {:?}", uii);
let ast_map = ast_map.expect("--unpretty mir missing ast_map");
let nodeid = uii.to_one_node_id("--unpretty", &sess, &ast_map);

abort_on_err(driver::phase_3_run_analysis_passes(&sess,
&cstore,
ast_map,
&arenas,
&id,
resolve::MakeGlobMap::No,
|tcx, mir_map, _, _| {
let mir_map = mir_map.unwrap();
try!(writeln!(out, "MIR for {}", tcx.map.node_to_string(nodeid)));
let mir = mir_map.map.get(&nodeid).unwrap_or_else(|| {
sess.fatal(&format!("no MIR map entry for node {}", nodeid))
});
write_mir_pretty(mir, &mut out)
}), &sess)
}

(PpmFlowGraph(mode), opt_uii) => {
debug!("pretty printing flow graph for {:?}", opt_uii);
let uii = opt_uii.unwrap_or_else(|| {
Expand Down