comparison graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java @ 2799:e1dad0edd57a

first part of loop reworking
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 27 May 2011 17:48:28 +0200
parents 79590d6b4a7c
children b003ea36fa12
comparison
equal deleted inserted replaced
2798:58e65eb6bb5d 2799:e1dad0edd57a
26 import java.util.regex.*; 26 import java.util.regex.*;
27 27
28 import com.oracle.graal.graph.*; 28 import com.oracle.graal.graph.*;
29 import com.oracle.graal.graph.vis.*; 29 import com.oracle.graal.graph.vis.*;
30 import com.sun.c1x.*; 30 import com.sun.c1x.*;
31 import com.sun.c1x.ir.*;
31 import com.sun.c1x.observer.*; 32 import com.sun.c1x.observer.*;
32 import com.sun.c1x.value.*; 33 import com.sun.c1x.value.*;
33 34
34 /** 35 /**
35 * Observes compilation events and uses {@link GraphvizPrinter} to produce a control flow graph in the DOT language 36 * Observes compilation events and uses {@link GraphvizPrinter} to produce a control flow graph in the DOT language
68 69
69 OutputStream out = null; 70 OutputStream out = null;
70 try { 71 try {
71 if (pdf) { 72 if (pdf) {
72 ByteArrayOutputStream buffer = new ByteArrayOutputStream(); 73 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
73 GraphvizPrinter printer = new GraphvizPrinter(buffer); 74 printGraph(graph, name, buffer);
74 if (C1XOptions.OmitDOTFrameStates) {
75 printer.addOmittedClass(FrameState.class);
76 }
77 printer.begin(name);
78 printer.print(graph, true);
79 printer.end();
80 75
81 out = new FileOutputStream(filename + ".pdf"); 76 out = new FileOutputStream(filename + ".pdf");
82 GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(buffer.toByteArray()), out, "pdf"); 77 GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(buffer.toByteArray()), out, "pdf");
83 } else { 78 } else {
84 out = new FileOutputStream(filename + ".gv"); 79 out = new FileOutputStream(filename + ".gv");
85 80
86 GraphvizPrinter printer = new GraphvizPrinter(out); 81 printGraph(graph, name, out);
87 if (C1XOptions.OmitDOTFrameStates) {
88 printer.addOmittedClass(FrameState.class);
89 }
90 printer.begin(name);
91 printer.print(graph, true);
92 printer.end();
93 } 82 }
94 } catch (IOException e) { 83 } catch (IOException e) {
95 e.printStackTrace(); 84 e.printStackTrace();
96 } finally { 85 } finally {
97 if (out != null) { 86 if (out != null) {
101 } 90 }
102 } 91 }
103 } 92 }
104 } 93 }
105 } 94 }
95
96 private static void printGraph(Graph graph, String name, OutputStream buffer) {
97 GraphvizPrinter printer = new GraphvizPrinter(buffer);
98 if (C1XOptions.OmitDOTFrameStates) {
99 printer.addOmittedClass(FrameState.class);
100 }
101 printer.addClassColor(StartNode.class, "snow3");
102 printer.addClassColor(EndNode.class, "snow3");
103 printer.addClassColor(LoopBegin.class, "skyblue");
104 printer.addClassColor(LoopEnd.class, "skyblue3");
105 printer.addClassColor(Unwind.class, "red");
106 printer.addClassColor(Return.class, "indianred1");
107 printer.begin(name);
108 printer.print(graph, true);
109 printer.end();
110 }
106 } 111 }