Parcourir la source

Extended 'is_arith() method.

Taddeus Kroes il y a 14 ans
Parent
commit
06607dd186
2 fichiers modifiés avec 4 ajouts et 2 suppressions
  1. 1 0
      src/optimize/advanced.py
  2. 3 2
      src/statement.py

+ 1 - 0
src/optimize/advanced.py

@@ -148,6 +148,7 @@ def fold_constants(block):
             # Usage of variable with constant value
             # Usage of variable with constant value
             register[s[0]] = constants[s[1]]
             register[s[0]] = constants[s[1]]
         elif s.name in ['addu', 'subu', 'mult', 'div']:
         elif s.name in ['addu', 'subu', 'mult', 'div']:
+            # TODO: implement 'mult' optimization
             # Calculation with constants
             # Calculation with constants
             rd, rs, rt = s[0], s[1], s[2]
             rd, rs, rt = s[0], s[1], s[2]
             rs_known = rs in register
             rs_known = rs in register

+ 3 - 2
src/statement.py

@@ -62,7 +62,7 @@ class Statement:
 
 
     def is_shift(self):
     def is_shift(self):
         """Check if the statement is a shift operation."""
         """Check if the statement is a shift operation."""
-        return self.is_command() and re.match('^s(ll|la|rl|ra)$', self.name)
+        return self.is_command() and re.match('^s(ll|rl|ra)$', self.name)
 
 
     def is_load(self):
     def is_load(self):
         """Check if the statement is a load instruction."""
         """Check if the statement is a load instruction."""
@@ -71,7 +71,8 @@ class Statement:
     def is_arith(self):
     def is_arith(self):
         """Check if the statement is an arithmetic operation."""
         """Check if the statement is an arithmetic operation."""
         return self.is_command() \
         return self.is_command() \
-               and re.match('^(add|sub|mult|div|abs|neg)(u|\.d)?$', self.name)
+               and re.match('^s(ll|rl|ra)|(add|sub|mflo|abs|neg|slt|sqrt)' \
+                            + '(u|\.s|\.d)?$', self.name)
 
 
     def is_monop(self):
     def is_monop(self):
         """Check if the statement is an unary operation."""
         """Check if the statement is an unary operation."""