// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use build::Location;
+use build::{Location, ScopeAuxiliary};
use rustc::mir::repr::*;
use rustc::middle::ty::{self, TyCtxt};
use rustc_data_structures::fnv::FnvHashMap;
-> io::Result<()>
where I: Iterator<Item=(&'a NodeId, &'a Mir<'tcx>)>, 'tcx: 'a
{
- let no_annotations = FnvHashMap();
for (&node_id, mir) in iter {
- write_mir_fn(tcx, node_id, mir, w, &no_annotations)?;
+ write_mir_fn(tcx, node_id, mir, w, None)?;
}
Ok(())
}
-pub enum Annotation {
+enum Annotation {
EnterScope(ScopeId),
ExitScope(ScopeId),
}
node_id: NodeId,
mir: &Mir<'tcx>,
w: &mut Write,
- annotations: &FnvHashMap<Location, Vec<Annotation>>)
+ auxiliary: Option<&Vec<ScopeAuxiliary>>)
-> io::Result<()> {
+ // compute scope/entry exit annotations
+ let mut annotations = FnvHashMap();
+ if let Some(auxiliary) = auxiliary {
+ for (index, auxiliary) in auxiliary.iter().enumerate() {
+ let scope_id = ScopeId::new(index);
+
+ annotations.entry(auxiliary.dom)
+ .or_insert(vec![])
+ .push(Annotation::EnterScope(scope_id));
+
+ for &loc in &auxiliary.postdoms {
+ annotations.entry(loc)
+ .or_insert(vec![])
+ .push(Annotation::ExitScope(scope_id));
+ }
+ }
+ }
+
write_mir_intro(tcx, node_id, mir, w)?;
for block in mir.all_basic_blocks() {
- write_basic_block(tcx, block, mir, w, annotations)?;
+ write_basic_block(tcx, block, mir, w, &annotations)?;
}
- // construct a scope tree
+ // construct a scope tree and write it out
let mut scope_tree: FnvHashMap<Option<ScopeId>, Vec<ScopeId>> = FnvHashMap();
for (index, scope_data) in mir.scopes.vec.iter().enumerate() {
scope_tree.entry(scope_data.parent_scope)
.or_insert(vec![])
.push(ScopeId::new(index));
}
- write_scope_tree(tcx, mir, &scope_tree, w, None, 1)?;
+ write_scope_tree(tcx, mir, auxiliary, &scope_tree, w, None, 1)?;
writeln!(w, "}}")?;
Ok(())
fn write_scope_tree(tcx: &TyCtxt,
mir: &Mir,
+ auxiliary: Option<&Vec<ScopeAuxiliary>>,
scope_tree: &FnvHashMap<Option<ScopeId>, Vec<ScopeId>>,
w: &mut Write,
parent: Option<ScopeId>,
let data = &mir.scopes[child];
assert_eq!(data.parent_scope, parent);
writeln!(w, "{0:1$}Scope({2}) {{", "", indent, child.index())?;
+
let indent = indent + INDENT.len();
if let Some(parent) = parent {
writeln!(w, "{0:1$}Parent: Scope({2})", "", indent, parent.index())?;
}
- writeln!(w, "{0:1$}Extent: {2:?}",
- "", indent,
- tcx.region_maps.code_extent_data(data.extent))?;
- write_scope_tree(tcx, mir, scope_tree, w, Some(child), depth + 1)?;
+
+ if let Some(auxiliary) = auxiliary {
+ let extent = auxiliary[child.index()].extent;
+ let data = tcx.region_maps.code_extent_data(extent);
+ writeln!(w, "{0:1$}Extent: {2:?}", "", indent, data)?;
+ }
+
+ write_scope_tree(tcx, mir, auxiliary, scope_tree, w,
+ Some(child), depth + 1)?;
}
Ok(())
}