diff --git a/core/src/main/java/org/teavm/common/GraphBuilder.java b/core/src/main/java/org/teavm/common/GraphBuilder.java index f5d7055c6..bda4123cd 100644 --- a/core/src/main/java/org/teavm/common/GraphBuilder.java +++ b/core/src/main/java/org/teavm/common/GraphBuilder.java @@ -99,11 +99,11 @@ public class GraphBuilder { return builtGraph; } - private static class GraphImpl implements Graph { + private static final class GraphImpl implements Graph { private final int[][] incomingEdgeList; private final int[][] outgoingEdgeList; - public GraphImpl(int[][] incomingEdgeList, int[][] outgoingEdgeList) { + GraphImpl(int[][] incomingEdgeList, int[][] outgoingEdgeList) { this.incomingEdgeList = incomingEdgeList; this.outgoingEdgeList = outgoingEdgeList; } @@ -148,5 +148,27 @@ public class GraphBuilder { public int outgoingEdgesCount(int node) { return outgoingEdgeList[node].length; } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("digraph {\n"); + + for (int i = 0; i < size(); ++i) { + if (outgoingEdgesCount(i) > 0) { + sb.append(" ").append(i).append(" -> { "); + int[] outgoingEdges = outgoingEdges(i); + sb.append(outgoingEdges[0]); + for (int j = 1; j < outgoingEdges.length; ++j) { + sb.append(", ").append(outgoingEdges[j]); + } + sb.append(" }\n"); + } + } + + sb.append("}"); + + return sb.toString(); + } } }