Преглед изворни кода

Combined bne and beq optimization.

Jayke Meijer пре 14 година
родитељ
комит
7e7ea9b3c4
2 измењених фајлова са 7 додато и 18 уклоњено
  1. 6 17
      src/optimize.py
  2. 1 1
      src/parser.py

+ 6 - 17
src/optimize.py

@@ -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])
 

+ 1 - 1
src/parser.py

@@ -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