Skip to content

Commit 084db0e

Browse files
committed
cnt analyzer for python3
1 parent 2ed2678 commit 084db0e

File tree

6 files changed

+57
-20
lines changed

6 files changed

+57
-20
lines changed

pyverilog_toolbox/testcode/norm_cnt2.v

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ module TOP(CLK, RSTN, UP_ENABLE, UP_ENABLE2, CLEAR);
22
input CLK,RSTN,UP_ENABLE,UP_ENABLE2,CLEAR;
33

44
reg [2:0] up_cnt;
5-
wire is_count_max = up_cnt == 3'd6;
5+
wire is_cnt_four = up_cnt == 4;
66

77
always @(posedge CLK or negedge RSTN) begin
88
if(!RSTN) begin
99
up_cnt <= 0;
10-
end else if(is_count_max) begin
11-
up_cnt <= 0;
1210
end else if(up_cnt >= 3'd5) begin
1311
up_cnt <= 0;
1412
end else if(CLEAR) begin
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module TOP(CLK, RSTN);
2+
input CLK, RSTN;
3+
4+
reg [2:0] up_cnt;
5+
6+
always @(posedge CLK or negedge RSTN) begin
7+
if(!RSTN) begin
8+
up_cnt <= 0;
9+
end else if(up_cnt2 == 3'd6) begin
10+
up_cnt <= 0;
11+
end else begin
12+
up_cnt <= up_cnt + 1;
13+
end
14+
end
15+
16+
reg now;
17+
always @(posedge CLK or negedge RSTN) begin
18+
if(!RSTN) begin
19+
now <= 0;
20+
end else if(up_cnt == 3'd4) begin
21+
now <= 0;
22+
end else if(up_cnt == 3'd2) begin
23+
now <= 1;
24+
end
25+
end
26+
endmodule
27+

pyverilog_toolbox/testcode/test_ra.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ def test_cnt_analyzer(self):
8686
"\nmax_val: 4\nmother counter:()")
8787
self.assertEqual(cnt_dict['TOP.up_cnt'].tostr(),
8888
'name: TOP.up_cnt\ncategory: up counter\nreset val: 0' +
89-
'\nmax_val: 6\nmother counter:()')
89+
'\nmax_val: 5\nmother counter:()')
9090
self.assertEqual(cnt_dict['TOP.up_cnt2'].tostr(),
9191
"name: TOP.up_cnt2\ncategory: up counter\nreset val: 0" +
9292
"\nmax_val: 4\nmother counter:('TOP.up_cnt',)")
9393
c_analyzer.make_cnt_event_all()
94-
## self.assertEqual(str(c_analyzer.cnt_dict['TOP.up_cnt'].cnt_event_dict),
95-
## '{2: ["TOP.now=\'d1 @(TOP_up_cnt==3\'d2)", "TOP.is_count_max=\'d1 @(TOP_up_cnt==3\'d2)", "TOP.up_cnt2=\'d0 @(TOP_up_cnt==3\'d2)"]}')
94+
self.assertEqual(str(c_analyzer.cnt_dict['TOP.up_cnt'].cnt_event_dict),
95+
'{2: ["TOP.now=\'d1 @(TOP_up_cnt==3\'d2)"]}')
9696

9797
def test_cnt_analyzer2(self):
9898
c_analyzer = CntAnalyzer("norm_cnt.v")

pyverilog_toolbox/verify_tool/bindlibrary.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def __init__(self, bind_library) :
262262
self.scope_dict = bind_library.scope_dict
263263
self.cache = bind_library.cache
264264
self.gnb_cache = bind_library.gnb_cache
265-
self.disable_dfxxx_eq()
265+
#self.disable_dfxxx_eq()
266266

267267
def __del__(self):
268268
self.enable_dfxxx_eq()

pyverilog_toolbox/verify_tool/cnt_analyzer.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,31 @@ def make_cnt_event_all(self):
7979
end
8080
cnt_event_dict[3,'Eq)] = (reg1 <= 1'd1,)
8181
"""
82-
82+
#self.make_term_reffered_dict()
8383
m_setter = MothernodeSetter(self.binds)
8484

8585
for cnt_name, counter in self.cnt_dict.items():
8686
cnt_ref_dict = {}
8787
for term_name in self.term_ref_dict[cnt_name]:
88-
if term_name == cnt_name: continue
88+
if term_name == cnt_name: continue #exclude self reference
8989
scope = self.binds.get_scope(term_name)
9090
target_tree = self.makeTree(scope)
9191
funcdict = splitter.split(target_tree)
9292
funcdict = splitter.remove_reset_condition(funcdict)
93+
if not funcdict: continue
9394
branch_dict = {func[-1]: value for func, value in funcdict.items()}#extract last condition
9495

96+
cnt_ref_branch=[]
97+
m_setter.disable_dfxxx_eq()
9598
for branch, value in branch_dict.items():
96-
cnt_ref_branch=[]
97-
ref_cnt_set = set([])
98-
ref_cnt_set = ref_cnt_set | m_setter.extract_all_dfxxx(branch, set([]), 0, pyverilog.dataflow.dataflow.DFTerminal)
99+
ref_cnt_set = m_setter.extract_all_dfxxx(branch, set([]), 0, pyverilog.dataflow.dataflow.DFTerminal)
99100
ref_cnt_set = set([term[0] for term in ref_cnt_set])
100101
ref_cnt_set = set([term for term in ref_cnt_set if str(term) == cnt_name])
101102
cnt_ref_branch.append((ref_cnt_set, value))
102-
cnt_ref_dict[term_name] = cnt_ref_branch
103+
if cnt_ref_branch:
104+
cnt_ref_dict[term_name] = cnt_ref_branch
105+
m_setter.disable_dfxxx_eq()
103106
counter.make_cnt_event_dict(cnt_ref_dict)
104-
#m_setter.enable_dfxxx_eq()
105-
del m_setter
106107

107108
def get_reset_value(self, cnt_name, target_tree, reset_name):
108109
if target_tree.condnode.operator == 'Ulnot':
@@ -259,26 +260,26 @@ def make_cnt_event_dict(self, cnt_ref_dict):
259260
"""
260261
self.cnt_event_dict = {}
261262
for term_name, ref_cnt_set in cnt_ref_dict.items():
263+
root_ope = None
262264
for ref_cnt,value in ref_cnt_set:
263265
if len(ref_cnt) != 1:
264266
raise Exception('Found redundunt condition description @' + term_name)
265267
ref_cnt = tuple(ref_cnt)[0]
266268

267-
if str(ref_cnt.mother_node) in self.compare_ope:
269+
if ref_cnt.mother_node.operator in self.compare_ope:
268270
root_ope = ref_cnt.mother_node
269271
cond_lsb = 0
270272
diff_list = [1,]
271273
elif isinstance(ref_cnt.mother_node, pyverilog.dataflow.dataflow.DFPartselect):
272-
if str(ref_cnt.mother_node.mother_node) in compare_ope:
274+
if ref_cnt.mother_node.mother_node.operator in self.compare_ope:
273275
root_ope = ref_cnt.mother_node.mother_node
274276
cond_lsb = ref_cnt.mother_node.lsb
275277
if ref_cnt.mother_node.msb == self.msb:
276278
diff_list = [1,]
277279
else:
278280
diff_list = [i for i in range(1,self.msb - ref_cnt.mother_node.msb)]
279-
else:
280-
continue
281281

282+
if root_ope is None: continue
282283
if str(root_ope.nextnodes[0]) == str(ref_cnt.name):
283284
comp_pair = eval_value(root_ope.nextnodes[1])
284285
elif str(root_ope.nextnodes[1]) == str(ref_cnt.name):

pyverilog_toolbox/verify_tool/dataflow_facade.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def get_dataflow(self, code_file_name, topmodule='', config_file=None):
190190
return options.topmodule, terms, binddict, resolved_terms, resolved_binddict, constlist, fsm_vars
191191

192192
def make_term_ref_dict(self):
193-
self.term_ref_dict ={}
193+
self.term_ref_dict = {}
194194
for tv,tk,bvi,bit,term_lsb in self.binds.walk_reg_each_bit():
195195
if 'Rename' in tv.termtype: continue
196196
target_tree = self.makeTree(tk)
@@ -200,6 +200,17 @@ def make_term_ref_dict(self):
200200
self.term_ref_dict[str(tree)] = set([])
201201
self.term_ref_dict[str(tree)].add(str(tk))
202202

203+
def make_term_reffered_dict(self):
204+
if not self.term_ref_dict:
205+
self.make_term_ref_dict
206+
self.term_reffered_dict = {}
207+
for ref, terms in self.term_ref_dict.items():
208+
for term in terms:
209+
if not term in self.term_reffered_dict.keys():
210+
self.term_reffered_dict[term] = []
211+
self.term_reffered_dict[term].append(ref)
212+
#print(self.term_reffered_dict)
213+
203214
def make_extract_dfterm_dict(self):
204215
return_dict = {}
205216
binds = BindLibrary(self.resolved_binddict, self.resolved_terms)

0 commit comments

Comments
 (0)