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

Combined bne and beq optimization.

parent 1af3567d
No related branches found
No related tags found
No related merge requests found
......@@ -68,31 +68,20 @@ def optimize_global(statements):
statements.replace(2, [lw])
continue
# beq ..., $Lx -> bne ..., $Ly
# beq/bne ..., $Lx -> bne/beq ..., $Ly
# j $Ly $Lx:
# $Lx:
if s.is_command('beq'):
if s.is_command('beq') or s.is_command('bne'):
following = statements.peek(2)
if len(following) == 2:
j, label = following
if j.is_command('j') and label.is_label(s[2]):
s.name = 'bne'
s[2] = j[0]
statements.replace(3, [s, label])
# bne ..., $Lx -> beq ..., $Ly
# j $Ly $Lx:
# $Lx:
if s.is_command('bne'):
following = statements.peek(2)
if len(following) == 2:
j, label = following
if j.is_command('j') and label.is_label(s[2]):
s.name = 'beq'
if s.is_command('beq'):
s.name = 'bne'
else:
s.name = 'beq'
s[2] = j[0]
statements.replace(3, [s, label])
......
......@@ -47,7 +47,7 @@ def t_int(t):
return t
def t_WORD(t):
r'[a-zA-Z0-9$_.+()]+'
r'[a-zA-Z0-9$_.+()-]+'
return t
# Ignore whitespaces
......
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