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
9706e239
Commit
9706e239
authored
13 years ago
by
Richard Torenvliet
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:taddeus/peephole
parents
e97d3e56
bb1f3ba0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/statement.py
+6
-1
6 additions, 1 deletion
src/statement.py
tests/__init__.pyc
+0
-0
0 additions, 0 deletions
tests/__init__.pyc
tests/test_optimize.py
+45
-2
45 additions, 2 deletions
tests/test_optimize.py
tests/test_statement.py
+1
-0
1 addition, 0 deletions
tests/test_statement.py
with
52 additions
and
3 deletions
src/statement.py
+
6
−
1
View file @
9706e239
...
...
@@ -21,6 +21,9 @@ class Statement:
arguments.
"""
return
self
.
stype
==
other
.
stype
and
self
.
name
==
other
.
name
\
and
self
.
args
==
other
.
args
def
__len__
(
self
):
return
len
(
self
.
args
)
def
__str__
(
self
):
# pragma: nocover
return
'
<Statement type=%s name=%s args=%s>
'
\
...
...
@@ -115,8 +118,10 @@ class Block:
"""
Replace the given range start-(start + count) with the given
statement list, and move the pointer to the first statement after the
replacement.
"""
if
self
.
pointer
==
0
:
raise
Exception
(
'
No statement have been read yet.
'
)
if
start
==
None
:
start
=
self
.
pointer
start
=
self
.
pointer
-
1
before
=
self
.
statements
[:
start
]
after
=
self
.
statements
[
start
+
count
:]
...
...
This diff is collapsed.
Click to expand it.
tests/__init__.pyc
+
0
−
0
View file @
9706e239
No preview for this file type
This diff is collapsed.
Click to expand it.
tests/test_optimize.py
+
45
−
2
View file @
9706e239
...
...
@@ -9,5 +9,48 @@ class TestOptimize(unittest.TestCase):
def
setUp
(
self
):
pass
def
test_
(
self
):
pass
def
test_optimize_global_movaa
(
self
):
foo
=
S
(
'
command
'
,
'
foo
'
)
bar
=
S
(
'
command
'
,
'
bar
'
)
block
=
B
([
foo
,
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regA
'
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
bar
])
def
test_optimize_global_movab
(
self
):
foo
=
S
(
'
command
'
,
'
foo
'
)
move
=
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
)
bar
=
S
(
'
command
'
,
'
bar
'
)
block
=
B
([
foo
,
move
,
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
move
,
bar
])
def
test_optimize_global_movinst_true
(
self
):
foo
=
S
(
'
command
'
,
'
foo
'
)
bar
=
S
(
'
command
'
,
'
bar
'
)
block
=
B
([
foo
,
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
S
(
'
command
'
,
'
addu
'
,
'
$regA
'
,
'
$regA
'
,
2
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
S
(
'
command
'
,
'
addu
'
,
'
$regA
'
,
'
$regB
'
,
2
),
bar
])
def
test_optimize_global_movinst_false
(
self
):
foo
=
S
(
'
command
'
,
'
foo
'
)
bar
=
S
(
'
command
'
,
'
bar
'
)
block
=
B
([
foo
,
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
S
(
'
command
'
,
'
addu
'
,
'
$regA
'
,
'
$regC
'
,
2
),
bar
])
optimize_global
(
block
)
self
.
assertEquals
(
block
.
statements
,
[
foo
,
S
(
'
command
'
,
'
move
'
,
'
$regA
'
,
'
$regB
'
),
S
(
'
command
'
,
'
addu
'
,
'
$regA
'
,
'
$regC
'
,
2
),
bar
])
This diff is collapsed.
Click to expand it.
tests/test_statement.py
+
1
−
0
View file @
9706e239
...
...
@@ -67,6 +67,7 @@ class TestStatement(unittest.TestCase):
self
.
assertEqual
(
self
.
block
.
peek
(),
S
(
'
comment
'
,
'
bar
'
))
def
test_replace
(
self
):
self
.
block
.
read
()
self
.
block
.
replace
(
1
,
[
S
(
'
command
'
,
'
foobar
'
)])
self
.
assertEqual
(
self
.
block
.
pointer
,
1
)
self
.
assertEqual
(
self
.
block
.
statements
,
[
S
(
'
command
'
,
'
foobar
'
),
\
...
...
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