8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use build:: Location ;
11
+ use build:: { Location , ScopeAuxiliary } ;
12
12
use rustc:: mir:: repr:: * ;
13
13
use rustc:: middle:: ty:: { self , TyCtxt } ;
14
14
use rustc_data_structures:: fnv:: FnvHashMap ;
@@ -25,14 +25,13 @@ pub fn write_mir_pretty<'a, 'tcx, I>(tcx: &TyCtxt<'tcx>,
25
25
-> io:: Result < ( ) >
26
26
where I : Iterator < Item =( & ' a NodeId , & ' a Mir < ' tcx > ) > , ' tcx : ' a
27
27
{
28
- let no_annotations = FnvHashMap ( ) ;
29
28
for ( & node_id, mir) in iter {
30
- write_mir_fn ( tcx, node_id, mir, w, & no_annotations ) ?;
29
+ write_mir_fn ( tcx, node_id, mir, w, None ) ?;
31
30
}
32
31
Ok ( ( ) )
33
32
}
34
33
35
- pub enum Annotation {
34
+ enum Annotation {
36
35
EnterScope ( ScopeId ) ,
37
36
ExitScope ( ScopeId ) ,
38
37
}
@@ -41,21 +40,39 @@ pub fn write_mir_fn<'tcx>(tcx: &TyCtxt<'tcx>,
41
40
node_id : NodeId ,
42
41
mir : & Mir < ' tcx > ,
43
42
w : & mut Write ,
44
- annotations : & FnvHashMap < Location , Vec < Annotation > > )
43
+ auxiliary : Option < & Vec < ScopeAuxiliary > > )
45
44
-> io:: Result < ( ) > {
45
+ // compute scope/entry exit annotations
46
+ let mut annotations = FnvHashMap ( ) ;
47
+ if let Some ( auxiliary) = auxiliary {
48
+ for ( index, auxiliary) in auxiliary. iter ( ) . enumerate ( ) {
49
+ let scope_id = ScopeId :: new ( index) ;
50
+
51
+ annotations. entry ( auxiliary. dom )
52
+ . or_insert ( vec ! [ ] )
53
+ . push ( Annotation :: EnterScope ( scope_id) ) ;
54
+
55
+ for & loc in & auxiliary. postdoms {
56
+ annotations. entry ( loc)
57
+ . or_insert ( vec ! [ ] )
58
+ . push ( Annotation :: ExitScope ( scope_id) ) ;
59
+ }
60
+ }
61
+ }
62
+
46
63
write_mir_intro ( tcx, node_id, mir, w) ?;
47
64
for block in mir. all_basic_blocks ( ) {
48
- write_basic_block ( tcx, block, mir, w, annotations) ?;
65
+ write_basic_block ( tcx, block, mir, w, & annotations) ?;
49
66
}
50
67
51
- // construct a scope tree
68
+ // construct a scope tree and write it out
52
69
let mut scope_tree: FnvHashMap < Option < ScopeId > , Vec < ScopeId > > = FnvHashMap ( ) ;
53
70
for ( index, scope_data) in mir. scopes . vec . iter ( ) . enumerate ( ) {
54
71
scope_tree. entry ( scope_data. parent_scope )
55
72
. or_insert ( vec ! [ ] )
56
73
. push ( ScopeId :: new ( index) ) ;
57
74
}
58
- write_scope_tree ( tcx, mir, & scope_tree, w, None , 1 ) ?;
75
+ write_scope_tree ( tcx, mir, auxiliary , & scope_tree, w, None , 1 ) ?;
59
76
60
77
writeln ! ( w, "}}" ) ?;
61
78
Ok ( ( ) )
@@ -115,6 +132,7 @@ fn comment(tcx: &TyCtxt,
115
132
116
133
fn write_scope_tree ( tcx : & TyCtxt ,
117
134
mir : & Mir ,
135
+ auxiliary : Option < & Vec < ScopeAuxiliary > > ,
118
136
scope_tree : & FnvHashMap < Option < ScopeId > , Vec < ScopeId > > ,
119
137
w : & mut Write ,
120
138
parent : Option < ScopeId > ,
@@ -125,14 +143,20 @@ fn write_scope_tree(tcx: &TyCtxt,
125
143
let data = & mir. scopes [ child] ;
126
144
assert_eq ! ( data. parent_scope, parent) ;
127
145
writeln ! ( w, "{0:1$}Scope({2}) {{" , "" , indent, child. index( ) ) ?;
146
+
128
147
let indent = indent + INDENT . len ( ) ;
129
148
if let Some ( parent) = parent {
130
149
writeln ! ( w, "{0:1$}Parent: Scope({2})" , "" , indent, parent. index( ) ) ?;
131
150
}
132
- writeln ! ( w, "{0:1$}Extent: {2:?}" ,
133
- "" , indent,
134
- tcx. region_maps. code_extent_data( data. extent) ) ?;
135
- write_scope_tree ( tcx, mir, scope_tree, w, Some ( child) , depth + 1 ) ?;
151
+
152
+ if let Some ( auxiliary) = auxiliary {
153
+ let extent = auxiliary[ child. index ( ) ] . extent ;
154
+ let data = tcx. region_maps . code_extent_data ( extent) ;
155
+ writeln ! ( w, "{0:1$}Extent: {2:?}" , "" , indent, data) ?;
156
+ }
157
+
158
+ write_scope_tree ( tcx, mir, auxiliary, scope_tree, w,
159
+ Some ( child) , depth + 1 ) ?;
136
160
}
137
161
Ok ( ( ) )
138
162
}
0 commit comments