Skip to content

Commit eeed65b

Browse files
committed
---
yaml --- r: 273521 b: refs/heads/beta c: 0d93989 h: refs/heads/master i: 273519: a55c327
1 parent 2bc8d87 commit eeed65b

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: d32bde3311a035f2a0d7c26cf3170cf98860d701
26+
refs/heads/beta: 0d93989cf5dd479a097a4d58984a482920982aa5
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_mir/pretty.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use build::Location;
11+
use build::{Location, ScopeAuxiliary};
1212
use rustc::mir::repr::*;
1313
use rustc::middle::ty::{self, TyCtxt};
1414
use rustc_data_structures::fnv::FnvHashMap;
@@ -25,14 +25,13 @@ pub fn write_mir_pretty<'a, 'tcx, I>(tcx: &TyCtxt<'tcx>,
2525
-> io::Result<()>
2626
where I: Iterator<Item=(&'a NodeId, &'a Mir<'tcx>)>, 'tcx: 'a
2727
{
28-
let no_annotations = FnvHashMap();
2928
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)?;
3130
}
3231
Ok(())
3332
}
3433

35-
pub enum Annotation {
34+
enum Annotation {
3635
EnterScope(ScopeId),
3736
ExitScope(ScopeId),
3837
}
@@ -41,21 +40,39 @@ pub fn write_mir_fn<'tcx>(tcx: &TyCtxt<'tcx>,
4140
node_id: NodeId,
4241
mir: &Mir<'tcx>,
4342
w: &mut Write,
44-
annotations: &FnvHashMap<Location, Vec<Annotation>>)
43+
auxiliary: Option<&Vec<ScopeAuxiliary>>)
4544
-> 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+
4663
write_mir_intro(tcx, node_id, mir, w)?;
4764
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)?;
4966
}
5067

51-
// construct a scope tree
68+
// construct a scope tree and write it out
5269
let mut scope_tree: FnvHashMap<Option<ScopeId>, Vec<ScopeId>> = FnvHashMap();
5370
for (index, scope_data) in mir.scopes.vec.iter().enumerate() {
5471
scope_tree.entry(scope_data.parent_scope)
5572
.or_insert(vec![])
5673
.push(ScopeId::new(index));
5774
}
58-
write_scope_tree(tcx, mir, &scope_tree, w, None, 1)?;
75+
write_scope_tree(tcx, mir, auxiliary, &scope_tree, w, None, 1)?;
5976

6077
writeln!(w, "}}")?;
6178
Ok(())
@@ -115,6 +132,7 @@ fn comment(tcx: &TyCtxt,
115132

116133
fn write_scope_tree(tcx: &TyCtxt,
117134
mir: &Mir,
135+
auxiliary: Option<&Vec<ScopeAuxiliary>>,
118136
scope_tree: &FnvHashMap<Option<ScopeId>, Vec<ScopeId>>,
119137
w: &mut Write,
120138
parent: Option<ScopeId>,
@@ -125,14 +143,20 @@ fn write_scope_tree(tcx: &TyCtxt,
125143
let data = &mir.scopes[child];
126144
assert_eq!(data.parent_scope, parent);
127145
writeln!(w, "{0:1$}Scope({2}) {{", "", indent, child.index())?;
146+
128147
let indent = indent + INDENT.len();
129148
if let Some(parent) = parent {
130149
writeln!(w, "{0:1$}Parent: Scope({2})", "", indent, parent.index())?;
131150
}
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)?;
136160
}
137161
Ok(())
138162
}

0 commit comments

Comments
 (0)