@@ -31,6 +31,7 @@ use rustc_resolve as resolve;
3131use rustc_metadata:: cstore:: CStore ;
3232
3333use rustc_mir:: pretty:: write_mir_pretty;
34+ use rustc_mir:: graphviz:: write_mir_graphviz;
3435
3536use syntax:: ast:: { self , BlockCheckMode } ;
3637use syntax:: codemap;
@@ -44,6 +45,7 @@ use graphviz as dot;
4445
4546use std:: fs:: File ;
4647use std:: io:: { self , Write } ;
48+ use std:: iter;
4749use std:: option;
4850use std:: path:: PathBuf ;
4951use std:: str:: FromStr ;
@@ -80,6 +82,7 @@ pub enum PpMode {
8082 PpmHir ( PpSourceMode ) ,
8183 PpmFlowGraph ( PpFlowGraphMode ) ,
8284 PpmMir ,
85+ PpmMirCFG ,
8386}
8487
8588pub fn parse_pretty ( sess : & Session ,
@@ -100,6 +103,7 @@ pub fn parse_pretty(sess: &Session,
100103 ( "hir,identified" , true ) => PpmHir ( PpmIdentified ) ,
101104 ( "hir,typed" , true ) => PpmHir ( PpmTyped ) ,
102105 ( "mir" , true ) => PpmMir ,
106+ ( "mir-cfg" , true ) => PpmMirCFG ,
103107 ( "flowgraph" , true ) => PpmFlowGraph ( PpFlowGraphMode :: Default ) ,
104108 ( "flowgraph,unlabelled" , true ) => PpmFlowGraph ( PpFlowGraphMode :: UnlabelledEdges ) ,
105109 _ => {
@@ -574,6 +578,7 @@ fn needs_ast_map(ppm: &PpMode, opt_uii: &Option<UserIdentifiedItem>) -> bool {
574578 PpmSource ( PpmExpandedHygiene ) |
575579 PpmHir ( _) |
576580 PpmMir |
581+ PpmMirCFG |
577582 PpmFlowGraph ( _) => true ,
578583 PpmSource ( PpmTyped ) => panic ! ( "invalid state" ) ,
579584 }
@@ -590,6 +595,7 @@ fn needs_expansion(ppm: &PpMode) -> bool {
590595 PpmSource ( PpmExpandedHygiene ) |
591596 PpmHir ( _) |
592597 PpmMir |
598+ PpmMirCFG |
593599 PpmFlowGraph ( _) => true ,
594600 PpmSource ( PpmTyped ) => panic ! ( "invalid state" ) ,
595601 }
@@ -807,9 +813,15 @@ pub fn pretty_print_input(sess: Session,
807813 } )
808814 }
809815
810- ( PpmMir , None ) => {
811- debug ! ( "pretty printing MIR for whole crate" ) ;
812- let ast_map = ast_map. expect ( "--unpretty mir missing ast_map" ) ;
816+ ( pp_type@PpmMir , uii) | ( pp_type@PpmMirCFG , uii) => {
817+ let ast_map = ast_map. expect ( "--unpretty missing ast_map" ) ;
818+ let nodeid = if let Some ( uii) = uii {
819+ debug ! ( "pretty printing MIR for {:?}" , uii) ;
820+ Some ( uii. to_one_node_id ( "--unpretty" , & sess, & ast_map) )
821+ } else {
822+ debug ! ( "pretty printing MIR for whole crate" ) ;
823+ None
824+ } ;
813825 abort_on_err ( driver:: phase_3_run_analysis_passes ( & sess,
814826 & cstore,
815827 ast_map,
@@ -818,38 +830,25 @@ pub fn pretty_print_input(sess: Session,
818830 resolve:: MakeGlobMap :: No ,
819831 |tcx, mir_map, _, _| {
820832 if let Some ( mir_map) = mir_map {
821- for ( nodeid, mir) in & mir_map. map {
822- try!( writeln ! ( out, "MIR for {}" , tcx. map. node_to_string( * nodeid) ) ) ;
823- try!( write_mir_pretty ( mir, & mut out) ) ;
833+ if let Some ( nodeid) = nodeid {
834+ let mir = mir_map. map . get ( & nodeid) . unwrap_or_else ( || {
835+ sess. fatal ( & format ! ( "no MIR map entry for node {}" , nodeid) )
836+ } ) ;
837+ try!( match pp_type {
838+ PpmMir => write_mir_pretty ( tcx, iter:: once ( ( & nodeid, mir) ) , & mut out) ,
839+ _ => write_mir_graphviz ( tcx, iter:: once ( ( & nodeid, mir) ) , & mut out)
840+ } ) ;
841+ } else {
842+ try!( match pp_type {
843+ PpmMir => write_mir_pretty ( tcx, mir_map. map . iter ( ) , & mut out) ,
844+ _ => write_mir_graphviz ( tcx, mir_map. map . iter ( ) , & mut out)
845+ } ) ;
824846 }
825847 }
826848 Ok ( ( ) )
827849 } ) , & sess)
828850 }
829851
830- ( PpmMir , Some ( uii) ) => {
831- debug ! ( "pretty printing MIR for {:?}" , uii) ;
832- let ast_map = ast_map. expect ( "--unpretty mir missing ast_map" ) ;
833- let nodeid = uii. to_one_node_id ( "--unpretty" , & sess, & ast_map) ;
834-
835- abort_on_err ( driver:: phase_3_run_analysis_passes ( & sess,
836- & cstore,
837- ast_map,
838- & arenas,
839- & id,
840- resolve:: MakeGlobMap :: No ,
841- |tcx, mir_map, _, _| {
842- if let Some ( mir_map) = mir_map {
843- try!( writeln ! ( out, "MIR for {}" , tcx. map. node_to_string( nodeid) ) ) ;
844- let mir = mir_map. map . get ( & nodeid) . unwrap_or_else ( || {
845- sess. fatal ( & format ! ( "no MIR map entry for node {}" , nodeid) )
846- } ) ;
847- try!( write_mir_pretty ( mir, & mut out) ) ;
848- }
849- Ok ( ( ) )
850- } ) , & sess)
851- }
852-
853852 ( PpmFlowGraph ( mode) , opt_uii) => {
854853 debug ! ( "pretty printing flow graph for {:?}" , opt_uii) ;
855854 let uii = opt_uii. unwrap_or_else ( || {
0 commit comments