@@ -31,6 +31,7 @@ use rustc_resolve as resolve;
31
31
use rustc_metadata:: cstore:: CStore ;
32
32
33
33
use rustc_mir:: pretty:: write_mir_pretty;
34
+ use rustc_mir:: graphviz:: write_mir_graphviz;
34
35
35
36
use syntax:: ast:: { self , BlockCheckMode } ;
36
37
use syntax:: codemap;
@@ -44,6 +45,7 @@ use graphviz as dot;
44
45
45
46
use std:: fs:: File ;
46
47
use std:: io:: { self , Write } ;
48
+ use std:: iter;
47
49
use std:: option;
48
50
use std:: path:: PathBuf ;
49
51
use std:: str:: FromStr ;
@@ -80,6 +82,7 @@ pub enum PpMode {
80
82
PpmHir ( PpSourceMode ) ,
81
83
PpmFlowGraph ( PpFlowGraphMode ) ,
82
84
PpmMir ,
85
+ PpmMirCFG ,
83
86
}
84
87
85
88
pub fn parse_pretty ( sess : & Session ,
@@ -100,6 +103,7 @@ pub fn parse_pretty(sess: &Session,
100
103
( "hir,identified" , true ) => PpmHir ( PpmIdentified ) ,
101
104
( "hir,typed" , true ) => PpmHir ( PpmTyped ) ,
102
105
( "mir" , true ) => PpmMir ,
106
+ ( "mir-cfg" , true ) => PpmMirCFG ,
103
107
( "flowgraph" , true ) => PpmFlowGraph ( PpFlowGraphMode :: Default ) ,
104
108
( "flowgraph,unlabelled" , true ) => PpmFlowGraph ( PpFlowGraphMode :: UnlabelledEdges ) ,
105
109
_ => {
@@ -574,6 +578,7 @@ fn needs_ast_map(ppm: &PpMode, opt_uii: &Option<UserIdentifiedItem>) -> bool {
574
578
PpmSource ( PpmExpandedHygiene ) |
575
579
PpmHir ( _) |
576
580
PpmMir |
581
+ PpmMirCFG |
577
582
PpmFlowGraph ( _) => true ,
578
583
PpmSource ( PpmTyped ) => panic ! ( "invalid state" ) ,
579
584
}
@@ -590,6 +595,7 @@ fn needs_expansion(ppm: &PpMode) -> bool {
590
595
PpmSource ( PpmExpandedHygiene ) |
591
596
PpmHir ( _) |
592
597
PpmMir |
598
+ PpmMirCFG |
593
599
PpmFlowGraph ( _) => true ,
594
600
PpmSource ( PpmTyped ) => panic ! ( "invalid state" ) ,
595
601
}
@@ -807,9 +813,15 @@ pub fn pretty_print_input(sess: Session,
807
813
} )
808
814
}
809
815
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
+ } ;
813
825
abort_on_err ( driver:: phase_3_run_analysis_passes ( & sess,
814
826
& cstore,
815
827
ast_map,
@@ -818,38 +830,25 @@ pub fn pretty_print_input(sess: Session,
818
830
resolve:: MakeGlobMap :: No ,
819
831
|tcx, mir_map, _, _| {
820
832
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
+ } ) ;
824
846
}
825
847
}
826
848
Ok ( ( ) )
827
849
} ) , & sess)
828
850
}
829
851
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
-
853
852
( PpmFlowGraph ( mode) , opt_uii) => {
854
853
debug ! ( "pretty printing flow graph for {:?}" , opt_uii) ;
855
854
let uii = opt_uii. unwrap_or_else ( || {
0 commit comments