|
1 |
| -#------------------------------------------------------------------------------- |
| 1 | +# ------------------------------------------------------------------------------- |
2 | 2 | # active_analyzer.py
|
3 | 3 | #
|
4 | 4 | # Active condition list generator from Verilog Definitions
|
5 | 5 | #
|
6 | 6 | # Copyright (C) 2013, Shinya Takamaeda-Yamazaki
|
7 | 7 | # License: Apache 2.0
|
8 |
| -#------------------------------------------------------------------------------- |
| 8 | +# ------------------------------------------------------------------------------- |
9 | 9 | from __future__ import absolute_import
|
10 | 10 | from __future__ import print_function
|
11 | 11 | import sys
|
|
16 | 16 | import pyverilog.controlflow.transition as transition
|
17 | 17 | from pyverilog.controlflow.controlflow_analyzer import VerilogControlflowAnalyzer
|
18 | 18 |
|
| 19 | + |
19 | 20 | class VerilogActiveConditionAnalyzer(VerilogControlflowAnalyzer):
|
20 |
| - def __init__(self, topmodule, terms, binddict, |
| 21 | + def __init__(self, topmodule, terms, binddict, |
21 | 22 | resolved_terms, resolved_binddict, constlist):
|
22 |
| - VerilogControlflowAnalyzer.__init__(self, topmodule, terms, binddict, |
| 23 | + VerilogControlflowAnalyzer.__init__(self, topmodule, terms, binddict, |
23 | 24 | resolved_terms, resolved_binddict, constlist)
|
24 | 25 | self.fsm_loops, self.fsms = self.getLoops()
|
25 | 26 |
|
26 |
| - ############################################################################ |
27 | 27 | def getActiveConditions(self, termname, condition=splitter.active_constant):
|
28 |
| - if not termname in self.resolved_binddict: return {} |
| 28 | + if not termname in self.resolved_binddict: |
| 29 | + return {} |
29 | 30 | tree = self.makeTree(termname)
|
30 | 31 | funcdict = splitter.split(tree)
|
31 | 32 | funcdict = splitter.filter(funcdict, termname, condition)
|
32 | 33 | funcdict = splitter.remove_reset_condition(funcdict)
|
33 | 34 |
|
34 | 35 | if len(funcdict) == 1 and len(list(funcdict.keys())[0]) == 0:
|
35 | 36 | func = funcdict.values()[0]
|
36 |
| - return {termname : ( ('any', None), )} |
| 37 | + return {termname: (('any', None), )} |
37 | 38 |
|
38 | 39 | active_conditions = {}
|
39 | 40 | active_conditions_size = 0
|
40 | 41 | for fsm_sig in self.fsms.keys():
|
41 | 42 | rslt = self.getActiveConditions_fsm(fsm_sig, funcdict)
|
42 |
| - if len(rslt) > 0: active_conditions[fsm_sig] = rslt |
| 43 | + if len(rslt) > 0: |
| 44 | + active_conditions[fsm_sig] = rslt |
43 | 45 | active_conditions_size += len(rslt)
|
44 | 46 |
|
45 | 47 | if active_conditions_size == 0:
|
46 | 48 | rslt = self.getActiveConditions_fsm(termname, funcdict)
|
47 |
| - if len(rslt) > 0: active_conditions[termname] = rslt |
| 49 | + if len(rslt) > 0: |
| 50 | + active_conditions[termname] = rslt |
48 | 51 |
|
49 | 52 | return active_conditions
|
50 | 53 |
|
51 | 54 | def getActiveConditions_fsm(self, fsm_sig, funcdict):
|
52 | 55 | # returns a list of some (state, transcond) pairs
|
53 | 56 | active_conditions = []
|
54 | 57 | fsm_sig_width = self.getWidth(fsm_sig)
|
55 |
| - for condlist, func in sorted(funcdict.items(), key=lambda x:len(x[0])): |
| 58 | + for condlist, func in sorted(funcdict.items(), key=lambda x: len(x[0])): |
56 | 59 | node = transition.walkCondlist(condlist, fsm_sig, fsm_sig_width)
|
57 | 60 | state_node_list = []
|
58 | 61 | if isinstance(node, transition.StateNodeList):
|
59 |
| - for n in node.nodelist: state_node_list.append(n) |
| 62 | + for n in node.nodelist: |
| 63 | + state_node_list.append(n) |
60 | 64 | elif node:
|
61 | 65 | state_node_list.append(node)
|
62 | 66 |
|
63 | 67 | for state_node in state_node_list:
|
64 |
| - #if state_node.isany: |
| 68 | + # if state_node.isany: |
65 | 69 | # active_conditions.append( ('any', state_node.transcond) )
|
66 | 70 | for rs, re in state_node.range_pairs:
|
67 |
| - for state in range(rs, re+1): |
| 71 | + for state in range(rs, re + 1): |
68 | 72 | transcond = self.optimizer.optimize(state_node.transcond)
|
69 |
| - if isinstance(transcond, DFEvalValue) and transcond.value == 0: continue |
70 |
| - active_conditions.append( (state, transcond) ) |
| 73 | + if isinstance(transcond, DFEvalValue) and transcond.value == 0: |
| 74 | + continue |
| 75 | + active_conditions.append((state, transcond)) |
71 | 76 | return tuple(active_conditions)
|
0 commit comments