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
cf984639
Commit
cf984639
authored
Dec 30, 2011
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added comments in debug mode at start and end of basic blocks.
parent
069c57ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
src/program.py
src/program.py
+22
-6
No files found.
src/program.py
View file @
cf984639
from
statement
import
Block
from
statement
import
Statement
as
S
,
Block
from
dataflow
import
find_basic_blocks
,
generate_flow_graph
from
dataflow
import
find_basic_blocks
,
generate_flow_graph
from
optimize.redundancies
import
remove_redundant_jumps
,
remove_redundancies
from
optimize.redundancies
import
remove_redundant_jumps
,
remove_redundancies
from
optimize.advanced
import
eliminate_common_subexpressions
,
\
from
optimize.advanced
import
eliminate_common_subexpressions
,
\
...
@@ -14,14 +14,30 @@ class Program(Block):
...
@@ -14,14 +14,30 @@ class Program(Block):
return
len
(
self
.
statements
)
if
hasattr
(
self
,
'statements'
)
\
return
len
(
self
.
statements
)
if
hasattr
(
self
,
'statements'
)
\
else
reduce
(
lambda
a
,
b
:
len
(
a
)
+
len
(
b
),
self
.
blocks
,
0
)
else
reduce
(
lambda
a
,
b
:
len
(
a
)
+
len
(
b
),
self
.
blocks
,
0
)
def
get_statements
(
self
):
def
get_statements
(
self
,
add_block_comments
=
False
):
"""Concatenate the statements of all blocks and return the resulting
"""Concatenate the statements of all blocks and return the resulting
list."""
list."""
if
hasattr
(
self
,
'statements'
):
if
hasattr
(
self
,
'statements'
):
return
self
.
statements
return
self
.
statements
else
:
return
reduce
(
lambda
a
,
b
:
a
+
b
,
# Only add block start and end comments when in debug mode
[
b
.
statements
for
b
in
self
.
blocks
])
if
add_block_comments
and
self
.
debug
:
get_id
=
lambda
b
:
b
.
bid
statements
=
[]
for
b
in
self
.
blocks
:
message
=
' Block %d (%d statements), edges from: %s'
\
%
(
b
.
bid
,
len
(
b
),
map
(
get_id
,
b
.
edges_from
))
statements
.
append
(
S
(
'comment'
,
message
,
block
=
False
))
statements
+=
b
.
statements
message
=
' End of block %d, edges to: %s'
\
%
(
b
.
bid
,
map
(
get_id
,
b
.
edges_to
))
statements
.
append
(
S
(
'comment'
,
message
,
block
=
False
))
return
statements
return
reduce
(
lambda
a
,
b
:
a
+
b
,
[
b
.
statements
for
b
in
self
.
blocks
])
def
count_instructions
(
self
):
def
count_instructions
(
self
):
"""Count the number of statements that are commands or labels."""
"""Count the number of statements that are commands or labels."""
...
@@ -91,5 +107,5 @@ class Program(Block):
...
@@ -91,5 +107,5 @@ class Program(Block):
def
save
(
self
,
filename
):
def
save
(
self
,
filename
):
"""Save the program in the specified file."""
"""Save the program in the specified file."""
f
=
open
(
filename
,
'w+'
)
f
=
open
(
filename
,
'w+'
)
f
.
write
(
write_statements
(
self
.
get_statements
()))
f
.
write
(
write_statements
(
self
.
get_statements
(
True
)))
f
.
close
()
f
.
close
()
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