Mercurial > hg > graal-jvmci-8
comparison graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java @ 2786:39a9d62e4c60
IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
author | Peter Hofer <peter.hofer@jku.at> |
---|---|
date | Wed, 25 May 2011 17:10:53 +0200 |
parents | b179be22a3db |
children | 9253df721472 |
comparison
equal
deleted
inserted
replaced
2785:847dcd4dbd4c | 2786:39a9d62e4c60 |
---|---|
34 public class IdealGraphPrinter { | 34 public class IdealGraphPrinter { |
35 | 35 |
36 private static class Edge { | 36 private static class Edge { |
37 final int from; | 37 final int from; |
38 final int to; | 38 final int to; |
39 final int index; | 39 final int fromIndex; |
40 final int toIndex; | |
40 | 41 |
41 Edge(int from, int to, int index) { | 42 Edge(int from, int fromIndex, int to, int toIndex) { |
42 this.from = from; | 43 this.from = from; |
44 this.fromIndex = fromIndex; | |
43 this.to = to; | 45 this.to = to; |
44 this.index = index; | 46 this.toIndex = toIndex; |
45 } | 47 } |
46 } | 48 } |
47 | 49 |
48 private final HashSet<Class<?>> omittedClasses = new HashSet<Class<?>>(); | 50 private final HashSet<Class<?>> omittedClasses = new HashSet<Class<?>>(); |
49 private final PrintStream stream; | 51 private final PrintStream stream; |
137 stream.printf(" <node id='%d'><properties>", node.id()); | 139 stream.printf(" <node id='%d'><properties>", node.id()); |
138 stream.printf("<p name='idx'>%d</p>", node.id()); | 140 stream.printf("<p name='idx'>%d</p>", node.id()); |
139 stream.printf("<p name='name'>%s</p>", escape(name)); | 141 stream.printf("<p name='name'>%s</p>", escape(name)); |
140 stream.println("</properties></node>"); | 142 stream.println("</properties></node>"); |
141 | 143 |
142 int index = 0; | 144 // successors |
143 for (Node predecessor : node.predecessors()) { | 145 int fromIndex = 0; |
144 if (predecessor != Node.Null && !omittedClasses.contains(predecessor.getClass())) { | 146 for (Node successor : node.successors()) { |
145 edges.add(new Edge(predecessor.id(), node.id(), index)); | 147 if (successor != Node.Null && !omittedClasses.contains(successor.getClass())) { |
148 edges.add(new Edge(node.id(), fromIndex, successor.id(), 0)); | |
146 } | 149 } |
147 index++; | 150 fromIndex++; |
148 } | 151 } |
152 | |
153 // inputs | |
154 int toIndex = 1; | |
149 for (Node input : node.inputs()) { | 155 for (Node input : node.inputs()) { |
150 if (input != Node.Null && !omittedClasses.contains(input.getClass())) { | 156 if (input != Node.Null && !omittedClasses.contains(input.getClass())) { |
151 edges.add(new Edge(input.id(), node.id(), index)); | 157 edges.add(new Edge(input.id(), input.successors().size(), node.id(), toIndex)); |
152 } | 158 } |
153 index++; | 159 toIndex++; |
154 } | 160 } |
155 } | 161 } |
156 | 162 |
157 return edges; | 163 return edges; |
158 } | 164 } |
159 | 165 |
160 private void printEdge(Edge edge) { | 166 private void printEdge(Edge edge) { |
161 stream.printf(" <edge from='%d' to='%d' index='%d'/>%n", edge.from, edge.to, edge.index); | 167 stream.printf(" <edge from='%d' fromIndex='%d' to='%d' toIndex='%d'/>%n", edge.from, edge.fromIndex, edge.to, edge.toIndex); |
162 } | 168 } |
163 | 169 |
164 private String escape(String s) { | 170 private String escape(String s) { |
165 s = s.replace("&", "&"); | 171 s = s.replace("&", "&"); |
166 s = s.replace("<", "<"); | 172 s = s.replace("<", "<"); |