diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e4ea1239..71a5d57d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## [Unreleased] ### Added - Graphviz graphs colorized +- AS3: Show try graph heads in Graphviz distinguished ### Fixed - Using new FFDec icon on Mac diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java index 8b6943d22..475e77430 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java @@ -31,6 +31,7 @@ import com.jpexs.decompiler.flash.exporters.script.graphviz.TokenType; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.graph.Graph; +import com.jpexs.decompiler.graph.GraphException; import com.jpexs.decompiler.graph.GraphPart; import com.jpexs.decompiler.graph.GraphSource; import com.jpexs.decompiler.graph.ScopeStack; @@ -98,16 +99,41 @@ public class PcodeGraphVizExporter { for (GraphPart h : heads) { populateParts(h, allBlocks); } + List exceptions = graph.getExceptions(); Set knownAddresses = graphSource.getImportantAddresses(); int h = 0; + List exPassedStarts = new ArrayList<>(); + List exPassedEnds = new ArrayList<>(); + for (GraphPart head : heads) { String headName = "start"; - if (heads.size() > 1) { + if (heads.size() > 1 && head.start != 0) { h++; headName = "start" + h; } - writer.append(headName + " [shape=\"circle\"]\r\n"); + String headLabel = ""; + List headLabels = new ArrayList<>(); + for (int e = 0; e < exceptions.size(); e++) { + GraphException ex = exceptions.get(e); + if (head.start == ex.start && !exPassedStarts.contains(e)) { + headLabels.add("try " + e + " begin"); + exPassedStarts.add(e); + break; + } + if (head.start == ex.end && !exPassedEnds.contains(e)) { + headLabels.add("try " + e + " end"); + exPassedEnds.add(e); + break; + } + if (head.start == ex.target) { + headLabels.add("try " + e + " target"); + } + } + if (!headLabels.isEmpty()) { + headLabel = String.join("\\n", headLabels); + } + writer.append(headName + " [shape=\"circle\"" + (headLabel.isEmpty() ? "" : " label=\"" + headLabel + "\"") + "]\r\n"); writer.append(headName + ":s -> " + getBlockName(graphSource, head) + ":n;\r\n"); } for (GraphPart part : allBlocks) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java index 44c285289..51cfb13c1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -124,6 +124,10 @@ public class Graph { } } + public List getExceptions() { + return exceptions; + } + protected static void populateParts(GraphPart part, Set allParts) { if (allParts.contains(part)) { return;