Skip to content

Commit

Permalink
Still print catch targets in the decompiled code though
Browse files Browse the repository at this point in the history
  • Loading branch information
p1-mmr committed Mar 16, 2023
1 parent a81706a commit d71d628
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
29 changes: 13 additions & 16 deletions src/decompilation/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,19 @@ def output_code(self, state : HermesDecompiler):
output += (' ' * (state.indent_level * 4)) + '}\n'

if len(basic_block_starts) > 1 and pos in basic_block_starts:
output += 'case %d:\n' % pos
"""
# Commented: Unused now that we have basic blocks:
if pos in self.try_starts:
for label in self.try_starts[pos]:
output += '%s:\n' % label
if pos in self.try_ends:
for label in self.try_ends[pos]:
output += '%s:\n' % label
if pos in self.catch_targets:
for label in self.catch_targets[pos]:
output += '%s:\n' % label
if pos in self.jump_targets:
output += 'label_%d:\n' % pos
"""
output += 'case %d:' % pos

if pos in self.try_starts:
for label in self.try_starts[pos]:
output += ' // %s' % label
if pos in self.try_ends:
for label in self.try_ends[pos]:
output += ' // %s' % label
if pos in self.catch_targets:
for label in self.catch_targets[pos]:
output += ' // %s' % label

output += '\n'

while pos in nested_frame_starts:
nested_frame_starts.pop(nested_frame_starts.index(pos))
Expand Down
16 changes: 8 additions & 8 deletions tests/sample.hermes_dec_hdec
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,25 @@ case 19:
case 21:
ResumeGenerator(result_out_reg=1, return_bool_out_reg=4);
if(r4) { _fun5_ip = 173; continue _fun5 }
case 30:
case 30: // try_start_0 // try_start_1
r4 = global;
r4 = r4.gen;
r5 = r4.bind(r2)();
r4 = r5.next;
r4 = r4.bind(r5)();
case 50:
case 50: // try_end0
_fun5_ip = 71; continue _fun5;
case 52:
case 52: // catch_target0
CatchBlockStart(arg_register=4);
r4 = global;
r5 = r4.print;
r4 = 'Hello! Exception handling';
r4 = r5.bind(r2)(r4);
case 71:
case 71: // try_end1
_fun5_ip = 170; continue _fun5;
case 73:
case 73: // catch_target1
CatchBlockStart(arg_register=3);
case 75:
case 75: // try_start_2
r5 = 432;
r4 = 'dçdàçD°D+D';
r5 = r5 * r4;
Expand All @@ -119,9 +119,9 @@ case 102:
r3 = 6;
r3 = r7 + r3;
r3 = r5.bind(r6)(r4, r3);
case 149:
case 149: // try_end2
_fun5_ip = 170; continue _fun5;
case 151:
case 151: // catch_target2
CatchBlockStart(arg_register=3);
r3 = global;
r4 = r3.alert;
Expand Down

0 comments on commit d71d628

Please sign in to comment.