annotate graal/GraalCompiler/src/com/sun/c1x/debug/IdealGraphPrinter.java @ 2793:d3fc4fe063bf

Rename BlockBegin to Merge, remove some Block related member from it. Made CFGPrinter work with the Block class from schedule
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Fri, 27 May 2011 11:08:55 +0200
parents 9253df721472
children b003ea36fa12
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.*;
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
27 import java.util.Map.Entry;
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.*;
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 /**
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 * 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
33 * 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
34 */
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 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
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 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
38 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
39 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
40 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
41 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
42
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
43 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
44 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
45 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
46 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
47 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
48 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 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
52 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
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 /**
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 * 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
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 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
58 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
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
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 /**
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 * 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
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 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
65 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
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
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 /**
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
69 * 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
70 */
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
71 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
72 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
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
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 /**
2692
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
76 * 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
77 */
2692
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
78 public void begin() {
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
79 stream.println("<graphDocument>");
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
80 }
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
81
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
82 /**
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
83 * 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
84 */
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
85 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
86 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
87 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
88 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
89 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 /**
2692
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
92 * Ends the current group.
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
93 */
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
94 public void endGroup() {
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
95 stream.println("</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
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
98 /**
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
99 * 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
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 public void end() {
2692
79590d6b4a7c IdealGraphPrinterObserver, GraphvizPrinterObserver: replace possibly invalid characters in file names
Peter Hofer <peter.hofer@jku.at>
parents: 2684
diff changeset
102 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
103 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
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
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 /**
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 * 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
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 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
110 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
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 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
113 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
114 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
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 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
117 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
118 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
119 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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(" </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
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 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
123 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 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
126 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
127
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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 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
129 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
130 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
131 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to 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
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
133 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
134 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
135
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
136 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
137 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
138 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
139 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
140 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
141 } 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
142 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
143 }
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
144 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
145 }
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
146 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
147 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
148 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
149 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
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.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
153
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
154 // 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
155 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
156 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
157 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
158 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
159 }
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
160 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
161 }
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
162
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
163 // 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
164 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
165 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
166 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
167 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
168 }
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
169 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
170 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff changeset
171 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff changeset
172
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff changeset
173 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
174 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff changeset
175
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff changeset
176 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
177 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
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
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff changeset
180 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
181 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
182 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
183 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
184 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
185 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
186 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
187 }
ed36daed4c43 Add new option PrintIdealGraphToFile and another printer/observer pair to generate a graph representation that can be visualized and inspected with the ideal graph visualizer
Peter Hofer <peter.hofer@jku.at>
parents:
diff changeset
188 }