@@ -27,10 +27,10 @@ def make_scope_dict(terms):
27
27
""" [FUNCTIONS] for getScopeChaindict
28
28
make {string: ScopeChain, ...} from binddict
29
29
"""
30
- return_dict = {}
30
+ scope_dict = {}
31
31
for scope in terms .keys ():
32
- return_dict [str (scope )] = scope
33
- return return_dict
32
+ scope_dict [str (scope )] = scope
33
+ return scope_dict
34
34
35
35
self ._binddict = binddict
36
36
self ._terms = terms
@@ -44,12 +44,12 @@ def dfx_memoize(f):
44
44
Using self.cache.
45
45
"""
46
46
def helper (self , target_tree , tree_list , bit , dftype ):
47
- if dftype == pyverilog . dataflow . dataflow . DFTerminal :
47
+ if dftype == DFTerminal :
48
48
if (target_tree ,bit ) not in self .cache :
49
49
self .cache [(target_tree ,bit )] = f (self , target_tree , set ([]), bit , dftype )
50
- return tree_list .union (self .cache [(target_tree ,bit )])
50
+ return tree_list .union (self .cache [(target_tree , bit )])
51
51
else :
52
- return f (self , target_tree , tree_list ,bit ,dftype )
52
+ return f (self , target_tree , tree_list , bit , dftype )
53
53
return helper
54
54
55
55
@dfx_memoize
@@ -61,7 +61,7 @@ def extract_all_dfxxx(self, target_tree, tree_list, bit, dftype):
61
61
bit: signal bit pointer
62
62
dftype: DFOperator or DFIntConst or ,...
63
63
"""
64
- if dftype == pyverilog . dataflow . dataflow . DFTerminal and isinstance (target_tree , pyverilog . dataflow . dataflow . DFTerminal ):
64
+ if dftype == DFTerminal and isinstance (target_tree , DFTerminal ):
65
65
target_scope = self .get_scope (target_tree )
66
66
if target_scope in self ._binddict .keys ():
67
67
target_bind , target_term_lsb = self .get_next_bind (target_scope , bit )
@@ -74,7 +74,7 @@ def extract_all_dfxxx(self, target_tree, tree_list, bit, dftype):
74
74
tree_list .add ((target_tree , bit ))
75
75
76
76
if hasattr (target_tree , "nextnodes" ):
77
- if isinstance (target_tree , pyverilog . dataflow . dataflow . DFConcat ):
77
+ if isinstance (target_tree , DFConcat ):
78
78
now_max_bit = 0
79
79
now_min_bit = 0
80
80
for nextnode in reversed (target_tree .nextnodes ):
@@ -85,22 +85,21 @@ def extract_all_dfxxx(self, target_tree, tree_list, bit, dftype):
85
85
now_min_bit = now_max_bit + 1
86
86
else :
87
87
for nextnode in target_tree .nextnodes :
88
- if isinstance (target_tree , pyverilog . dataflow . dataflow . DFBranch ) and nextnode == target_tree .condnode :
88
+ if isinstance (target_tree , DFBranch ) and nextnode == target_tree .condnode :
89
89
tree_list = self .extract_all_dfxxx (nextnode ,tree_list , 0 , dftype )
90
90
else :
91
91
tree_list = self .extract_all_dfxxx (nextnode ,tree_list , bit , dftype )
92
- elif isinstance (target_tree , pyverilog . dataflow . dataflow . DFBranch ):
92
+ elif isinstance (target_tree , DFBranch ):
93
93
tree_list = self .extract_all_dfxxx (target_tree .condnode , tree_list , 0 , dftype )
94
94
tree_list = self .extract_all_dfxxx (target_tree .truenode , tree_list , bit , dftype )
95
95
tree_list = self .extract_all_dfxxx (target_tree .falsenode , tree_list , bit , dftype )
96
- elif isinstance (target_tree , pyverilog . dataflow . dataflow . DFTerminal ):
96
+ elif isinstance (target_tree , DFTerminal ):
97
97
target_scope = self .get_scope (target_tree )
98
98
if target_scope in self ._binddict .keys ():
99
99
target_bind , target_term_lsb = self .get_next_bind (target_scope , bit )
100
100
if target_bind .isCombination ():
101
101
tree_list = self .extract_all_dfxxx (target_bind .tree , tree_list , bit , dftype )
102
- elif isinstance (target_tree , pyverilog .dataflow .dataflow .DFPartselect ):
103
- #ref_bit = eval_value(target_tree.lsb) + bit
102
+ elif isinstance (target_tree , DFPartselect ):
104
103
ref_bit = eval_value (target_tree .lsb ) + bit - eval_value (self ._terms [self .scope_dict [str (target_tree .var )]].lsb )
105
104
tree_list = self .extract_all_dfxxx (target_tree .var , tree_list , ref_bit , dftype )
106
105
return tree_list
@@ -122,7 +121,7 @@ def search_combloop(self, target_tree, bit, start_tree, start_bit, find_cnt=0, r
122
121
raise CombLoopException (str (start_tree ) + ' may be combinational loop, or too complex logic (concern over 1000 variable).' )
123
122
124
123
if hasattr (target_tree , "nextnodes" ):
125
- if isinstance (target_tree , pyverilog . dataflow . dataflow . DFConcat ):
124
+ if isinstance (target_tree , DFConcat ):
126
125
now_max_bit = 0
127
126
now_min_bit = 0
128
127
for nextnode in reversed (target_tree .nextnodes ):
@@ -133,21 +132,21 @@ def search_combloop(self, target_tree, bit, start_tree, start_bit, find_cnt=0, r
133
132
now_min_bit = now_max_bit + 1
134
133
else :
135
134
for nextnode in target_tree .nextnodes :
136
- if isinstance (target_tree , pyverilog . dataflow . dataflow . DFBranch ) and nextnode == target_tree .condnode :
135
+ if isinstance (target_tree , DFBranch ) and nextnode == target_tree .condnode :
137
136
self .search_combloop (nextnode , 0 , start_tree , start_bit , find_cnt , rec_call_cnt )
138
137
else :
139
138
self .search_combloop (nextnode , bit , start_tree , start_bit , find_cnt , rec_call_cnt )
140
- elif isinstance (target_tree , pyverilog . dataflow . dataflow . DFBranch ):
139
+ elif isinstance (target_tree , DFBranch ):
141
140
self .search_combloop (target_tree .condnode , 0 , start_tree , start_bit , find_cnt , rec_call_cnt )
142
141
self .search_combloop (target_tree .truenode , bit , start_tree , start_bit , find_cnt , rec_call_cnt )
143
142
self .search_combloop (target_tree .falsenode , bit , start_tree , start_bit , find_cnt , rec_call_cnt )
144
- elif isinstance (target_tree , pyverilog . dataflow . dataflow . DFTerminal ):
143
+ elif isinstance (target_tree , DFTerminal ):
145
144
target_scope = self .get_scope (target_tree )
146
145
if target_scope in self ._binddict .keys ():
147
146
target_bind , target_term_lsb = self .get_next_bind (target_scope , bit )
148
147
if target_bind .isCombination ():
149
148
self .search_combloop (target_bind .tree , bit , start_tree , start_bit , find_cnt , rec_call_cnt )
150
- elif isinstance (target_tree , pyverilog . dataflow . dataflow . DFPartselect ):
149
+ elif isinstance (target_tree , DFPartselect ):
151
150
ref_bit = eval_value (target_tree .lsb ) + bit - eval_value (self ._terms [self .scope_dict [str (target_tree .var )]].lsb )
152
151
self .search_combloop (target_tree .var , ref_bit , start_tree , start_bit , find_cnt , rec_call_cnt )
153
152
return
@@ -171,7 +170,6 @@ def get_next_bind(self, scope, bit):
171
170
if scope in self ._binddict .keys ():
172
171
target_binds = self ._binddict [scope ]
173
172
target_bind_index = self .get_bind_index (target_binds , bit + eval_value (self ._terms [scope ].lsb ), self ._terms [scope ])
174
- #target_bind_index = self.get_bind_index(target_binds, bit, self._terms[scope])
175
173
target_bind = target_binds [target_bind_index ]
176
174
return target_bind , eval_value (self ._terms [scope ].lsb )
177
175
else :
@@ -197,30 +195,30 @@ def get_bind_index(self, binds=None, bit=None, term=None, scope=None):
197
195
198
196
def get_bit_width_from_tree (self , tree ):
199
197
onebit_comb = ('Ulnot' ,'Unot' ,'Eq' , 'Ne' ,'Lor' ,'Land' ,'Unand' ,'Uor' ,'Unor' ,'Uxor' ,'Uxnor' )
200
- if isinstance (tree , pyverilog . dataflow . dataflow . DFTerminal ):
198
+ if isinstance (tree , DFTerminal ):
201
199
term = self ._terms [self .get_scope (tree )]
202
200
return eval_value (term .msb ) + 1
203
- elif isinstance (tree , pyverilog . dataflow . dataflow . DFPartselect ):
201
+ elif isinstance (tree , DFPartselect ):
204
202
return eval_value (tree .msb ) - eval_value (tree .lsb ) + 1
205
- elif isinstance (tree , pyverilog . dataflow . dataflow . DFOperator ):
203
+ elif isinstance (tree , DFOperator ):
206
204
if tree .operator in onebit_comb :
207
205
return 1
208
206
else :
209
207
each_sizes = (self .get_bit_width_from_tree (nextnode ) for nextnode in tree .nextnodes )
210
208
return min (each_sizes )
211
- elif isinstance (tree , pyverilog . dataflow . dataflow . DFIntConst ):
209
+ elif isinstance (tree , DFIntConst ):
212
210
return tree .width ()
213
- elif isinstance (tree , pyverilog . dataflow . dataflow . DFConcat ):
211
+ elif isinstance (tree , DFConcat ):
214
212
return sum ([self .get_bit_width_from_tree (nextnode ) for nextnode in tree .nextnodes ])
215
- elif isinstance (tree , pyverilog . dataflow . dataflow . DFEvalValue ):
213
+ elif isinstance (tree , DFEvalValue ):
216
214
return tree .width
217
215
else :
218
216
raise IRREGAL_CODE_FORM ("unexpected concat node" )
219
217
220
218
def walk_reg_each_bit (self ):
221
219
for tk , tv in sorted (self ._terms .items (), key = lambda x :len (x [0 ])):
222
220
if tk in self ._binddict .keys ():
223
- for bvi in self ._binddict [tk ]:#process for each always block
221
+ for bvi in self ._binddict [tk ]: #process for each always block
224
222
bind_lsb = self .get_bind_lsb (bvi )
225
223
bind_msb = self .get_bind_msb (bvi )
226
224
for bit in range (bind_lsb , bind_msb + 1 ):
@@ -330,7 +328,8 @@ def DFConstant_eq_org(self, other):
330
328
331
329
def DFEvalValue_eq_org (self , other ):
332
330
if type (self ) != type (other ): return False
333
- return self .value == other .value and self .width == other .width and self .isfloat == other .isfloat and self .isstring == other .isstring
331
+ return (self .value == other .value and self .width == other .width and
332
+ self .isfloat == other .isfloat and self .isstring == other .isstring )
334
333
335
334
def DFUndefined_eq_org (self , other ):
336
335
if type (self ) != type (other ): return False
@@ -346,7 +345,8 @@ def DFTerminal_eq_org(self, other):
346
345
347
346
def DFBranch_eq_org (self , other ):
348
347
if type (self ) != type (other ): return False
349
- return self .condnode == other .condnode and self .truenode == other .truenode and self .falsenode == other .falsenode
348
+ return (self .condnode == other .condnode and self .truenode == other .truenode and
349
+ self .falsenode == other .falsenode )
350
350
351
351
def DFOperator_eq_org (self , other ):
352
352
if type (self ) != type (other ): return False
@@ -365,32 +365,30 @@ def DFConcat_eq_org(self, other):
365
365
return self .nextnodes == other .nextnodes
366
366
367
367
def eval_value (tree ):
368
- if isinstance (tree , pyverilog . dataflow . dataflow . DFOperator ):
368
+ if isinstance (tree , DFOperator ):
369
369
for nextnode in self .nextnodes :
370
- assert (isinstance (nextnode , pyverilog . dataflow . dataflow . DFEvalValue )
371
- or isinstance (nextnode , pyverilog . dataflow . dataflow . DFIntConst )
372
- or isinstance (nextnode , pyverilog . dataflow . dataflow . DFOperator )
373
- or isinstance (nextnode , pyverilog . dataflow . dataflow . DFTerminal ))
370
+ assert (isinstance (nextnode , DFEvalValue )
371
+ or isinstance (nextnode , DFIntConst )
372
+ or isinstance (nextnode , DFOperator )
373
+ or isinstance (nextnode , DFTerminal ))
374
374
if self .operator == 'Plus' :
375
375
return eval_value (nextnodes [0 ]) + eval_value (nextnodes [1 ])
376
376
elif self .operator == 'Minus' :
377
377
return eval_value (nextnodes [0 ]) - eval_value (nextnodes [1 ])
378
378
elif self .operator == 'Times' :
379
379
return eval_value (nextnodes [0 ]) * eval_value (nextnodes [1 ])
380
- else :#unimplemented
381
- raise Exception
382
- elif isinstance (tree , pyverilog . dataflow . dataflow . DFTerminal ):
380
+ else :
381
+ raise Exception ( 'unimplemented for this type tree' + str ( type ( tree )))
382
+ elif isinstance (tree , DFTerminal ):
383
383
if self .get_scope (scopedict ) in binddict .keys ():
384
384
return binddict [self .get_scope (scopedict )][0 ].tree .eval ()
385
385
else :
386
386
raise verror .ImplementationError ()
387
- elif isinstance (tree , pyverilog . dataflow . dataflow . DFIntConst ):
387
+ elif isinstance (tree , DFIntConst ):
388
388
return tree .eval ()
389
- elif isinstance (tree , pyverilog . dataflow . dataflow . DFEvalValue ):
389
+ elif isinstance (tree , DFEvalValue ):
390
390
return tree .value
391
391
elif tree is None :
392
392
return 0
393
393
else :
394
394
raise Exception ('Unexpected error@bindlibrary' )
395
-
396
-
0 commit comments