def _updateNamespaces(self): # dicts to keep track of objects used in Instantiator objects usedsigdict = {} usedlosdict = {} for inst in self.subs: # the symdict of a block instance is defined by # the call context of its instantiations if isinstance(inst, Cosimulation): continue # ignore if self.symdict is None: self.symdict = inst.callinfo.symdict if isinstance(inst, _Instantiator): usedsigdict.update(inst.sigdict) usedlosdict.update(inst.losdict) if self.symdict is None: self.symdict = {} # Special case: due to attribute reference transformation, the # sigdict and losdict from Instantiator objects may contain new # references. Therefore, update the symdict with them. # To be revisited. self.symdict.update(usedsigdict) self.symdict.update(usedlosdict) # Infer sigdict and memdict, with compatibility patches from _extractHierarchy for n, v in self.symdict.items(): if isinstance(v, _Signal): self.sigdict[n] = v if n in usedsigdict: v._markUsed() if _isListOfSigs(v): m = _makeMemInfo(v) self.memdict[n] = m if n in usedlosdict: m._used = True
def extractor(self, frame, event, arg): if event == "call": funcname = frame.f_code.co_name # skip certain functions if funcname in self.skipNames: self.skip += 1 if not self.skip: self.level += 1 elif event == "return": funcname = frame.f_code.co_name func = frame.f_globals.get(funcname) if func is None: # Didn't find a func in the global space, try the local "self" # argument and see if it has a method called *funcname* obj = frame.f_locals.get('self') if hasattr(obj, funcname): func = getattr(obj, funcname) if not self.skip: isGenSeq = _isGenSeq(arg) if isGenSeq: specs = {} for hdl in _userCodeMap: spec = "__%s__" % hdl if spec in frame.f_locals and frame.f_locals[spec]: specs[spec] = frame.f_locals[spec] spec = "%s_code" % hdl if func and hasattr(func, spec) and getattr( func, spec): specs[spec] = getattr(func, spec) spec = "%s_instance" % hdl if func and hasattr(func, spec) and getattr( func, spec): specs[spec] = getattr(func, spec) if specs: _addUserCode(specs, arg, funcname, func, frame) # building hierarchy only makes sense if there are generators if isGenSeq and arg: sigdict = {} memdict = {} # **** KH added code argdict = {} if func: arglist = getargspec(func).args else: arglist = [] # ---- cellvars = frame.f_code.co_cellvars for dict in (frame.f_globals, frame.f_locals): for n, v in dict.items(): # extract signals and memories # also keep track of whether they are used in generators # only include objects that are used in generators ## if not n in cellvars: ## continue if isinstance(v, _Signal): sigdict[n] = v if n in cellvars: v._markUsed() if _isListOfSigs(v): m = _makeMemInfo(v) memdict[n] = m if n in cellvars: m._used = True # **** KH added code: save any other variable in argdict if (n in arglist) and (n not in sigdict) and ( n not in memdict): argdict[n] = v # ----- subs = [] for n, sub in frame.f_locals.items(): for elt in _inferArgs(arg): if elt is sub: subs.append((n, sub)) # **** KH modified code: add "func" and "argdict" inst = _Instance(self.level, arg, subs, sigdict, memdict, func, argdict) # ----- self.hierarchy.append(inst) self.level -= 1 if funcname in self.skipNames: self.skip -= 1
def extractor(self, frame, event, arg): if event == "call": funcname = frame.f_code.co_name # skip certain functions if funcname in self.skipNames: self.skip +=1 if not self.skip: self.level += 1 elif event == "return": funcname = frame.f_code.co_name func = frame.f_globals.get(funcname) if func is None: # Didn't find a func in the global space, try the local "self" # argument and see if it has a method called *funcname* obj = frame.f_locals.get('self') if hasattr(obj, funcname): func = getattr(obj, funcname) if not self.skip: isGenSeq = _isGenSeq(arg) if isGenSeq: specs = {} for hdl in _userCodeMap: spec = "__%s__" % hdl if spec in frame.f_locals and frame.f_locals[spec]: specs[spec] = frame.f_locals[spec] spec = "%s_code" % hdl if func and hasattr(func, spec) and getattr(func, spec): specs[spec] = getattr(func, spec) spec = "%s_instance" % hdl if func and hasattr(func, spec) and getattr(func, spec): specs[spec] = getattr(func, spec) if specs: _addUserCode(specs, arg, funcname, func, frame) # building hierarchy only makes sense if there are generators if isGenSeq and arg: sigdict = {} memdict = {} # **** KH added code argdict = {} if func: arglist = getargspec(func).args else: arglist = [] # ---- cellvars = frame.f_code.co_cellvars for dict in (frame.f_globals, frame.f_locals): for n, v in dict.items(): # extract signals and memories # also keep track of whether they are used in generators # only include objects that are used in generators ## if not n in cellvars: ## continue if isinstance(v, _Signal): sigdict[n] = v if n in cellvars: v._markUsed() if _isListOfSigs(v): m = _makeMemInfo(v) memdict[n] = m if n in cellvars: m._used = True # **** KH added code: save any other variable in argdict if (n in arglist) and (n not in sigdict) and (n not in memdict): argdict[n] = v # ----- subs = [] for n, sub in frame.f_locals.items(): for elt in _inferArgs(arg): if elt is sub: subs.append((n, sub)) # **** KH modified code: add "func" and "argdict" inst = _Instance(self.level, arg, subs, sigdict, memdict, func, argdict) # ----- self.hierarchy.append(inst) self.level -= 1 if funcname in self.skipNames: self.skip -= 1