Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
peephole
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
peephole
Commits
e305a0d2
Commit
e305a0d2
authored
Dec 30, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unittests for get_use and fixed bugs coming from that.
parent
0c7d903d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
5 deletions
+61
-5
src/statement.py
src/statement.py
+4
-4
tests/test_statement.py
tests/test_statement.py
+57
-1
No files found.
src/statement.py
View file @
e305a0d2
...
@@ -82,8 +82,8 @@ class Statement:
...
@@ -82,8 +82,8 @@ class Statement:
def
is_store
(
self
):
def
is_store
(
self
):
"""Check if the statement is a store instruction."""
"""Check if the statement is a store instruction."""
return
self
.
is_command
()
and
self
.
name
in
[
'sw'
,
's
.d'
,
'dsw'
,
's.s
'
,
\
return
self
.
is_command
()
and
self
.
name
in
[
'sw'
,
's
b'
,
's.d'
,
'dsw
'
,
\
's.b'
]
's.
s'
,
's.
b'
]
def
is_arith
(
self
):
def
is_arith
(
self
):
"""Check if the statement is an arithmetic operation."""
"""Check if the statement is an arithmetic operation."""
...
@@ -186,7 +186,7 @@ class Statement:
...
@@ -186,7 +186,7 @@ class Statement:
or self.is_double_arithmetic() or self.is_double_unary()
\
or self.is_double_arithmetic() or self.is_double_unary()
\
or self.is_logical() or self.is_convert()
\
or self.is_logical() or self.is_convert()
\
or self.is_truncate() or self.is_set_if_less()
\
or self.is_truncate() or self.is_set_if_less()
\
or self.is_command(*instr):
or self.is_com
pare() or self.is_com
mand(*instr):
use.append(self[1])
use.append(self[1])
# Case arg1 relative adressing
# Case arg1 relative adressing
if self.is_load_non_immediate() or self.is_store():
if self.is_load_non_immediate() or self.is_store():
...
@@ -198,7 +198,7 @@ class Statement:
...
@@ -198,7 +198,7 @@ class Statement:
use.append(self[1])
use.append(self[1])
# Case arg2
# Case arg2
if self.is_double_arithmetic() or self.is_set_if_less()
\
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
']):
or self.is_command(*['
addu
', '
subu
']):
if not isinstance(self[2], int):
if not isinstance(self[2], int):
use.append(self[2])
use.append(self[2])
...
...
tests/test_statement.py
View file @
e305a0d2
...
@@ -94,7 +94,7 @@ class TestStatement(unittest.TestCase):
...
@@ -94,7 +94,7 @@ class TestStatement(unittest.TestCase):
self
.
assertFalse
(
S
(
'command'
,
'foo'
).
is_arith
())
self
.
assertFalse
(
S
(
'command'
,
'foo'
).
is_arith
())
self
.
assertFalse
(
S
(
'label'
,
'addu'
).
is_arith
())
self
.
assertFalse
(
S
(
'label'
,
'addu'
).
is_arith
())
def
test_get_def
(
self
):
def
test_get_def
_true
(
self
):
a
=
[
'a'
]
a
=
[
'a'
]
self
.
assertEqual
(
S
(
'command'
,
'move'
,
'a'
,
'b'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'command'
,
'move'
,
'a'
,
'b'
).
get_def
(),
a
)
...
@@ -104,6 +104,8 @@ class TestStatement(unittest.TestCase):
...
@@ -104,6 +104,8 @@ class TestStatement(unittest.TestCase):
self
.
assertEqual
(
S
(
'command'
,
'srl'
,
'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
)
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'
,
'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'
,
'add.d'
,
'a'
,
'b'
,
'c'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'command'
,
'neg.d'
,
'a'
,
'b'
).
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
)
self
.
assertEqual
(
S
(
'command'
,
'sub.d'
,
'a'
,
'b'
,
'c'
).
get_def
(),
a
)
...
@@ -111,3 +113,57 @@ class TestStatement(unittest.TestCase):
...
@@ -111,3 +113,57 @@ class TestStatement(unittest.TestCase):
self
.
assertEqual
(
S
(
'command'
,
'xori'
,
'a'
,
'b'
,
'0x0000'
).
get_def
(),
a
)
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'
,
'mov.d'
,
'a'
,
'b'
).
get_def
(),
a
)
self
.
assertEqual
(
S
(
'command'
,
'dmfc1'
,
'a'
,
'$f0'
).
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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment