@@ -30,6 +30,8 @@ use rustc_borrowck::graphviz as borrowck_dot;
30
30
use rustc_resolve as resolve;
31
31
use rustc_metadata:: cstore:: CStore ;
32
32
33
+ use rustc_mir:: pretty:: write_mir_pretty;
34
+
33
35
use syntax:: ast:: { self , BlockCheckMode } ;
34
36
use syntax:: codemap;
35
37
use syntax:: fold:: { self , Folder } ;
@@ -77,6 +79,7 @@ pub enum PpMode {
77
79
PpmSource ( PpSourceMode ) ,
78
80
PpmHir ( PpSourceMode ) ,
79
81
PpmFlowGraph ( PpFlowGraphMode ) ,
82
+ PpmMir ,
80
83
}
81
84
82
85
pub fn parse_pretty ( sess : & Session ,
@@ -96,14 +99,15 @@ pub fn parse_pretty(sess: &Session,
96
99
( "hir" , true ) => PpmHir ( PpmNormal ) ,
97
100
( "hir,identified" , true ) => PpmHir ( PpmIdentified ) ,
98
101
( "hir,typed" , true ) => PpmHir ( PpmTyped ) ,
102
+ ( "mir" , true ) => PpmMir ,
99
103
( "flowgraph" , true ) => PpmFlowGraph ( PpFlowGraphMode :: Default ) ,
100
104
( "flowgraph,unlabelled" , true ) => PpmFlowGraph ( PpFlowGraphMode :: UnlabelledEdges ) ,
101
105
_ => {
102
106
if extended {
103
107
sess. fatal ( & format ! ( "argument to `unpretty` must be one of `normal`, \
104
108
`expanded`, `flowgraph[,unlabelled]=<nodeid>`, \
105
109
`identified`, `expanded,identified`, `everybody_loops`, \
106
- `hir`, `hir,identified`, or `hir,typed`; got {}",
110
+ `hir`, `hir,identified`, `hir,typed`, or `mir `; got {}",
107
111
name) ) ;
108
112
} else {
109
113
sess. fatal ( & format ! ( "argument to `pretty` must be one of `normal`, `expanded`, \
@@ -569,6 +573,7 @@ fn needs_ast_map(ppm: &PpMode, opt_uii: &Option<UserIdentifiedItem>) -> bool {
569
573
PpmSource ( PpmExpandedIdentified ) |
570
574
PpmSource ( PpmExpandedHygiene ) |
571
575
PpmHir ( _) |
576
+ PpmMir |
572
577
PpmFlowGraph ( _) => true ,
573
578
PpmSource ( PpmTyped ) => panic ! ( "invalid state" ) ,
574
579
}
@@ -584,6 +589,7 @@ fn needs_expansion(ppm: &PpMode) -> bool {
584
589
PpmSource ( PpmExpandedIdentified ) |
585
590
PpmSource ( PpmExpandedHygiene ) |
586
591
PpmHir ( _) |
592
+ PpmMir |
587
593
PpmFlowGraph ( _) => true ,
588
594
PpmSource ( PpmTyped ) => panic ! ( "invalid state" ) ,
589
595
}
@@ -801,6 +807,48 @@ pub fn pretty_print_input(sess: Session,
801
807
} )
802
808
}
803
809
810
+ ( PpmMir , None ) => {
811
+ debug ! ( "pretty printing MIR for whole crate" ) ;
812
+ let ast_map = ast_map. expect ( "--unpretty mir missing ast_map" ) ;
813
+ abort_on_err ( driver:: phase_3_run_analysis_passes ( & sess,
814
+ & cstore,
815
+ ast_map,
816
+ & arenas,
817
+ & id,
818
+ resolve:: MakeGlobMap :: No ,
819
+ |tcx, mir_map, _, _| {
820
+ let mir_map = mir_map. unwrap ( ) ;
821
+
822
+ for ( nodeid, mir) in & mir_map. map {
823
+ try!( writeln ! ( out, "MIR for {}" , tcx. map. node_to_string( * nodeid) ) ) ;
824
+ try!( write_mir_pretty ( mir, & mut out) ) ;
825
+ }
826
+
827
+ Ok ( ( ) )
828
+ } ) , & sess)
829
+ }
830
+
831
+ ( PpmMir , Some ( uii) ) => {
832
+ debug ! ( "pretty printing MIR for {:?}" , uii) ;
833
+ let ast_map = ast_map. expect ( "--unpretty mir missing ast_map" ) ;
834
+ let nodeid = uii. to_one_node_id ( "--unpretty" , & sess, & ast_map) ;
835
+
836
+ abort_on_err ( driver:: phase_3_run_analysis_passes ( & sess,
837
+ & cstore,
838
+ ast_map,
839
+ & arenas,
840
+ & id,
841
+ resolve:: MakeGlobMap :: No ,
842
+ |tcx, mir_map, _, _| {
843
+ let mir_map = mir_map. unwrap ( ) ;
844
+ try!( writeln ! ( out, "MIR for {}" , tcx. map. node_to_string( nodeid) ) ) ;
845
+ let mir = mir_map. map . get ( & nodeid) . unwrap_or_else ( || {
846
+ sess. fatal ( & format ! ( "no MIR map entry for node {}" , nodeid) )
847
+ } ) ;
848
+ write_mir_pretty ( mir, & mut out)
849
+ } ) , & sess)
850
+ }
851
+
804
852
( PpmFlowGraph ( mode) , opt_uii) => {
805
853
debug ! ( "pretty printing flow graph for {:?}" , opt_uii) ;
806
854
let uii = opt_uii. unwrap_or_else ( || {
0 commit comments