Mercurial > hg > graal-compiler
annotate graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java @ 2684:ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
author | Peter Hofer <peter.hofer@jku.at> |
---|---|
date | Mon, 16 May 2011 17:31:53 +0200 |
parents | |
children | 79590d6b4a7c |
rev | line source |
---|---|
2684
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
1 /* |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
4 * |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
8 * |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
14 * |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
18 * |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
21 * questions. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
22 */ |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
23 package com.sun.c1x.debug; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
24 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
25 import java.io.*; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
26 import java.util.*; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
27 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
28 import com.oracle.graal.graph.*; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
29 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
30 /** |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
31 * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the <a |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
32 * href="http://kenai.com/projects/igv">Ideal Graph Visualizer</a>. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
33 */ |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
34 public class IdealGraphPrinter { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
35 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
36 private static class Edge { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
37 final int from; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
38 final int to; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
39 final int index; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
40 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
41 Edge(int from, int to, int index) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
42 this.from = from; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
43 this.to = to; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
44 this.index = index; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
45 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
46 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
47 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
48 private final HashSet<Class<?>> omittedClasses = new HashSet<Class<?>>(); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
49 private final PrintStream stream; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
50 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
51 /** |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
52 * Creates a new {@link IdealGraphPrinter} that writes to the specified output stream. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
53 */ |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
54 public IdealGraphPrinter(OutputStream stream) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
55 this.stream = new PrintStream(stream); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
56 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
57 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
58 /** |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
59 * Adds a node class that is omitted in the output. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
60 */ |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
61 public void addOmittedClass(Class<?> clazz) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
62 omittedClasses.add(clazz); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
63 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
64 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
65 /** |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
66 * Starts a new graph document containing a single group of graphs with the given name, short name and byte code |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
67 * index (BCI) as properties. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
68 */ |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
69 public void begin(String name, String shortName, int bci) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
70 stream.println("<graphDocument><group>"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
71 stream.printf(" <properties><p name='name'>%s</p></properties>%n", escape(name)); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
72 stream.printf(" <method name='%s' shortName='%s' bci='%d'/>%n", escape(name), escape(shortName), bci); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
73 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
74 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
75 /** |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
76 * Finishes the graph document. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
77 */ |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
78 public void end() { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
79 stream.println("</group></graphDocument>"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
80 stream.flush(); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
81 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
82 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
83 /** |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
84 * Prints an entire {@link Graph} with the specified title, optionally using short names for nodes. |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
85 */ |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
86 public void print(Graph graph, String title, boolean shortNames) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
87 stream.printf(" <graph name='%s'>%n", escape(title)); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
88 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
89 stream.println(" <nodes>"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
90 List<Edge> edges = printNodes(graph.getNodes(), shortNames); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
91 stream.println(" </nodes>"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
92 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
93 stream.println(" <edges>"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
94 for (Edge edge : edges) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
95 printEdge(edge); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
96 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
97 stream.println(" </edges>"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
98 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
99 stream.println(" </graph>"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
100 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
101 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
102 private List<Edge> printNodes(Collection<Node> nodes, boolean shortNames) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
103 ArrayList<Edge> edges = new ArrayList<Edge>(); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
104 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
105 for (Node node : nodes) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
106 if (node == Node.Null || omittedClasses.contains(node)) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
107 continue; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
108 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
109 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
110 String name; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
111 if (shortNames) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
112 name = node.shortName(); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
113 } else { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
114 name = node.toString(); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
115 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
116 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
117 stream.printf(" <node id='%d'><properties>", node.id()); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
118 stream.printf("<p name='idx'>%d</p>", node.id()); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
119 stream.printf("<p name='name'>%s</p>", escape(name)); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
120 stream.println("</properties></node>"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
121 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
122 int index = 0; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
123 for (Node predecessor : node.predecessors()) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
124 if (predecessor != Node.Null && !omittedClasses.contains(predecessor.getClass())) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
125 edges.add(new Edge(predecessor.id(), node.id(), index)); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
126 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
127 index++; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
128 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
129 for (Node input : node.inputs()) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
130 if (input != Node.Null && !omittedClasses.contains(input.getClass())) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
131 edges.add(new Edge(input.id(), node.id(), index)); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
132 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
133 index++; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
134 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
135 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
136 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
137 return edges; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
138 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
139 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
140 private void printEdge(Edge edge) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
141 stream.printf(" <edge from='%d' to='%d' index='%d'/>%n", edge.from, edge.to, edge.index); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
142 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
143 |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
144 private String escape(String s) { |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
145 s = s.replace("&", "&"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
146 s = s.replace("<", "<"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
147 s = s.replace(">", ">"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
148 s = s.replace("\"", """); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
149 s = s.replace("'", "'"); |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
150 return s; |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
151 } |
ed36daed4c43
Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff
changeset
|
152 } |