annotate graal/com.oracle.max.graal.compiler/src/com/sun/c1x/debug/IdealGraphPrinter.java @ 2872:0341b6424579

Project renaming.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 08:42:25 +0200
parents graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java@7f14e6b48a9c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.*;
2872
0341b6424579 Project renaming.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2866
diff changeset
27 import java.util.Map.*;
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
28
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 import com.oracle.graal.graph.*;
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
30 import com.oracle.max.graal.schedule.*;
2810
6fb5a1bf819f Hide back edges from the output.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2809
diff changeset
31 import com.sun.c1x.ir.*;
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
32
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 * 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
35 * 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
36 */
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 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
38
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 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
40 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
41 final int to;
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
42 final int fromIndex;
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
43 final int toIndex;
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
44
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
45 Edge(int from, int fromIndex, int to, int toIndex) {
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
46 this.from = from;
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
47 this.fromIndex = fromIndex;
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
48 this.to = to;
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
49 this.toIndex = toIndex;
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
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
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 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
54 private final PrintStream stream;
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
55 private final List<Node> noBlockNodes = new LinkedList<Node>();
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
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 * 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
59 */
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 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
61 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
62 }
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 * 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
66 */
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 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
68 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
69 }
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
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 /**
2698
b179be22a3db Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2
Peter Hofer <peter.hofer@jku.at>
parents: 2692
diff changeset
72 * Flushes any buffered output.
b179be22a3db Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2
Peter Hofer <peter.hofer@jku.at>
parents: 2692
diff changeset
73 */
b179be22a3db Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2
Peter Hofer <peter.hofer@jku.at>
parents: 2692
diff changeset
74 public void flush() {
b179be22a3db Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2
Peter Hofer <peter.hofer@jku.at>
parents: 2692
diff changeset
75 stream.flush();
b179be22a3db Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2
Peter Hofer <peter.hofer@jku.at>
parents: 2692
diff changeset
76 }
b179be22a3db Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2
Peter Hofer <peter.hofer@jku.at>
parents: 2692
diff changeset
77
b179be22a3db Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2
Peter Hofer <peter.hofer@jku.at>
parents: 2692
diff changeset
78 /**
2692
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
79 * Starts a new graph document.
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
80 */
2692
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
81 public void begin() {
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
82 stream.println("<graphDocument>");
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
83 }
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
84
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
85 /**
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
86 * Starts a new group of graphs with the given name, short name and method byte code index (BCI) as properties.
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
87 */
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
88 public void beginGroup(String name, String shortName, int bci) {
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
89 stream.println("<group>");
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
90 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
91 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
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
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 /**
2692
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
95 * Ends the current group.
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
96 */
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
97 public void endGroup() {
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
98 stream.println("</group>");
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
99 }
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
100
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
101 /**
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
102 * Finishes the graph document and flushes the output stream.
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
103 */
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 public void end() {
2692
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
105 stream.println("</graphDocument>");
2698
b179be22a3db Allow to submit graphs to IdealGraphVisualizer remotely with new options named after their counterparts in C2
Peter Hofer <peter.hofer@jku.at>
parents: 2692
diff changeset
106 flush();
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
107 }
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 * 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
111 */
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 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
113 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
114
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
115 Schedule schedule = null;
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
116 try {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
117 schedule = new Schedule(graph);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
118 } catch (Throwable t) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
119 // nothing to do here...
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
120 }
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
121
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
122 stream.println(" <nodes>");
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
123 List<Edge> edges = printNodes(graph.getNodes(), shortNames, schedule == null ? null : schedule.getNodeToBlock());
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
124 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
125
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 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
127 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
128 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
129 }
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 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
131
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
132 stream.println(" <controlFlow>");
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
133 if (schedule != null) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
134 for (Block block : schedule.getBlocks()) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
135 printBlock(graph, block);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
136 }
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
137 printNoBlock();
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
138 }
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
139 stream.println(" </controlFlow>");
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
140
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
141 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
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
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
144 private List<Edge> printNodes(Collection<Node> nodes, boolean shortNames, NodeMap<Block> nodeToBlock) {
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
145 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
146
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 for (Node node : nodes) {
2814
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
148 if (node == Node.Null || omittedClasses.contains(node.getClass())) {
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
149 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
150 }
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
2787
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
152 stream.printf(" <node id='%d'><properties>%n", node.id());
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
153 stream.printf(" <p name='idx'>%d</p>%n", node.id());
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
154
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
155 Map<Object, Object> props = node.getDebugProperties();
2793
d3fc4fe063bf Rename BlockBegin to Merge, remove some Block related member from it. Made CFGPrinter work with the Block class from schedule
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2787
diff changeset
156 if (!props.containsKey("name") || props.get("name").toString().trim().length() == 0) {
2787
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
157 String name;
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
158 if (shortNames) {
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
159 name = node.shortName();
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
160 } else {
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
161 name = node.toString();
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
162 }
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
163 stream.printf(" <p name='name'>%s</p>%n", escape(name));
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
164 }
2866
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
165 if (nodeToBlock != null) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
166 Block block = nodeToBlock.get(node);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
167 if (block != null) {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
168 stream.printf(" <p name='block'>%d</p>%n", block.blockID());
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
169 } else {
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
170 stream.printf(" <p name='block'>noBlock</p>%n");
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
171 noBlockNodes.add(node);
7f14e6b48a9c added dead code elimination
Lukas Stadler <lukas.stadler@jku.at>
parents: 2815
diff changeset
172 }
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
173 }
2787
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
174 for (Entry<Object, Object> entry : props.entrySet()) {
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
175 String key = entry.getKey().toString();
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
176 String value = entry.getValue().toString();
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
177 stream.printf(" <p name='%s'>%s</p>%n", escape(key), escape(value));
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
178 }
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
179
2787
9253df721472 Allow to return a map of "debug properties" in Node and subclasses and show these properties in the IdealGraphVisualizer. Also, fix inputCount() and successorCount() for Local.
Peter Hofer <peter.hofer@jku.at>
parents: 2786
diff changeset
180 stream.println(" </properties></node>");
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
181
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
182 // successors
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
183 int fromIndex = 0;
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
184 for (Node successor : node.successors()) {
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
185 if (successor != Node.Null && !omittedClasses.contains(successor.getClass())) {
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
186 edges.add(new Edge(node.id(), fromIndex, successor.id(), 0));
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
187 }
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
188 fromIndex++;
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
189 }
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
190
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
191 // inputs
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
192 int toIndex = 1;
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
193 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
194 if (input != Node.Null && !omittedClasses.contains(input.getClass())) {
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
195 edges.add(new Edge(input.id(), input.successors().size(), node.id(), toIndex));
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
196 }
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
197 toIndex++;
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
198 }
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
199 }
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
200
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
201 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
202 }
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
203
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
204 private void printEdge(Edge edge) {
2786
39a9d62e4c60 IdealGraph visualization: Create a graph that is identical to the GraphViz one, except for some missing unconnected slots
Peter Hofer <peter.hofer@jku.at>
parents: 2698
diff changeset
205 stream.printf(" <edge from='%d' fromIndex='%d' to='%d' toIndex='%d'/>%n", edge.from, edge.fromIndex, edge.to, edge.toIndex);
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
206 }
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
207
2814
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
208 private void printBlock(Graph graph, Block block) {
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
209 stream.printf(" <block name='%d'>%n", block.blockID());
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
210 stream.printf(" <successors>%n");
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
211 for (Block sux : block.getSuccessors()) {
2810
6fb5a1bf819f Hide back edges from the output.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2809
diff changeset
212 if (sux.firstNode() instanceof LoopBegin && block.lastNode() instanceof LoopEnd) {
6fb5a1bf819f Hide back edges from the output.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2809
diff changeset
213 // Skip back edges.
6fb5a1bf819f Hide back edges from the output.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2809
diff changeset
214 } else {
6fb5a1bf819f Hide back edges from the output.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2809
diff changeset
215 stream.printf(" <successor name='%d'/>%n", sux.blockID());
6fb5a1bf819f Hide back edges from the output.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2809
diff changeset
216 }
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
217 }
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
218 stream.printf(" </successors>%n");
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
219 stream.printf(" <nodes>%n");
2814
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
220
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
221 ArrayList<Node> nodes = new ArrayList<Node>(block.getInstructions());
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
222 // if this is the first block: add all locals to this block
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
223 if (nodes.get(0) == graph.start()) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
224 for (Node node : graph.getNodes()) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
225 if (node instanceof Local) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
226 nodes.add(node);
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
227 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
228 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
229 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
230 // add all framestates and phis to their blocks
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
231 for (Node node : block.getInstructions()) {
2814
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
232 if (node instanceof Instruction && ((Instruction) node).stateAfter() != null) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
233 nodes.add(((Instruction) node).stateAfter());
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
234 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
235 if (node instanceof Merge) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
236 Merge merge = (Merge) node;
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
237 if (merge.stateBefore() != null) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
238 nodes.add(merge.stateBefore());
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
239 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
240 for (Node usage : merge.usages()) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
241 if (usage instanceof Phi) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
242 nodes.add(usage);
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
243 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
244 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
245 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
246 }
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
247
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
248 for (Node node : nodes) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
249 if (!omittedClasses.contains(node.getClass())) {
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
250 stream.printf(" <node id='%d'/>%n", node.id());
31e0786a986c IdealGraph: fix omittedClasses, put FrameStates, Locals and Phis into the correct blocks
Lukas Stadler <lukas.stadler@jku.at>
parents: 2809
diff changeset
251 }
2809
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
252 }
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
253 stream.printf(" </nodes>%n");
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
254 stream.printf(" </block>%n", block.blockID());
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
255 }
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
256
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
257 private void printNoBlock() {
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
258 if (!noBlockNodes.isEmpty()) {
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
259 stream.printf(" <block name='noBlock'>%n");
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
260 stream.printf(" <nodes>%n");
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
261 for (Node node : noBlockNodes) {
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
262 stream.printf(" <node id='%d'/>%n", node.id());
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
263 }
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
264 stream.printf(" </nodes>%n");
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
265 stream.printf(" </block>%n");
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
266 }
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
267 }
b003ea36fa12 Add block structure to ideal graph visualizer
Gilles Duboscq <gilles.duboscq@oracle.com>
parents: 2793
diff changeset
268
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
269 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
270 s = s.replace("&", "&amp;");
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
271 s = s.replace("<", "&lt;");
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
272 s = s.replace(">", "&gt;");
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
273 s = s.replace("\"", "&quot;");
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
274 s = s.replace("'", "&apos;");
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
275 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
276 }
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
277 }