def __init__(self, name, dut, *args, **kwargs): global _profileFunc _memInfoMap.clear() for hdl in _userCodeMap: _userCodeMap[hdl].clear() self.skipNames = ('always_comb', 'instance', \ 'always_seq', '_always_seq_decorator', \ 'always', '_always_decorator', \ 'instances', \ 'processes', 'posedge', 'negedge') self.skip = 0 self.hierarchy = hierarchy = [] self.absnames = absnames = {} self.level = 0 _profileFunc = self.extractor sys.setprofile(_profileFunc) _top = dut(*args, **kwargs) sys.setprofile(None) if not hierarchy: raise ExtractHierarchyError(_error.NoInstances) self.top = _top # streamline hierarchy hierarchy.reverse() # walk the hierarchy to define relative and absolute names names = {} top_inst = hierarchy[0] obj, subs = top_inst.obj, top_inst.subs names[id(obj)] = name absnames[id(obj)] = name if not top_inst.level == 1: raise ExtractHierarchyError(_error.InconsistentToplevel % (top_inst.level, name)) for inst in hierarchy: obj, subs = inst.obj, inst.subs if id(obj) not in names: raise ExtractHierarchyError(_error.InconsistentHierarchy) inst.name = names[id(obj)] tn = absnames[id(obj)] for sn, so in subs: names[id(so)] = sn absnames[id(so)] = "%s_%s" % (tn, sn) if isinstance(so, (tuple, list)): for i, soi in enumerate(so): sni = "%s_%s" % (sn, i) names[id(soi)] = sni absnames[id(soi)] = "%s_%s_%s" % (tn, sn, i)
def __init__(self, name, dut, *args, **kwargs): def _nDname(top, name, obj): ''' a local (recursive) subroutine ''' names[id(obj)] = name absnames[id(obj)] = '{}_{}'.format(top, name) # trace.print('{}_{}'.format(top, name)) if isinstance(obj, (tuple, list)): for i, item in enumerate(obj): _nDname(top, '{}{}'.format(name, i), item) global _profileFunc _memInfoMap.clear() for hdl in _userCodeMap: _userCodeMap[hdl].clear() self.skipNames = ('always_comb', 'instance', 'always_seq', '_always_seq_decorator', 'always', '_always_decorator', 'instances', 'processes', 'posedge', 'negedge') self.skip = 0 self.hierarchy = hierarchy = [] self.absnames = absnames = collections.OrderedDict() # {} self.level = 0 _profileFunc = self.extractor sys.setprofile(_profileFunc) if hasattr(dut, 'rtl'): _top = dut(*args, **kwargs).rtl() else: _top = dut(*args, **kwargs) trace.push(message='_HierExtr') # for tt in _top: # trace.print(tt) sys.setprofile(None) if not hierarchy: raise ExtractHierarchyError(_error.NoInstances) self.top = _top # streamline hierarchy hierarchy.reverse() # walk the hierarchy to define relative and absolute names names = {} # collections.OrderedDict() #{} top_inst = hierarchy[0] obj, subs = top_inst.obj, top_inst.subs names[id(obj)] = name absnames[id(obj)] = name if not top_inst.level == 1: raise ExtractHierarchyError(_error.InconsistentToplevel % (top_inst.level, name)) for inst in hierarchy: # print(repr(inst)) obj, subs = inst.obj, inst.subs if id(obj) not in names: raise ExtractHierarchyError(_error.InconsistentHierarchy, '{}'.format(repr(obj))) inst.name = names[id(obj)] tn = absnames[id(obj)] for sn, so in subs: sns = sn[:-3] if sn[-3:] == 'rtl' else sn _nDname(tn, sns, so)
def visit_Attribute(self, node): self.generic_visit(node) reserved = ('next', 'posedge', 'negedge', 'max', 'min', 'val', 'signed') if node.attr in reserved: return node # Don't handle subscripts for now. if not isinstance(node.value, ast.Name): return node # Don't handle locals if node.value.id not in self.data.symdict: return node obj = self.data.symdict[node.value.id] # Don't handle enums and functions, handle signals as long as it is a new attribute if isinstance(obj, (EnumType, FunctionType)): return node elif isinstance(obj, SignalType): if hasattr(SignalType, node.attr): return node attrobj = getattr(obj, node.attr) orig_name = node.value.id + '.' + node.attr # TODO: may have to resolve down ... elif isinstance(obj, Array): # print(obj, node.attr) return node # TODO: must resolve down elif isinstance(obj, StructType): # print(obj, node.attr) attrobj = getattr(obj, node.attr) orig_name = node.value.id + '.' + node.attr if orig_name not in self.name_map: # print('resolverefs {}'.format(orig_name), end=' ') # print('not in self.name_map') if self.data.symdict.has_key(orig_name): raise ValueError('self.data.symdict.haskey(orig_name)') self.name_map[orig_name] = orig_name else: # return node # print('_AttrRefTransformer:', obj, node.attr) attrobj = getattr(obj, node.attr) orig_name = node.value.id + '.' + node.attr if orig_name not in self.name_map: if node.value.id != 'self': if node.attr[0] != '_': base_name = node.value.id + '_' + node.attr else: base_name = node.value.id + node.attr else: base_name = node.attr if self.data.symdict.has_key(base_name): raise ExtractHierarchyError( _error.NameCollision.format(base_name, orig_name)) result = _suffixer(base_name, self.data.symdict) self.name_map[orig_name] = result new_name = self.name_map[orig_name] self.data.symdict[new_name] = attrobj self.data.objlist.append(new_name) # print( orig_name, new_name, attrobj ) new_node = ast.Name(id=new_name, ctx=node.value.ctx) return ast.copy_location(new_node, node)