# HG changeset patch # User Gilles Duboscq # Date 1382429737 -7200 # Node ID 9e33b386281ecb09df78f8a903ff354d50758936 # Parent 11dc3108904f666760e8f260fe6cca3dd3d7a327 Small refactoring of edge dumping in BinaryGraphPrinter diff -r 11dc3108904f -r 9e33b386281e graal/com.oracle.graal.printer/src/com/oracle/graal/printer/BinaryGraphPrinter.java --- 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 entry : props.entrySet()) { String key = entry.getKey().toString(); @@ -414,54 +415,42 @@ writePropertyObject(entry.getValue()); } // inputs - Collection 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 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 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); } }