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
2ed0286f
Commit
2ed0286f
authored
Dec 28, 2011
by
Jayke Meijer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved main to root.
parent
d890c575
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
15 deletions
+62
-15
.gitignore
.gitignore
+2
-0
main.py
main.py
+3
-3
src/optimize/__init__.py
src/optimize/__init__.py
+1
-1
src/optimize/advanced.py
src/optimize/advanced.py
+38
-9
tests/test_optimize_advanced.py
tests/test_optimize_advanced.py
+18
-2
No files found.
.gitignore
View file @
2ed0286f
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
*.out
*.out
*.toc
*.toc
.coverage
.coverage
parser.out
parsetab.py
coverage/
coverage/
build/
build/
src/Makefile_old
src/Makefile_old
src/
main.py
→
main.py
View file @
2ed0286f
#!/usr/bin/python
#!/usr/bin/python
from
parser
import
parse_file
from
src.
parser
import
parse_file
from
optimize
import
optimize
from
src.
optimize
import
optimize
from
writer
import
write_statements
from
src.
writer
import
write_statements
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
from
sys
import
argv
,
exit
from
sys
import
argv
,
exit
...
...
src/optimize/__init__.py
View file @
2ed0286f
from
dataflow
import
find_basic_blocks
from
src.
dataflow
import
find_basic_blocks
from
standard
import
redundant_move_1
,
redundant_move_2
,
\
from
standard
import
redundant_move_1
,
redundant_move_2
,
\
redundant_move_3
,
redundant_move_4
,
redundant_load
,
\
redundant_move_3
,
redundant_move_4
,
redundant_load
,
\
...
...
src/optimize/advanced.py
View file @
2ed0286f
from
statement
import
Statement
as
S
from
s
rc.s
tatement
import
Statement
as
S
def
create_variable
():
def
create_variable
():
...
@@ -109,15 +109,44 @@ def copy_propagation(block):
...
@@ -109,15 +109,44 @@ def copy_propagation(block):
Rename values that were copied to there original, so the copy statement
Rename values that were copied to there original, so the copy statement
might be useless, allowing it to be removed by dead code elimination.
might be useless, allowing it to be removed by dead code elimination.
"""
"""
moves
=
[]
moves
_from
=
[]
count
=
0
moves_to
=
[]
while
not
block
.
end
():
while
not
block
.
end
():
s
=
block
.
read
()
s
=
block
.
read
()
print
"len(s)"
,
len
(
s
)
if
s
.
is_command
(
'move'
):
if
len
(
s
)
==
3
:
moves
.
append
((
s
[
0
],
s
[
1
]))
print
"s[0] = "
,
s
[
0
]
count
+=
1
print
"s[1] = "
,
s
[
1
]
print
"s[2] = "
,
s
[
2
]
print
"count"
,
count
if
moves_from
:
print
moves_from
print
moves_to
if
s
.
is_command
(
'move'
)
and
s
[
0
]
not
in
moves_from
:
moves_from
.
append
(
s
[
0
])
moves_to
.
append
(
s
[
1
])
print
"Added move to list."
elif
s
.
is_command
(
'move'
):
for
i
in
xrange
(
len
(
moves_to
)):
if
moves_to
[
i
]
==
s
[
0
]:
moves_from
[
i
]
=
s
[
1
]
elif
len
(
s
)
==
3
and
s
[
0
]
in
moves_to
:
for
i
in
xrange
(
len
(
moves_to
)):
if
moves_to
[
i
]
==
s
[
0
]:
del
moves_to
[
i
]
del
moves_from
[
i
]
"Removed move from list."
elif
len
(
s
)
==
3
and
(
s
[
1
]
in
moves_to
or
s
[
2
]
in
moves_to
):
print
"Have to propagate."
for
i
in
xrange
(
len
(
moves_to
)):
if
s
[
1
]
==
moves_to
[
i
]:
s
[
1
]
=
moves_from
[
i
]
print
"Propagated"
if
s
[
2
]
==
moves_to
[
i
]:
s
[
2
]
=
moves_from
[
i
]
print
"Propagated"
return
False
return
False
tests/test_optimize_advanced.py
View file @
2ed0286f
import
unittest
import
unittest
from
src.optimize.advanced
import
eliminate_common_subexpressions
from
src.optimize.advanced
import
eliminate_common_subexpressions
,
\
copy_propagation
from
src.statement
import
Statement
as
S
,
Block
as
B
from
src.statement
import
Statement
as
S
,
Block
as
B
class
TestOptimizeAdvanced
(
unittest
.
TestCase
):
class
TestOptimizeAdvanced
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
pass
self
.
foo
=
S
(
'command'
,
'foo'
)
self
.
bar
=
S
(
'command'
,
'bar'
)
def
test_eliminate_common_subexpressions
(
self
):
def
test_eliminate_common_subexpressions
(
self
):
pass
pass
def
test_copy_propagation_true
(
self
):
# block = B([self.foo,
# S('command', 'move', '$1', '$2'),
# self.foo,
# S('command', 'addu', '$3', '$1', '$4'),
# self.bar])
#
# copy_propagation(block)
# self.assertEquals(block.statements, [self.foo,
# S('command', 'move', '$1', '$2'),
# self.foo,
# S('command', 'addu', '$3', '$2', '$4'),
# self.bar])
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