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
1e2cf2e9
Commit
1e2cf2e9
authored
13 years ago
by
Jayke Meijer
Browse files
Options
Downloads
Patches
Plain Diff
Added unittests for dag.
parent
1f8dbb4f
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
src/dataflow.py
+1
-1
1 addition, 1 deletion
src/dataflow.py
tests/__init__.pyc
+0
-0
0 additions, 0 deletions
tests/__init__.pyc
tests/test_dataflow.py
+53
-3
53 additions, 3 deletions
tests/test_dataflow.py
with
54 additions
and
4 deletions
src/dataflow.py
+
1
−
1
View file @
1e2cf2e9
...
...
@@ -175,7 +175,7 @@ class Dag:
def
find_op_node
(
self
,
op
,
rd
,
*
args
):
for
n
in
self
.
nodes
:
if
n
.
op
==
op
and
n
.
nodes
==
args
:
if
not
isinstance
(
n
,
DagLeaf
)
and
n
.
op
==
op
and
n
.
nodes
==
args
:
n
.
labels
.
append
(
rd
)
return
n
...
...
This diff is collapsed.
Click to expand it.
tests/__init__.pyc
deleted
100644 → 0
+
0
−
0
View file @
1f8dbb4f
File deleted
This diff is collapsed.
Click to expand it.
tests/test_dataflow.py
+
53
−
3
View file @
1e2cf2e9
...
...
@@ -2,7 +2,7 @@ import unittest
from
src.statement
import
Statement
as
S
from
src.dataflow
import
BasicBlock
as
B
,
find_leaders
,
find_basic_blocks
,
\
generate_flow_graph
,
Dag
generate_flow_graph
,
Dag
,
DagNode
,
DagLeaf
class
TestDataflow
(
unittest
.
TestCase
):
...
...
@@ -45,5 +45,55 @@ class TestDataflow(unittest.TestCase):
self
.
assertIn
(
b1
,
b3
.
edges_from
)
self
.
assertIn
(
b2
,
b3
.
edges_from
)
def
test_dag
(
self
):
pass
def
test_dag_unary
(
self
):
dag
=
Dag
(
B
([
S
(
'
command
'
,
'
neg.d
'
,
'
$rd
'
,
'
$rs
'
)]))
expect
=
Dag
([])
expect
.
nodes
=
[
DagLeaf
(
'
$rs
'
),
DagNode
(
'
neg.d
'
,
'
$rd
'
,
DagLeaf
(
'
$rs
'
))]
self
.
assertEqualDag
(
dag
,
expect
)
def
test_dag_binary
(
self
):
dag
=
Dag
(
B
([
S
(
'
command
'
,
'
addu
'
,
'
$rd
'
,
'
$r1
'
,
'
$r2
'
)]))
expect
=
Dag
([])
expect
.
nodes
=
[
DagLeaf
(
'
$r1
'
),
DagLeaf
(
'
$r2
'
),
DagNode
(
'
addu
'
,
'
$rd
'
,
DagLeaf
(
'
$r1
'
),
DagLeaf
(
'
$r2
'
))]
self
.
assertEqualDag
(
dag
,
expect
)
# def test_dag_combinednode(self):
# dag = Dag(B([S('command', 'mult', '$rd1', '$r1', '$r2'),
# S('command', 'mult', '$rd2', '$r1', '$r2')]))
# expect = Dag([])
# multnode = DagNode('mult',
# DagLeaf('$r1'),
# DagLeaf('$r2'))
# multnode.labels = ['$rd1', '$rd2']
# expect.nodes = [DagLeaf('$r1'),
# DagLeaf('$r2'),
# multnode]
#
# self.assertEqualDag(dag, expect)
def
assertEqualDag
(
self
,
dag1
,
dag2
):
self
.
assertEqual
(
len
(
dag1
.
nodes
),
len
(
dag2
.
nodes
))
for
node1
,
node2
in
zip
(
dag1
.
nodes
,
dag2
.
nodes
):
self
.
assertEqualNodes
(
node1
,
node2
)
def
assertEqualNodes
(
self
,
node1
,
node2
):
if
isinstance
(
node1
,
DagLeaf
):
self
.
assertIsInstance
(
node2
,
DagLeaf
)
self
.
assertEqual
(
node1
.
reg
,
node2
.
reg
)
elif
isinstance
(
node2
,
DagLeaf
):
raise
AssertionError
else
:
self
.
assertEqual
(
node1
.
op
,
node2
.
op
)
self
.
assertEqual
(
node1
.
labels
,
node2
.
labels
)
self
.
assertEqual
(
len
(
node1
.
nodes
),
len
(
node2
.
nodes
))
for
child1
,
child2
in
zip
(
node1
.
nodes
,
node2
.
nodes
):
self
.
assertEqualNodes
(
child1
,
child2
)
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