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