changeset 12511:9e33b386281e

Small refactoring of edge dumping in BinaryGraphPrinter
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 22 Oct 2013 10:15:37 +0200
parents 11dc3108904f
children a7d44c139948
files graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java
diffstat 1 files changed, 30 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Tue Oct 22 10:31:32 2013 +0200
+++ b/graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java	Tue Oct 22 10:15:37 2013 +0200
@@ -407,6 +407,7 @@
             writeInt(node.getId());
             writePoolObject(nodeClass);
             writeByte(node.predecessor() == null ? 0 : 1);
+            // properties
             writeShort((char) props.size());
             for (Entry<Object, Object> entry : props.entrySet()) {
                 String key = entry.getKey().toString();
@@ -414,54 +415,42 @@
                 writePropertyObject(entry.getValue());
             }
             // inputs
-            Collection<Position> directInputPositions = nodeClass.getFirstLevelInputPositions();
-            for (Position pos : directInputPositions) {
-                if (pos.subIndex == NodeClass.NOT_ITERABLE) {
-                    Node in = nodeClass.get(node, pos);
-                    if (in != null) {
-                        writeInt(in.getId());
-                    } else {
-                        writeInt(-1);
-                    }
+            writeEdges(node, nodeClass.getFirstLevelInputPositions());
+            // successors
+            writeEdges(node, nodeClass.getFirstLevelSuccessorPositions());
+
+            props.clear();
+        }
+    }
+
+    private void writeEdges(Node node, Collection<Position> positions) throws IOException {
+        NodeClass nodeClass = node.getNodeClass();
+        for (Position pos : positions) {
+            if (pos.subIndex == NodeClass.NOT_ITERABLE) {
+                Node edge = nodeClass.get(node, pos);
+                writeNodeRef(edge);
+            } else {
+                NodeList<?> list = nodeClass.getNodeList(node, pos);
+                if (list == null) {
+                    writeShort((char) 0);
                 } else {
-                    NodeList<?> list = nodeClass.getNodeList(node, pos);
                     int listSize = list.count();
                     assert listSize == ((char) listSize);
                     writeShort((char) listSize);
-                    for (Node in : list) {
-                        if (in != null) {
-                            writeInt(in.getId());
-                        } else {
-                            writeInt(-1);
-                        }
+                    for (Node edge : list) {
+                        writeNodeRef(edge);
                     }
                 }
             }
-            // successors
-            Collection<Position> directSuccessorPositions = nodeClass.getFirstLevelSuccessorPositions();
-            for (Position pos : directSuccessorPositions) {
-                if (pos.subIndex == NodeClass.NOT_ITERABLE) {
-                    Node sux = nodeClass.get(node, pos);
-                    if (sux != null) {
-                        writeInt(sux.getId());
-                    } else {
-                        writeInt(-1);
-                    }
-                } else {
-                    NodeList<?> list = nodeClass.getNodeList(node, pos);
-                    int listSize = list.count();
-                    assert listSize == ((char) listSize);
-                    writeShort((char) listSize);
-                    for (Node sux : list) {
-                        if (sux != null) {
-                            writeInt(sux.getId());
-                        } else {
-                            writeInt(-1);
-                        }
-                    }
-                }
-            }
-            props.clear();
+        }
+    }
+
+    @SuppressWarnings("deprecation")
+    private void writeNodeRef(Node edge) throws IOException {
+        if (edge != null) {
+            writeInt(edge.getId());
+        } else {
+            writeInt(-1);
         }
     }