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
50f13735
Commit
50f13735
authored
Dec 29, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:taddeus/peephole
parents
b6b91c9c
58c6acb7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
6 deletions
+48
-6
src/statement.py
src/statement.py
+48
-6
No files found.
src/statement.py
View file @
50f13735
...
@@ -74,7 +74,7 @@ class Statement:
...
@@ -74,7 +74,7 @@ class Statement:
"""Check if the statement is a load instruction."""
"""Check if the statement is a load instruction."""
return
self
.
is_command
()
and
self
.
name
in
[
'lw'
,
'li'
,
'dlw'
,
'l.s'
,
\
return
self
.
is_command
()
and
self
.
name
in
[
'lw'
,
'li'
,
'dlw'
,
'l.s'
,
\
'l.d'
]
'l.d'
]
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
()
\
...
@@ -91,18 +91,60 @@ class Statement:
...
@@ -91,18 +91,60 @@ class Statement:
def is_binop(self):
def is_binop(self):
"""Check if the statement is an binary operation."""
"""Check if the statement is an binary operation."""
return self.is_command() and len(self) == 3 and not self.is_jump()
return self.is_command() and len(self) == 3 and not self.is_jump()
def is_load_non_immediate(self):
"""Check if the statement is a load statement."""
return self.is_command()
\
and re.match('
^
l
(
w
|
a
|
b
|
bu
|
\
.
d
|
\
.
s
)
|
dlw
$
',
\
self.name)
def is_logical(self):
"""Check if the statement is a logical operator."""
return self.is_command() and re.match('
^
(
xor
|
or
|
and
)
i
?$
', self.name)
def is_double_aritmethic(self):
"""Check if the statement is a arithmetic .d operator."""
return self.is_command() and
\
re.match('
^
(
add
|
sub
|
div
|
mul
)
\
.
d
$
', self.name)
def is_double_unary(self):
"""Check if the statement is a unary .d operator."""
return self.is_command() and
\
re.match('
^
(
abs
|
neg
|
mov
)
\
.
d
$
', self.name)
def is_move_from_spec(self):
"""Check if the statement is a move from the result register."""
return self.is_command() and self.name in ['
mflo
', '
mthi
']
def is_set_if_less(self):
"""Check if the statement is a shift if less then."""
return self.is_command() and self.name in ['
slt
', '
sltu
']
def is_convert(self):
"""Check if the statement is a convert operator."""
return self.is_command() and re.match('
^
cvt
\
.[
a
-
z
\
.]
*
$
', self.name)
def is_truncate(self):
"""Check if the statement is a convert operator."""
return self.is_command() and re.match('
^
trunc
\
.[
a
-
z
\
.]
*
$
', self.name)
def jump_target(self):
def jump_target(self):
"""Get the jump target of this statement."""
"""Get the jump target of this statement."""
if not self.is_jump():
if not self.is_jump():
raise Exception('
Command
"%s"
has
no
jump
target
' % self.name)
raise Exception('
Command
"%s"
has
no
jump
target
' % self.name)
return self[-1]
return self[-1]
def get_def(self):
def get_def(self):
# TODO: Finish
"""Get the variable that this statement defines, if any."""
if self.is_load() or self.is_arith():
instr = ['
move
', '
addu
', '
subu
', '
li
', '
mtc1
', '
dmfc1
']
return self[:1]
if self.is_load_non_immediate() or self.is_arith()
\
or self.is_logical() or self.is_double_arithmetic()
\
or self.is_move_from_spec() or self.is_double_unary()
\
or self.is_set_if_less() or self.is_convert()
\
or self.is_truncate() or self.is_load()
\
or (self.is_command and self.name in instr):
return self[0]
return []
return []
...
...
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