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
b5507160
Commit
b5507160
authored
Dec 28, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Working on copyprop.
parent
53ac258b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
17 deletions
+34
-17
src/optimize/advanced.py
src/optimize/advanced.py
+10
-7
tests/test_optimize_advanced.py
tests/test_optimize_advanced.py
+24
-10
No files found.
src/optimize/advanced.py
View file @
b5507160
...
@@ -114,25 +114,27 @@ def copy_propagation(block):
...
@@ -114,25 +114,27 @@ def copy_propagation(block):
while
not
block
.
end
():
while
not
block
.
end
():
s
=
block
.
read
()
s
=
block
.
read
()
print
"len(s)"
,
len
(
s
)
if
len
(
s
)
==
3
:
if
len
(
s
)
==
3
:
print
"s[0] = "
,
s
[
0
]
print
"s[0] = "
,
s
[
0
]
print
"s[1] = "
,
s
[
1
]
print
"s[1] = "
,
s
[
1
]
print
"s[2] = "
,
s
[
2
]
print
"s[2] = "
,
s
[
2
]
if
moves_from
:
if
moves_from
:
print
moves_from
print
"fr: "
,
moves_from
print
moves_to
print
"to: "
,
moves_to
if
s
.
is_command
(
'move'
)
and
s
[
0
]
not
in
moves_
from
:
if
s
.
is_command
(
'move'
)
and
s
[
0
]
not
in
moves_
to
:
moves_from
.
append
(
s
[
0
])
moves_from
.
append
(
s
[
1
])
moves_to
.
append
(
s
[
1
])
moves_to
.
append
(
s
[
0
])
print
"Added move to list."
print
"Added move to list."
elif
s
.
is_command
(
'move'
):
elif
s
.
is_command
(
'move'
):
for
i
in
xrange
(
len
(
moves_to
)):
for
i
in
xrange
(
len
(
moves_to
)):
if
moves_to
[
i
]
==
s
[
0
]:
if
moves_to
[
i
]
==
s
[
0
]:
moves_from
[
i
]
=
s
[
1
]
moves_from
[
i
]
=
s
[
1
]
elif
len
(
s
)
==
3
and
s
[
0
]
in
moves_to
:
elif
len
(
s
)
==
3
and
s
[
0
]
in
moves_to
:
print
len
(
s
)
print
len
(
moves_to
)
for
i
in
xrange
(
len
(
moves_to
)):
for
i
in
xrange
(
len
(
moves_to
)):
if
moves_to
[
i
]
==
s
[
0
]:
if
moves_to
[
i
]
==
s
[
0
]:
del
moves_to
[
i
]
del
moves_to
[
i
]
...
@@ -148,5 +150,6 @@ def copy_propagation(block):
...
@@ -148,5 +150,6 @@ def copy_propagation(block):
if
s
[
2
]
==
moves_to
[
i
]:
if
s
[
2
]
==
moves_to
[
i
]:
s
[
2
]
=
moves_from
[
i
]
s
[
2
]
=
moves_from
[
i
]
print
"Propagated"
print
"Propagated"
print
""
return
False
return
False
tests/test_optimize_advanced.py
View file @
b5507160
...
@@ -14,17 +14,31 @@ class TestOptimizeAdvanced(unittest.TestCase):
...
@@ -14,17 +14,31 @@ class TestOptimizeAdvanced(unittest.TestCase):
def
test_eliminate_common_subexpressions
(
self
):
def
test_eliminate_common_subexpressions
(
self
):
pass
pass
def
test_copy_propagation_true
(
self
):
def
test_copy_propagation_true
(
self
):
# block = B([self.foo,
print
"testing true"
block
=
B
([
self
.
foo
,
S
(
'command'
,
'move'
,
'$1'
,
'$2'
),
self
.
foo
,
S
(
'command'
,
'addu'
,
'$3'
,
'$1'
,
'$4'
),
self
.
bar
])
copy_propagation
(
block
)
self
.
assertEqual
(
block
.
statements
,
[
self
.
foo
,
S
(
'command'
,
'move'
,
'$1'
,
'$2'
),
self
.
foo
,
S
(
'command'
,
'addu'
,
'$3'
,
'$2'
,
'$4'
),
self
.
bar
])
print
"Test true succesfull"
# def test_copy_propagation_false(self):
# print "Testing false"
# arguments = [self.foo,
# S('command', 'move', '$1', '$2'),
# S('command', 'move', '$1', '$2'),
# self.foo,
# S('command', 'move', '$10', '$20'),
# S('command', 'addu', '$1', '$5', 1),
# S('command', 'addu', '$3', '$1', '$4'),
# S('command', 'addu', '$3', '$1', '$4'),
# self.bar])
# self.bar]
# block = B(arguments)
#
#
# copy_propagation(block)
# copy_propagation(block)
# self.assertEquals(block.statements, [self.foo,
# self.assertEqual(block.statements, arguments)
# S('command', 'move', '$1', '$2'),
# self.foo,
# S('command', 'addu', '$3', '$2', '$4'),
# self.bar])
pass
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