Skip to content
Snippets Groups Projects
Commit 2bcdcaff authored by Jayke Meijer's avatar Jayke Meijer
Browse files

Added function to simplify branch-jump combos. Not function properly yet.

parent 1ea1d70f
No related branches found
No related tags found
No related merge requests found
......@@ -10,9 +10,38 @@ def empty_shift(statement):
stype, name, args = statement
return stype == 'command' and name in shift_types and \
args['args'][0] == args['args'][1] and args['args'][2] == 0
def optimize_branch_jump_label(statements):
'''Optimize jumps after branches.'''
out_statements = []
for i in xrange(len(statements)):
if i + 3 > len(statements):
out_statements.append(statements[i])
continue
stype, name, args = statements[i]
stype2, name2, args2 = statements[i + 1]
stype3, name3, args3 = statements[i + 2]
if stype == 'command' and name == 'beq' and \
stype2 == 'command' and name2 in ['j', 'jal'] and \
stype3 == 'label' and name3 == args['args'][2]:
out_statements.append(('command', 'bne', \
{'args': [args['args'][0], args['args'][1], args2['args'][0]]}))
out_statements.append(statements[1 + 2])
i += 3
else:
out_statements.append(statements[i])
return out_statements
def optimize_global(statements):
'''Optimize one-line statements in entire code.'''
statements = optimize_branch_jump_label(statements)
return filter(lambda s: not equal_mov(s) and not empty_shift(s), statements)
def optimize_blocks(blocks):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment