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
50c79cdf
Commit
50c79cdf
authored
13 years ago
by
Taddeus Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added possibility to add an inline comment message to a statement replacement.
parent
3d582115
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.py
+2
-0
2 additions, 0 deletions
main.py
src/program.py
+4
-1
4 additions, 1 deletion
src/program.py
src/statement.py
+28
-3
28 additions, 3 deletions
src/statement.py
with
34 additions
and
4 deletions
main.py
+
2
−
0
View file @
50c79cdf
...
...
@@ -2,6 +2,7 @@
from
src.parser
import
parse_file
from
src.optimize
import
optimize
if
__name__
==
'
__main__
'
:
from
sys
import
argv
,
exit
...
...
@@ -12,6 +13,7 @@ if __name__ == '__main__':
# Parse file
program
=
parse_file
(
argv
[
1
])
program
.
debug
=
True
if
len
(
argv
)
>
3
:
# Save input assembly in new file for easy comparison
...
...
This diff is collapsed.
Click to expand it.
src/program.py
+
4
−
1
View file @
50c79cdf
...
...
@@ -71,7 +71,10 @@ class Program(Block):
"""
Divide the statement list into basic blocks.
"""
self
.
blocks
=
find_basic_blocks
(
self
.
statements
)
# Remove the old statment list, since it will probably change
for
b
in
self
.
blocks
:
b
.
debug
=
self
.
debug
# Remove the old statement list, since it will probably change
del
self
.
statements
def
perform_dataflow_analysis
(
self
):
...
...
This diff is collapsed.
Click to expand it.
src/statement.py
+
28
−
3
View file @
50c79cdf
...
...
@@ -38,6 +38,9 @@ class Statement:
def
__repr__
(
self
):
# pragma: nocover
return
str
(
self
)
def
set_inline_comment
(
self
,
comment
):
self
.
options
[
'
comment
'
]
=
comment
def
has_inline_comment
(
self
):
return
'
comment
'
in
self
.
options
and
len
(
self
.
options
[
'
comment
'
])
...
...
@@ -221,7 +224,7 @@ class Statement:
class
Block
:
bid
=
1
def
__init__
(
self
,
statements
=
[]):
def
__init__
(
self
,
statements
=
[]
,
debug
=
False
):
self
.
statements
=
statements
self
.
pointer
=
0
...
...
@@ -229,6 +232,8 @@ class Block:
self
.
bid
=
Block
.
bid
Block
.
bid
+=
1
self
.
debug
=
debug
def
__str__
(
self
):
return
'
<Block bid=%d statements=%d>
'
%
(
self
.
bid
,
len
(
self
))
...
...
@@ -265,7 +270,7 @@ class Block:
return
self
.
statements
[
self
.
pointer
]
if
count
==
1
\
else
self
.
statements
[
self
.
pointer
:
self
.
pointer
+
count
]
def
replace
(
self
,
count
,
replacement
,
start
=
None
):
def
replace
(
self
,
count
,
replacement
,
start
=
None
,
message
=
''
):
"""
Replace the given range start-(start + count) with the given
statement list, and move the pointer to the first statement after the
replacement.
"""
...
...
@@ -275,15 +280,35 @@ class Block:
if
start
==
None
:
start
=
self
.
pointer
-
1
# Add a message in inline comments
if
self
.
debug
:
if
len
(
message
):
message
=
'
'
+
message
if
len
(
replacement
):
replacement
[
0
].
set_inline_comment
(
message
)
for
s
in
replacement
[
1
:]:
s
.
set_inline_comment
(
'
|
'
)
else
:
replacement
=
[
Statement
(
'
comment
'
,
message
)]
elif
not
len
(
replacement
):
# Statement is removed, comment it
replacement
=
[
Statement
(
'
comment
'
,
str
(
b
))
\
for
b
in
self
.
statements
[
start
:
start
+
count
]]
before
=
self
.
statements
[:
start
]
after
=
self
.
statements
[
start
+
count
:]
self
.
statements
=
before
+
replacement
+
after
self
.
pointer
=
start
+
len
(
replacement
)
def
insert
(
self
,
statement
,
index
=
None
):
def
insert
(
self
,
statement
,
index
=
None
,
message
=
''
):
if
index
==
None
:
index
=
self
.
pointer
if
self
.
debug
and
len
(
message
):
statement
.
set_inline_comment
(
'
'
+
message
)
self
.
statements
.
insert
(
index
,
statement
)
def
apply_filter
(
self
,
callback
):
...
...
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