about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-03-22 11:52:34 -0400
committerNiko Matsakis <niko@alum.mit.edu>2016-03-23 16:42:53 -0400
commit0d93989cf5dd479a097a4d58984a482920982aa5 (patch)
treeaf05bb23d719cef7846934ccff80e0c75ceae55d
parentd32bde3311a035f2a0d7c26cf3170cf98860d701 (diff)
downloadrust-0d93989cf5dd479a097a4d58984a482920982aa5.tar.gz
rust-0d93989cf5dd479a097a4d58984a482920982aa5.zip
adjust pretty printer to print scopes / auxiliary
-rw-r--r--src/librustc_mir/pretty.rs48
1 files changed, 36 insertions, 12 deletions
diff --git a/src/librustc_mir/pretty.rs b/src/librustc_mir/pretty.rs
index 813766d60c6..650f2d5bcb8 100644
--- a/src/librustc_mir/pretty.rs
+++ b/src/librustc_mir/pretty.rs
@@ -8,7 +8,7 @@
 // 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;
@@ -25,14 +25,13 @@ pub fn write_mir_pretty<'a, 'tcx, I>(tcx: &TyCtxt<'tcx>,
                                      -> 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),
 }
@@ -41,21 +40,39 @@ pub fn write_mir_fn<'tcx>(tcx: &TyCtxt<'tcx>,
                           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(())
@@ -115,6 +132,7 @@ fn comment(tcx: &TyCtxt,
 
 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>,
@@ -125,14 +143,20 @@ fn write_scope_tree(tcx: &TyCtxt,
         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(())
 }