36
36
from ._resolverefs import _resolveRefs
37
37
from ._util import _flatten , _genfunc , _isTupleOfInts , _isTupleOfFloats
38
38
39
-
40
39
_profileFunc = None
41
40
42
41
43
42
class _error :
44
43
pass
45
44
45
+
46
46
_error .NoInstances = "No instances found"
47
47
_error .InconsistentHierarchy = "Inconsistent hierarchy - are all" \
48
- " instances returned ?"
48
+ " instances returned ?"
49
49
_error .InconsistentToplevel = "Inconsistent top level %s for %s - should be 1"
50
50
51
51
@@ -77,6 +77,7 @@ def __init__(self, level, obj, subs, constdict, sigdict, memdict,
77
77
78
78
self .name = None
79
79
80
+
80
81
_memInfoMap = {}
81
82
82
83
@@ -174,11 +175,6 @@ def _isRom(mem):
174
175
return id (mem ) in _romInfoMap
175
176
176
177
177
- _userCodeMap = {'verilog' : {},
178
- 'vhdl' : {}
179
- }
180
-
181
-
182
178
class _UserCode (object ):
183
179
__slots__ = ['code' , 'namespace' , 'funcname' , 'func' , 'sourcefile' ,
184
180
'sourceline' ]
@@ -204,7 +200,14 @@ def __str__(self):
204
200
code = "\n %s\n " % code
205
201
return code
206
202
203
+ def _scrub_namespace (self ):
204
+ for nm , obj in self .namespace .items ():
205
+ if _isMem (obj ):
206
+ memi = _getMemInfo (obj )
207
+ self .namespace [nm ] = memi .name
208
+
207
209
def _interpolate (self ):
210
+ self ._scrub_namespace ()
208
211
return string .Template (self .code ).substitute (self .namespace )
209
212
210
213
@@ -264,40 +267,6 @@ def __str__(self):
264
267
return s
265
268
266
269
267
- def _addUserCode (specs , arg , funcname , func , frame ):
268
- classMap = {
269
- '__verilog__' : _UserVerilogCodeDepr ,
270
- '__vhdl__' : _UserVhdlCodeDepr ,
271
- 'verilog_code' : _UserVerilogCode ,
272
- 'vhdl_code' : _UserVhdlCode ,
273
- 'verilog_instance' : _UserVerilogInstance ,
274
- 'vhdl_instance' : _UserVhdlInstance ,
275
-
276
- }
277
- namespace = frame .f_globals .copy ()
278
- namespace .update (frame .f_locals )
279
- sourcefile = inspect .getsourcefile (frame )
280
- sourceline = inspect .getsourcelines (frame )[1 ]
281
- for hdl in _userCodeMap :
282
- oldspec = "__%s__" % hdl
283
- codespec = "%s_code" % hdl
284
- instancespec = "%s_instance" % hdl
285
- spec = None
286
- # XXX add warning logic
287
- if instancespec in specs :
288
- spec = instancespec
289
- elif codespec in specs :
290
- spec = codespec
291
- elif oldspec in specs :
292
- spec = oldspec
293
- if spec :
294
- assert id (arg ) not in _userCodeMap [hdl ]
295
- code = specs [spec ]
296
- _userCodeMap [hdl ][id (arg )] = classMap [spec ](code , namespace ,
297
- funcname , func ,
298
- sourcefile , sourceline )
299
-
300
-
301
270
class _CallFuncVisitor (object ):
302
271
303
272
def __init__ (self ):
@@ -319,8 +288,10 @@ def __init__(self, name, dut, *args, **kwargs):
319
288
320
289
global _profileFunc
321
290
_memInfoMap .clear ()
322
- for hdl in _userCodeMap :
323
- _userCodeMap [hdl ].clear ()
291
+ self .userCodeMap = {'verilog' : {},
292
+ 'vhdl' : {}
293
+ }
294
+
324
295
self .skipNames = ('always_comb' , 'instance' ,
325
296
'always_seq' , '_always_seq_decorator' ,
326
297
'always' , '_always_decorator' ,
@@ -395,7 +366,7 @@ def extractor(self, frame, event, arg):
395
366
isGenSeq = _isGenSeq (arg )
396
367
if isGenSeq :
397
368
specs = {}
398
- for hdl in _userCodeMap :
369
+ for hdl in self . userCodeMap :
399
370
spec = "__%s__" % hdl
400
371
if spec in frame .f_locals and frame .f_locals [spec ]:
401
372
specs [spec ] = frame .f_locals [spec ]
@@ -408,7 +379,7 @@ def extractor(self, frame, event, arg):
408
379
getattr (func , spec ):
409
380
specs [spec ] = getattr (func , spec )
410
381
if specs :
411
- _addUserCode (specs , arg , funcname , func , frame )
382
+ self . _add_user_code (specs , arg , funcname , func , frame )
412
383
# building hierarchy only makes sense if there are generators
413
384
if isGenSeq and arg :
414
385
constdict = {}
@@ -462,7 +433,7 @@ def extractor(self, frame, event, arg):
462
433
463
434
subs = []
464
435
for n , sub in frame .f_locals .items ():
465
- for elt in _inferArgs (arg ):
436
+ for elt in _infer_args (arg ):
466
437
if elt is sub :
467
438
subs .append ((n , sub ))
468
439
inst = _Instance (self .level , arg , subs , constdict ,
@@ -474,8 +445,40 @@ def extractor(self, frame, event, arg):
474
445
if funcname in self .skipNames :
475
446
self .skip -= 1
476
447
477
-
478
- def _inferArgs (arg ):
448
+ def _add_user_code (self , specs , arg , funcname , func , frame ):
449
+ classMap = {
450
+ '__verilog__' : _UserVerilogCodeDepr ,
451
+ '__vhdl__' : _UserVhdlCodeDepr ,
452
+ 'verilog_code' : _UserVerilogCode ,
453
+ 'vhdl_code' : _UserVhdlCode ,
454
+ 'verilog_instance' : _UserVerilogInstance ,
455
+ 'vhdl_instance' : _UserVhdlInstance ,
456
+ }
457
+ namespace = frame .f_globals .copy ()
458
+ namespace .update (frame .f_locals )
459
+ sourcefile = inspect .getsourcefile (frame )
460
+ sourceline = inspect .getsourcelines (frame )[1 ]
461
+ for hdl in self .userCodeMap :
462
+ oldspec = "__%s__" % hdl
463
+ codespec = "%s_code" % hdl
464
+ instancespec = "%s_instance" % hdl
465
+ spec = None
466
+ # XXX add warning logic
467
+ if instancespec in specs :
468
+ spec = instancespec
469
+ elif codespec in specs :
470
+ spec = codespec
471
+ elif oldspec in specs :
472
+ spec = oldspec
473
+ if spec :
474
+ assert id (arg ) not in self .userCodeMap [hdl ]
475
+ code = specs [spec ]
476
+ self .userCodeMap [hdl ][id (arg )] = classMap [spec ](code , namespace ,
477
+ funcname , func ,
478
+ sourcefile , sourceline )
479
+
480
+
481
+ def _infer_args (arg ):
479
482
c = [arg ]
480
483
if isinstance (arg , (tuple , list )):
481
484
c += list (arg )
0 commit comments