From 8cf219cb25c5f74a00cc32d2926c736d9e088198 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Mon, 26 Apr 2021 03:24:24 +0000 Subject: [PATCH] Avoid duplicating labels outside of and inside of do-while statements. Avoid going to or generating negative labels (artificially inserted nodes). --- bemani/format/afp/decompile.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bemani/format/afp/decompile.py b/bemani/format/afp/decompile.py index 1613379..a3c9208 100644 --- a/bemani/format/afp/decompile.py +++ b/bemani/format/afp/decompile.py @@ -180,6 +180,9 @@ class ContinueStatement(Statement): class GotoStatement(Statement): # A goto, including the ID of the chunk we want to jump to. def __init__(self, location: int) -> None: + if location < 0: + raise Exception(f"Logic error, attempting to go to artificially inserted location {location}!") + self.location = location def __repr__(self) -> str: @@ -2600,9 +2603,6 @@ class ByteCodeDecompiler(VerboseOutput): else: next_chunk_id = next_id - # Make sure when we collapse chunks, we don't lose labels. - statements.append(DefineLabelStatement(start_id)) - if isinstance(chunk, Loop): # Evaluate the loop. No need to update per-chunk stacks here since we will do it in a child eval. self.vprint(f"Evaluating graph in Loop {chunk.id}") @@ -2614,6 +2614,10 @@ class ByteCodeDecompiler(VerboseOutput): # We should have evaluated this earlier! raise Exception("Logic error!") else: + if start_id >= 0: + # Make sure when we collapse chunks, we don't lose labels. + statements.append(DefineLabelStatement(start_id)) + # Grab the computed start stack for this ID stack = stacks[chunk.id] del stacks[chunk.id]