diff graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java @ 2602:0c6564c254af

new node layout: BlockBegin, BlockEnd -Dc1x.dot=regex for pdf output escape dot graph labels (<, >, &)
author Lukas Stadler <lukas.stadler@jku.at>
date Fri, 06 May 2011 10:25:37 +0200
parents 268b8eb84b6e
children 01c5c0443158
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java	Thu May 05 16:33:12 2011 +0200
+++ b/graal/GraalCompiler/src/com/sun/c1x/C1XCompiler.java	Fri May 06 10:25:37 2011 +0200
@@ -22,8 +22,12 @@
  */
 package com.sun.c1x;
 
+import java.io.*;
 import java.util.*;
 
+import com.oracle.graal.graph.*;
+import com.oracle.graal.graph.vis.*;
+import com.oracle.graal.graph.vis.GraphvizTest.*;
 import com.sun.c1x.debug.*;
 import com.sun.c1x.globalstub.*;
 import com.sun.c1x.observer.*;
@@ -125,6 +129,45 @@
         if (C1XOptions.PrintCFGToFile) {
             addCompilationObserver(new CFGPrinterObserver());
         }
+        String dot = System.getProperty("c1x.dot");
+        if (dot != null && !dot.isEmpty()) {
+            if (!dot.endsWith("$")) {
+                dot = dot + ".*";
+            }
+            if (!dot.startsWith("^")) {
+                dot = ".*" + dot;
+            }
+            final String dotPattern = dot;
+            addCompilationObserver(new CompilationObserver() {
+                private Graph graph;
+                public void compilationStarted(CompilationEvent event) {
+                }
+                public void compilationFinished(CompilationEvent event) {
+                    String name = event.getMethod().holder().name();
+                    name = name.substring(1, name.length() - 1).replace('/', '.');
+                    name = name + "." + event.getMethod().name();
+                    if (name.matches(dotPattern)) {
+                        ByteArrayOutputStream out = new ByteArrayOutputStream();
+                        GraphvizPrinter printer = new GraphvizPrinter(out);
+                        printer.begin("Simple test");
+                        printer.print(graph);
+                        printer.end();
+
+                        try {
+                            GraphvizRunner.process(GraphvizRunner.DOT_COMMAND, new ByteArrayInputStream(out.toByteArray()),
+                                            new FileOutputStream(name + ".pdf"), "pdf");
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
+                public void compilationEvent(CompilationEvent event) {
+                    if (event.getStartBlock() != null) {
+                        graph = event.getStartBlock().graph();
+                    }
+                }
+            });
+        }
     }
 
     public GlobalStub lookupGlobalStub(GlobalStub.Id id) {