From 2895bfc050b849fed5989a125d13743b736c2070 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Thu, 15 Jul 2021 00:15:28 +0000 Subject: [PATCH] Another quick goto eliminiation optimization for decompiler. --- bemani/format/afp/decompile.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bemani/format/afp/decompile.py b/bemani/format/afp/decompile.py index 8131a56..9a02819 100644 --- a/bemani/format/afp/decompile.py +++ b/bemani/format/afp/decompile.py @@ -2707,6 +2707,13 @@ class ByteCodeDecompiler(VerboseOutput): if cur_statement.location == next_statement.location: gotos.append(cur_statement) + if ( + isinstance(cur_statement, GotoStatement) and + isinstance(next_statement, GotoStatement) + ): + if cur_statement.location == next_statement.location: + gotos.append(cur_statement) + elif isinstance(cur_statement, DoWhileStatement): # Loops do not "flow" into the next line, they can only "break" to the next # line. Goto of the next line has already been converted to a "break" statement. @@ -2727,6 +2734,7 @@ class ByteCodeDecompiler(VerboseOutput): # switch case first instruction when we don't. This isn't perfect, but eliminates # a lot of gotos in practice. cases = cur_statement.cases + def get_next_instruction(case: SwitchCase) -> Statement: found = False