Skip to content

Commit 23fdd01

Browse files
committed
dataflow_analyzer supports the basic primitives, such as 'and', 'or', and 'not'.
1 parent 3e5f54d commit 23fdd01

File tree

5 files changed

+64
-10
lines changed

5 files changed

+64
-10
lines changed

pyverilog/dataflow/bindvisitor.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,24 @@ def visit_Task(self, node):
135135
self.generic_visit(node)
136136
self.frames.unsetTaskDef()
137137

138+
def _visit_Instance_primitive(self, node):
139+
primitive_type = primitives[node.module]
140+
left = node.portlist[0].argname
141+
right = None
142+
if primitive_type == None:
143+
right = Partselect(node.portlist[1].argname, IntConst('0'), IntConst('0'))
144+
elif primitive_type == Unot:
145+
right = Ulnot(Partselect(node.portlist[1].argname, IntConst('0'), IntConst('0')))
146+
else:
147+
concat_list = [Partselect(p.argname, IntConst('0'), IntConst('0')) for p in node.portlist[1:]]
148+
right = primitive_type(Concat(concat_list))
149+
self.addBind(left, right, bindtype='assign')
150+
138151
def visit_Instance(self, node):
152+
if node.module in primitives:
153+
self._visit_Instance_primitive(node)
154+
return
155+
139156
current = self.stackInstanceFrame(node.name, node.module)
140157

141158
scope = self.frames.getCurrent()

pyverilog/dataflow/signalvisitor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def visit_Initial(self, node):
117117
#self.frames.setCurrent(current)
118118

119119
def visit_Instance(self, node):
120+
if node.module in primitives: return
121+
120122
current = self.stackInstanceFrame(node.name, node.module)
121123

122124
self.setInstanceSimpleConstantTerms()

pyverilog/dataflow/visit.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424
map_key = lambda f,d: collections.OrderedDict([ (f(k),v) for k,v in d.items() ])
2525
map_value = lambda f,d: collections.OrderedDict([ (k,f(v)) for k,v in d.items() ])
2626

27+
################################################################################
28+
# Primitive list
29+
################################################################################
30+
primitives = {
31+
'and' : Uand,
32+
'nand': Unand,
33+
'or' : Uor,
34+
'nor' : Unor,
35+
'xor' : Uxor,
36+
'xnor' : Uxnor,
37+
'not' : Unot,
38+
'buf' : None
39+
}
40+
2741
################################################################################
2842
# Base Visitor
2943
################################################################################

pyverilog/testcode/primitive.v

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
module TOP
2+
(
3+
CLK, RST,
4+
in1, in2, in3, in4,
5+
out0, out1, out2, out3, out4, out5, out6, out7
6+
);
7+
8+
input CLK, RST;
9+
input in1, in2, in3, in4;
10+
output out0, out1, out2, out3, out4, out5, out6, out7;
11+
12+
and U0 (out0, in1, in2, in3, in4);
13+
nand U1 (out1, in1, in2, in3, in4);
14+
or U2 (out2, in1, in2, in3, in4);
15+
nor U3 (out3, in1, in2, in3, in4);
16+
xor U4 (out4, in1, in2, in3, in4);
17+
xnor U5 (out5, in1, in2, in3, in4);
18+
not U6 (out6, in1);
19+
buf U7 (out7, in1);
20+
endmodule
21+

pyverilog/vparser/ast.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,16 +648,16 @@ def children(self):
648648
if self.statement: nodelist.extend(self.statement)
649649
return tuple(nodelist)
650650

651-
#class TaskCall(Node):
652-
# attr_names = ()
653-
# def __init__(self, name, args):
654-
# self.name = name
655-
# self.args = args
656-
# def children(self):
657-
# nodelist = []
658-
# if self.name: nodelist.append(self.name)
659-
# if self.args: nodelist.extend(self.args)
660-
# return tuple(nodelist)
651+
class TaskCall(Node):
652+
attr_names = ()
653+
def __init__(self, name, args):
654+
self.name = name
655+
self.args = args
656+
def children(self):
657+
nodelist = []
658+
if self.name: nodelist.append(self.name)
659+
if self.args: nodelist.extend(self.args)
660+
return tuple(nodelist)
661661

662662
class GenerateStatement(Node):
663663
attr_names = ()

0 commit comments

Comments
 (0)