From 9ed409df4516e0089afbc7d5ccf9b029d431be04 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Sun, 3 Mar 2024 17:55:47 +0000 Subject: Chapter 9: Global Value Numbering and Iterative Peepholes Co-authored-by: Cliff Click Co-authored-by: XmiliaH <45106915+XmiliaH@users.noreply.github.com> Co-authored-by: Robert Obkircher Co-authored-by: Dibyendu Majumdar Co-authored-by: Darrick Wiebe --- .../com/seaofnodes/simple/GraphVisualizer.java | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'src/main/java/com/seaofnodes/simple/GraphVisualizer.java') diff --git a/src/main/java/com/seaofnodes/simple/GraphVisualizer.java b/src/main/java/com/seaofnodes/simple/GraphVisualizer.java index d75e5bea..b4d64d4c 100644 --- a/src/main/java/com/seaofnodes/simple/GraphVisualizer.java +++ b/src/main/java/com/seaofnodes/simple/GraphVisualizer.java @@ -20,15 +20,16 @@ public class GraphVisualizer { public GraphVisualizer(boolean separateControlCluster) { this._separateControlCluster = separateControlCluster; } public GraphVisualizer() { this(false); } - public String generateDotOutput(Parser parser) { + public String generateDotOutput(Parser parse) { return generateDotOutput(parse.STOP,parse._scope,parse._xScopes); } + public String generateDotOutput(StopNode stop, Node scope, Stack xScopes) { // Since the graph has cycles, we need to create a flat list of all the // nodes in the graph. - Collection all = findAll(parser); + Collection all = findAll(stop, scope); StringBuilder sb = new StringBuilder(); - sb.append("digraph chapter08 {\n"); + sb.append("digraph chapter09 {\n"); sb.append("/*\n"); - sb.append(parser.src()); + sb.append(stop._src); sb.append("\n*/\n"); // To keep the Scopes below the graph and pointing up into the graph we @@ -52,15 +53,19 @@ public class GraphVisualizer { nodes(sb, all); // Now the scopes, in a cluster no edges - for( ScopeNode scope : parser._xScopes ) - scope( sb, scope ); + if( xScopes != null ) + for( ScopeNode xscope : xScopes ) + if( !xscope.isDead() ) + scope( sb, xscope ); // Walk the Node edges nodeEdges(sb, all); // Walk the active Scope edges - for( ScopeNode scope : parser._xScopes ) - scopeEdges( sb, scope ); + if( xScopes != null ) + for( ScopeNode xscope : xScopes ) + if( !xscope.isDead() ) + scopeEdges( sb, xscope ); sb.append("}\n"); return sb.toString(); @@ -232,12 +237,13 @@ public class GraphVisualizer { /** * Finds all nodes in the graph. */ - private Collection findAll(Parser parser) { + private Collection findAll(Node stop, Node scope) { final HashMap all = new HashMap<>(); - for( Node n : Parser.START._outputs ) - walk(all, n); - for( Node n : parser._scope._inputs ) + for( Node n : stop._inputs ) walk(all, n); + if( scope != null ) + for( Node n : scope._inputs ) + walk(all, n); return all.values(); } -- cgit v1.2.3