Commit e305a0d2 authored by Jayke Meijer's avatar Jayke Meijer

Added unittests for get_use and fixed bugs coming from that.

parent 0c7d903d
......@@ -82,8 +82,8 @@ class Statement:
def is_store(self):
"""Check if the statement is a store instruction."""
return self.is_command() and self.name in ['sw', 's.d', 'dsw', 's.s', \
's.b']
return self.is_command() and self.name in ['sw', 'sb', 's.d', 'dsw', \
's.s', 's.b']
def is_arith(self):
"""Check if the statement is an arithmetic operation."""
......@@ -186,7 +186,7 @@ class Statement:
or self.is_double_arithmetic() or self.is_double_unary() \
or self.is_logical() or self.is_convert() \
or self.is_truncate() or self.is_set_if_less() \
or self.is_command(*instr):
or self.is_compare() or self.is_command(*instr):
use.append(self[1])
# Case arg1 relative adressing
if self.is_load_non_immediate() or self.is_store():
......@@ -198,7 +198,7 @@ class Statement:
use.append(self[1])
# Case arg2
if self.is_double_arithmetic() or self.is_set_if_less() \
or self.is_logical() \
or self.is_logical() or self.is_truncate() \
or self.is_command(*['addu', 'subu']):
if not isinstance(self[2], int):
use.append(self[2])
......
......@@ -94,7 +94,7 @@ class TestStatement(unittest.TestCase):
self.assertFalse(S('command', 'foo').is_arith())
self.assertFalse(S('label', 'addu').is_arith())
def test_get_def(self):
def test_get_def_true(self):
a = ['a']
self.assertEqual(S('command', 'move', 'a', 'b').get_def(), a)
......@@ -104,6 +104,8 @@ class TestStatement(unittest.TestCase):
self.assertEqual(S('command', 'srl', 'a', 'b', 'c').get_def(), a)
self.assertEqual(S('command', 'la', 'a', '16($fp)').get_def(), a)
self.assertEqual(S('command', 'li', 'a', '16($fp)').get_def(), a)
self.assertEqual(S('command', 'lw', 'a', 'b').get_def(), a)
self.assertEqual(S('command', 'l.d', 'a', 'b').get_def(), a)
self.assertEqual(S('command', 'add.d', 'a', 'b', 'c').get_def(), a)
self.assertEqual(S('command', 'neg.d', 'a', 'b').get_def(), a)
self.assertEqual(S('command', 'sub.d', 'a', 'b', 'c').get_def(), a)
......@@ -111,3 +113,57 @@ class TestStatement(unittest.TestCase):
self.assertEqual(S('command', 'xori', 'a', 'b', '0x0000').get_def(), a)
self.assertEqual(S('command', 'mov.d', 'a', 'b').get_def(), a)
self.assertEqual(S('command', 'dmfc1', 'a', '$f0').get_def(), a)
self.assertEqual(S('command', 'mtc1', 'b', 'a').get_def(), a)
self.assertEqual(S('command', 'trunc.w.d', 'a', 'b', 'c').get_def(), a)
def test_get_def_false(self):
a = []
self.assertEqual(S('command', 'bne', 'a', 'b', 'L1').get_def(), a)
def test_get_use_true(self):
arg1 = ['$1']
arg2 = ['$1', '$2']
self.assertEqual(S('command', 'addu', '$3', '$1', '$2').get_use(), \
arg2)
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', 'move', '$2', '$1').get_use(), arg1)
self.assertEqual(S('command', 'beq', '$1', '$2', '$L1').get_use(), \
arg2)
self.assertEqual(S('command', 'bne', '$1', '$2', '$L1').get_use(), \
arg2)
self.assertEqual(S('command', 'sll', '$2', '$1', 2).get_use(), arg1)
self.assertEqual(S('command', 'lb', '$2', '10($1)').get_use(), arg1)
self.assertEqual(S('command', 'lw', '$2', '10($1)').get_use(), arg1)
self.assertEqual(S('command', 'la', '$2', '10($1)').get_use(), arg1)
self.assertEqual(S('command', 'lb', '$2', 'n.7').get_use(), ['n.7'])
self.assertEqual(S('command', 'lbu', '$2', '10($1)').get_use(), arg1)
self.assertEqual(S('command', 'l.d', '$2', '10($1)').get_use(), arg1)
self.assertEqual(S('command', 's.d', '$1', '10($2)').get_use(), \
arg2)
self.assertEqual(S('command', 's.s', '$1', '10($2)').get_use(), \
arg2)
self.assertEqual(S('command', 'sb', '$1', '10($2)').get_use(), \
arg2)
self.assertEqual(S('command', 'mtc1', '$1', '$2').get_use(), arg1)
self.assertEqual(S('command', 'add.d', '$3', '$1', '$2').get_use(), \
arg2)
self.assertEqual(S('command', 'sub.d', '$3', '$1', '$2').get_use(), \
arg2)
self.assertEqual(S('command', 'div.d', '$3', '$1', '$2').get_use(), \
arg2)
self.assertEqual(S('command', 'mul.d', '$3', '$1', '$2').get_use(), \
arg2)
self.assertEqual(S('command', 'neg.d', '$2', '$1').get_use(), arg1)
self.assertEqual(S('command', 'abs.d', '$2', '$1').get_use(), arg1)
self.assertEqual(S('command', 'dsz', '10($1)', '$2').get_use(), arg1)
self.assertEqual(S('command', 'dsw', '$1', '10($2)').get_use(), arg2)
self.assertEqual(S('command', 'c.lt.d', '$1', '$2').get_use(), arg2)
self.assertEqual(S('command', 'bgez', '$1', '$2').get_use(), arg1)
self.assertEqual(S('command', 'bltz', '$1', '$2').get_use(), arg1)
self.assertEqual(S('command', 'trunc.w.d', '$3', '$1', '$2').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