# HG changeset patch # User Thomas Wuerthinger # Date 1327694801 -3600 # Node ID 0e7133d1991de7391bb6570921b7344bc99ddfde # Parent 244626f45577a3b9302f740093912bcf09cdeb2c More clean up on igv printer. diff -r 244626f45577 -r 0e7133d1991d graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/BasicIdealGraphPrinter.java --- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/BasicIdealGraphPrinter.java Fri Jan 27 20:53:54 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/BasicIdealGraphPrinter.java Fri Jan 27 21:06:41 2012 +0100 @@ -29,7 +29,7 @@ /** * Elementary, generic generator of Ideal Graph Visualizer input for use in printers for specific data structures. */ -public class BasicIdealGraphPrinter { +class BasicIdealGraphPrinter { /** * Edge between two nodes. diff -r 244626f45577 -r 0e7133d1991d graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java --- a/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java Fri Jan 27 20:53:54 2012 +0100 +++ b/graal/com.oracle.max.graal.printer/src/com/oracle/max/graal/printer/IdealGraphPrinter.java Fri Jan 27 21:06:41 2012 +0100 @@ -34,58 +34,31 @@ import com.oracle.max.graal.graph.NodeClass.Position; import com.oracle.max.graal.java.*; import com.oracle.max.graal.nodes.*; -import com.oracle.max.graal.printer.BasicIdealGraphPrinter.Edge; /** * Generates a representation of {@link Graph Graphs} that can be visualized and inspected with the Ideal Graph Visualizer. */ -class IdealGraphPrinter { - - private final BasicIdealGraphPrinter printer; - private final HashSet> omittedClasses = new HashSet<>(); - private final Set noBlockNodes = new HashSet<>(); - +class IdealGraphPrinter extends BasicIdealGraphPrinter { /** * Creates a new {@link IdealGraphPrinter} that writes to the specified output stream. */ public IdealGraphPrinter(OutputStream stream) { - this.printer = new BasicIdealGraphPrinter(stream); - } - - /** - * Adds a node class that is omitted in the output. - */ - public void addOmittedClass(Class clazz) { - omittedClasses.add(clazz); - } - - /** - * Flushes any buffered output. - */ - public void flush() { - printer.flush(); - } - - /** - * Starts a new graph document. - */ - public void begin() { - printer.begin(); + super(stream); } /** * Starts a new group of graphs with the given name, short name and method byte code index (BCI) as properties. */ public void beginGroup(String name, String shortName, RiResolvedMethod method, int bci, String origin) { - printer.beginGroup(); - printer.beginProperties(); - printer.printProperty("name", name); - printer.printProperty("origin", origin); - printer.endProperties(); - printer.beginMethod(name, shortName, bci); + beginGroup(); + beginProperties(); + printProperty("name", name); + printProperty("origin", origin); + endProperties(); + beginMethod(name, shortName, bci); if (method != null) { - printer.beginBytecodes(); + beginBytecodes(); BytecodeStream bytecodes = new BytecodeStream(method.code()); while (bytecodes.currentBC() != Bytecodes.END) { int startBCI = bytecodes.currentBCI(); @@ -97,38 +70,24 @@ extra[i] = bytecodes.readUByte(startBCI + 1 + i); } } - printer.printBytecode(startBCI, mnemonic, extra); + printBytecode(startBCI, mnemonic, extra); bytecodes.next(); } - printer.endBytecodes(); + endBytecodes(); } - printer.endMethod(); + endMethod(); } - /** - * Ends the current group. - */ - public void endGroup() { - printer.endGroup(); - } - - /** - * Finishes the graph document and flushes the output stream. - */ - public void end() { - printer.end(); - } - - public void print(Graph graph, String title, boolean shortNames) { - print(graph, title, shortNames, null); + public void print(Graph graph, String title) { + print(graph, title, null); } /** * Prints an entire {@link Graph} with the specified title, optionally using short names for nodes. */ - public void print(Graph graph, String title, boolean shortNames, IdentifyBlocksPhase predefinedSchedule) { - printer.beginGraph(title); - noBlockNodes.clear(); + public void print(Graph graph, String title, IdentifyBlocksPhase predefinedSchedule) { + beginGraph(title); + Set noBlockNodes = new HashSet<>(); IdentifyBlocksPhase schedule = predefinedSchedule; if (schedule == null) { try { @@ -139,30 +98,30 @@ } } - printer.beginNodes(); - List edges = printNodes(graph, shortNames, schedule == null ? null : schedule.getNodeToBlock()); - printer.endNodes(); + beginNodes(); + List edges = printNodes(graph, schedule == null ? null : schedule.getNodeToBlock(), noBlockNodes); + endNodes(); - printer.beginEdges(); + beginEdges(); for (Edge edge : edges) { - printer.printEdge(edge); + printEdge(edge); } - printer.endEdges(); + endEdges(); if (schedule != null) { - printer.beginControlFlow(); + beginControlFlow(); for (Block block : schedule.getBlocks()) { printBlock(graph, block, schedule.getNodeToBlock()); } - printNoBlock(); - printer.endControlFlow(); + printNoBlock(noBlockNodes); + endControlFlow(); } - printer.endGraph(); + endGraph(); flush(); } - private List printNodes(Graph graph, boolean shortNames, NodeMap nodeToBlock) { + private List printNodes(Graph graph, NodeMap nodeToBlock, Set noBlockNodes) { ArrayList edges = new ArrayList<>(); NodeMap>> colors = graph.createNodeMap(); @@ -170,33 +129,25 @@ NodeMap> bits = graph.createNodeMap(); for (Node node : graph.getNodes()) { - if (omittedClasses.contains(node.getClass())) { - continue; - } - printer.beginNode(node.toString(Verbosity.Id)); - printer.beginProperties(); - printer.printProperty("idx", node.toString(Verbosity.Id)); + beginNode(node.toString(Verbosity.Id)); + beginProperties(); + printProperty("idx", node.toString(Verbosity.Id)); Map props = node.getDebugProperties(); if (!props.containsKey("name") || props.get("name").toString().trim().length() == 0) { - String name; - if (shortNames) { - name = node.toString(Verbosity.Name); - } else { - name = node.toString(); - } - printer.printProperty("name", name); + String name = node.toString(Verbosity.Name); + printProperty("name", name); } - printer.printProperty("class", node.getClass().getSimpleName()); + printProperty("class", node.getClass().getSimpleName()); Block block = nodeToBlock == null ? null : nodeToBlock.get(node); if (block != null) { - printer.printProperty("block", Integer.toString(block.blockID())); + printProperty("block", Integer.toString(block.blockID())); if (!(node instanceof PhiNode || node instanceof FrameState || node instanceof LocalNode) && !block.getInstructions().contains(node)) { - printer.printProperty("notInOwnBlock", "true"); + printProperty("notInOwnBlock", "true"); } } else { - printer.printProperty("block", "noBlock"); + printProperty("block", "noBlock"); noBlockNodes.add(node); } @@ -205,7 +156,7 @@ for (Entry color : nodeColors) { String name = color.getKey(); Integer value = color.getValue(); - printer.printProperty(name, Integer.toString(value)); + printProperty(name, Integer.toString(value)); } } Set> nodeColorStrings = colorsToString.get(node); @@ -213,24 +164,24 @@ for (Entry color : nodeColorStrings) { String name = color.getKey(); String value = color.getValue(); - printer.printProperty(name, value); + printProperty(name, value); } } Set nodeBits = bits.get(node); if (nodeBits != null) { for (String bit : nodeBits) { - printer.printProperty(bit, "true"); + printProperty(bit, "true"); } } for (Entry entry : props.entrySet()) { String key = entry.getKey().toString(); String value = entry.getValue() == null ? "null" : entry.getValue().toString(); - printer.printProperty(key, value); + printProperty(key, value); } - printer.endProperties(); - printer.endNode(); + endProperties(); + endNode(); // successors int fromIndex = 0; @@ -238,7 +189,7 @@ while (succIter.hasNext()) { Position position = succIter.nextPosition(); Node successor = node.getNodeClass().get(node, position); - if (successor != null && !omittedClasses.contains(successor.getClass())) { + if (successor != null) { edges.add(new Edge(node.toString(Verbosity.Id), fromIndex, successor.toString(Verbosity.Id), 0, node.getNodeClass().getName(position))); } fromIndex++; @@ -250,7 +201,7 @@ while (inputIter.hasNext()) { Position position = inputIter.nextPosition(); Node input = node.getNodeClass().get(node, position); - if (input != null && !omittedClasses.contains(input.getClass())) { + if (input != null) { edges.add(new Edge(input.toString(Verbosity.Id), input.successors().explicitCount(), node.toString(Verbosity.Id), toIndex, node.getNodeClass().getName(position))); } toIndex++; @@ -261,15 +212,15 @@ } private void printBlock(Graph graph, Block block, NodeMap nodeToBlock) { - printer.beginBlock(Integer.toString(block.blockID())); - printer.beginSuccessors(); + beginBlock(Integer.toString(block.blockID())); + beginSuccessors(); for (Block sux : block.getSuccessors()) { if (sux != null) { - printer.printSuccessor(Integer.toString(sux.blockID())); + printSuccessor(Integer.toString(sux.blockID())); } } - printer.endSuccessors(); - printer.beginBlockNodes(); + endSuccessors(); + beginBlockNodes(); Set nodes = new HashSet<>(block.getInstructions()); @@ -305,24 +256,22 @@ } for (Node node : nodes) { - if (!omittedClasses.contains(node.getClass())) { - printer.printBlockNode(node.toString(Verbosity.Id)); - } + printBlockNode(node.toString(Verbosity.Id)); } } - printer.endBlockNodes(); - printer.endBlock(); + endBlockNodes(); + endBlock(); } - private void printNoBlock() { + private void printNoBlock(Set noBlockNodes) { if (!noBlockNodes.isEmpty()) { - printer.beginBlock("noBlock"); - printer.beginBlockNodes(); + beginBlock("noBlock"); + beginBlockNodes(); for (Node node : noBlockNodes) { - printer.printBlockNode(node.toString(Verbosity.Id)); + printBlockNode(node.toString(Verbosity.Id)); } - printer.endBlockNodes(); - printer.endBlock(); + endBlockNodes(); + endBlock(); } }