Commit 98a981ab authored by Jayke Meijer's avatar Jayke Meijer

Fixed use and def of div instruction.

parent f971a60e
......@@ -141,7 +141,7 @@ def fold_constants(block):
if s.name == 'li':
# Save value in register
if not isinstance(s[1], int):
if not isinstance(s[1], int): # Negative numbers are stored as int
register[s[0]] = int(s[1], 16)
else:
register[s[0]] = s[1]
......@@ -176,6 +176,7 @@ def fold_constants(block):
elif s.name in ['mult', 'div'] \
and s[0]in register and s[1] in register:
# Multiplication/division with constants
print s
rs, rt = s
a, b = register[rs], register[rt]
......
......@@ -154,7 +154,7 @@ class Statement:
def get_def(self):
"""Get the variable that this statement defines, if any."""
instr = ['move', 'addu', 'subu', 'li', 'dmfc1', 'mov.d']
instr = ['div', 'move', 'addu', 'subu', 'li', 'dmfc1', 'mov.d']
if self.is_command('mtc1'):
return [self[1]]
......@@ -178,7 +178,7 @@ class Statement:
if (self.is_branch() \
and not self.is_command(*['bc1f', 'bc1t', 'bct', 'bcf'])) \
or self.is_store() or self.is_compare() \
or self.is_command(*['mult', 'div', 'dsz', 'mtc1']):
or self.is_command(*['mult', 'dsz', 'mtc1']):
if self.name == 'dsz':
m = re.match('^[^(]+\(([^)]+)\)$', self[0])
......@@ -206,7 +206,7 @@ class Statement:
# Case arg2
if self.is_double_arithmetic() or self.is_set_if_less() \
or self.is_logical() or self.is_truncate() \
or self.is_command(*['addu', 'subu']):
or self.is_command(*['addu', 'subu', 'div']):
if not isinstance(self[2], int):
use.append(self[2])
......
......@@ -99,8 +99,9 @@ class TestStatement(unittest.TestCase):
a = ['a']
self.assertEqual(S('command', 'move', 'a', 'b').get_def(), a)
self.assertEqual(S('command', 'subu', 'a', 'b').get_def(), a)
self.assertEqual(S('command', 'subu', 'a', 'b', 'c').get_def(), a)
self.assertEqual(S('command', 'addu', 'a', 'b', 'c').get_def(), a)
self.assertEqual(S('command', 'div', 'a', 'b', 'c').get_def(), a)
self.assertEqual(S('command', 'sll', 'a', 'b', 'c').get_def(), a)
self.assertEqual(S('command', 'srl', 'a', 'b', 'c').get_def(), a)
self.assertEqual(S('command', 'la', 'a', '16($fp)').get_def(), a)
......@@ -130,7 +131,7 @@ class TestStatement(unittest.TestCase):
self.assertEqual(S('command', 'subu', '$3', '$1', '$2').get_use(), \
arg2)
self.assertEqual(S('command', 'mult', '$1', '$2').get_use(), arg2)
self.assertEqual(S('command', 'div', '$1', '$2').get_use(), arg2)
self.assertEqual(S('command', 'div', '$3', '$1', '$2').get_use(), arg2)
self.assertEqual(S('command', 'move', '$2', '$1').get_use(), arg1)
self.assertEqual(S('command', 'beq', '$1', '$2', '$L1').get_use(), \
arg2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment