3636from ._resolverefs import _resolveRefs
3737from ._util import _flatten , _genfunc , _isTupleOfInts , _isTupleOfFloats
3838
39-
4039_profileFunc = None
4140
4241
4342class _error :
4443 pass
4544
45+
4646_error .NoInstances = "No instances found"
4747_error .InconsistentHierarchy = "Inconsistent hierarchy - are all" \
48- " instances returned ?"
48+ " instances returned ?"
4949_error .InconsistentToplevel = "Inconsistent top level %s for %s - should be 1"
5050
5151
@@ -77,6 +77,7 @@ def __init__(self, level, obj, subs, constdict, sigdict, memdict,
7777
7878 self .name = None
7979
80+
8081_memInfoMap = {}
8182
8283
@@ -174,11 +175,6 @@ def _isRom(mem):
174175 return id (mem ) in _romInfoMap
175176
176177
177- _userCodeMap = {'verilog' : {},
178- 'vhdl' : {}
179- }
180-
181-
182178class _UserCode (object ):
183179 __slots__ = ['code' , 'namespace' , 'funcname' , 'func' , 'sourcefile' ,
184180 'sourceline' ]
@@ -204,7 +200,14 @@ def __str__(self):
204200 code = "\n %s\n " % code
205201 return code
206202
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+
207209 def _interpolate (self ):
210+ self ._scrub_namespace ()
208211 return string .Template (self .code ).substitute (self .namespace )
209212
210213
@@ -264,40 +267,6 @@ def __str__(self):
264267 return s
265268
266269
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-
301270class _CallFuncVisitor (object ):
302271
303272 def __init__ (self ):
@@ -319,8 +288,10 @@ def __init__(self, name, dut, *args, **kwargs):
319288
320289 global _profileFunc
321290 _memInfoMap .clear ()
322- for hdl in _userCodeMap :
323- _userCodeMap [hdl ].clear ()
291+ self .userCodeMap = {'verilog' : {},
292+ 'vhdl' : {}
293+ }
294+
324295 self .skipNames = ('always_comb' , 'instance' ,
325296 'always_seq' , '_always_seq_decorator' ,
326297 'always' , '_always_decorator' ,
@@ -395,7 +366,7 @@ def extractor(self, frame, event, arg):
395366 isGenSeq = _isGenSeq (arg )
396367 if isGenSeq :
397368 specs = {}
398- for hdl in _userCodeMap :
369+ for hdl in self . userCodeMap :
399370 spec = "__%s__" % hdl
400371 if spec in frame .f_locals and frame .f_locals [spec ]:
401372 specs [spec ] = frame .f_locals [spec ]
@@ -408,7 +379,7 @@ def extractor(self, frame, event, arg):
408379 getattr (func , spec ):
409380 specs [spec ] = getattr (func , spec )
410381 if specs :
411- _addUserCode (specs , arg , funcname , func , frame )
382+ self . _add_user_code (specs , arg , funcname , func , frame )
412383 # building hierarchy only makes sense if there are generators
413384 if isGenSeq and arg :
414385 constdict = {}
@@ -462,7 +433,7 @@ def extractor(self, frame, event, arg):
462433
463434 subs = []
464435 for n , sub in frame .f_locals .items ():
465- for elt in _inferArgs (arg ):
436+ for elt in _infer_args (arg ):
466437 if elt is sub :
467438 subs .append ((n , sub ))
468439 inst = _Instance (self .level , arg , subs , constdict ,
@@ -474,8 +445,40 @@ def extractor(self, frame, event, arg):
474445 if funcname in self .skipNames :
475446 self .skip -= 1
476447
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 ):
479482 c = [arg ]
480483 if isinstance (arg , (tuple , list )):
481484 c += list (arg )
0 commit comments