Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
peephole
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Taddeüs Kroes
peephole
Commits
cf984639
Commit
cf984639
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added comments in debug mode at start and end of basic blocks.
parent
069c57ce
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/program.py
+22
-6
22 additions, 6 deletions
src/program.py
with
22 additions
and
6 deletions
src/program.py
+
22
−
6
View file @
cf984639
from
statement
import
Block
from
statement
import
Statement
as
S
,
Block
from
dataflow
import
find_basic_blocks
,
generate_flow_graph
from
optimize.redundancies
import
remove_redundant_jumps
,
remove_redundancies
from
optimize.advanced
import
eliminate_common_subexpressions
,
\
...
...
@@ -14,14 +14,30 @@ class Program(Block):
return
len
(
self
.
statements
)
if
hasattr
(
self
,
'
statements
'
)
\
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
list.
"""
if
hasattr
(
self
,
'
statements
'
):
return
self
.
statements
else
:
return
reduce
(
lambda
a
,
b
:
a
+
b
,
[
b
.
statements
for
b
in
self
.
blocks
])
# Only add block start and end comments when in debug mode
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
):
"""
Count the number of statements that are commands or labels.
"""
...
...
@@ -91,5 +107,5 @@ class Program(Block):
def
save
(
self
,
filename
):
"""
Save the program in the specified file.
"""
f
=
open
(
filename
,
'
w+
'
)
f
.
write
(
write_statements
(
self
.
get_statements
()))
f
.
write
(
write_statements
(
self
.
get_statements
(
True
)))
f
.
close
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment