Skip to content

Commit

Permalink
Tolerate empty final block
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed Sep 30, 2020
1 parent 0b4ae8c commit d19def3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,15 @@ def add_terminators(blocks):
"""
for i, block in enumerate(blocks.values()):
if not block:
dest = list(blocks.keys())[i + 1]
block.append({'op': 'jmp', 'labels': [dest]})
elif block[-1]['op'] not in TERMINATORS:
if i == len(blocks) - 1:
# In the last block, return.
block.append({'op': 'ret', 'args': []})
else:
dest = list(blocks.keys())[i + 1]
block.append({'op': 'jmp', 'labels': [dest]})
elif block[-1]['op'] not in TERMINATORS:
if i == len(blocks) - 1:
block.append({'op': 'ret', 'args': []})
else:
# Otherwise, jump to the next block.
dest = list(blocks.keys())[i + 1]
Expand Down

0 comments on commit d19def3

Please sign in to comment.