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
c43b02ec
Commit
c43b02ec
authored
Dec 22, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unittest for movA-A replacement, fixed replace.
parent
59b9d767
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
3 deletions
+16
-3
src/optimize.py
src/optimize.py
+1
-0
src/statement.py
src/statement.py
+6
-1
tests/test_optimize.py
tests/test_optimize.py
+8
-2
tests/test_statement.py
tests/test_statement.py
+1
-0
No files found.
src/optimize.py
View file @
c43b02ec
...
...
@@ -13,6 +13,7 @@ def optimize_global(statements):
# mov $regA, $regA -> --- remove it
if
s
.
is_command
(
'move'
)
and
s
[
0
]
==
s
[
1
]:
print
"Let me fix that"
,
s
statements
.
replace
(
1
,
[])
continue
...
...
src/statement.py
View file @
c43b02ec
...
...
@@ -21,6 +21,9 @@ class Statement:
arguments."""
return
self
.
stype
==
other
.
stype
and
self
.
name
==
other
.
name
\
and
self
.
args
==
other
.
args
def
__len__
(
self
):
return
len
(
self
.
args
)
def
__str__
(
self
):
# pragma: nocover
return
'<Statement type=%s name=%s args=%s>'
\
...
...
@@ -115,8 +118,10 @@ class Block:
"""Replace the given range start-(start + count) with the given
statement list, and move the pointer to the first statement after the
replacement."""
if self.pointer == 0:
raise Exception('
No
statement
have
been
read
yet
.
')
if start == None:
start = self.pointer
start = self.pointer
- 1
before = self.statements[:start]
after = self.statements[start + count:]
...
...
tests/test_optimize.py
View file @
c43b02ec
...
...
@@ -9,5 +9,11 @@ class TestOptimize(unittest.TestCase):
def
setUp
(
self
):
pass
def
test_
(
self
):
pass
def
test_optimize_global_movaa
(
self
):
foo
=
S
(
'command'
,
'foo'
)
bar
=
S
(
'command'
,
'baz'
)
block
=
B
([
foo
,
\
S
(
'command'
,
'move'
,
'$regA'
,
'$regA'
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
bar
])
tests/test_statement.py
View file @
c43b02ec
...
...
@@ -67,6 +67,7 @@ class TestStatement(unittest.TestCase):
self
.
assertEqual
(
self
.
block
.
peek
(),
S
(
'comment'
,
'bar'
))
def
test_replace
(
self
):
self
.
block
.
read
()
self
.
block
.
replace
(
1
,
[
S
(
'command'
,
'foobar'
)])
self
.
assertEqual
(
self
.
block
.
pointer
,
1
)
self
.
assertEqual
(
self
.
block
.
statements
,
[
S
(
'command'
,
'foobar'
),
\
...
...
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