mirror of
https://github.com/myhdl/myhdl.git
synced 2024-12-14 07:44:38 +08:00
indexed instances
This commit is contained in:
parent
80e9e7d7b1
commit
7715908967
@ -62,7 +62,16 @@ class ArgTypeError(Error):
|
|||||||
class NoInstancesError(Error):
|
class NoInstancesError(Error):
|
||||||
"""trace_sigs returned no instances"""
|
"""trace_sigs returned no instances"""
|
||||||
|
|
||||||
re_assname = re.compile(r"^\s*(?P<assname>\w[\w\d]*)\s*=")
|
re_assign = r"""^
|
||||||
|
\s*
|
||||||
|
(?P<name>\w[\w\d]*)
|
||||||
|
(?P<index>\[.*\])?
|
||||||
|
\s*
|
||||||
|
=
|
||||||
|
"""
|
||||||
|
|
||||||
|
rex_assign = re.compile(re_assign, re.X)
|
||||||
|
|
||||||
|
|
||||||
def trace_sigs(dut, *args, **kwargs):
|
def trace_sigs(dut, *args, **kwargs):
|
||||||
global _tracing
|
global _tracing
|
||||||
@ -74,15 +83,11 @@ def trace_sigs(dut, *args, **kwargs):
|
|||||||
raise ArgTypeError("got generator function")
|
raise ArgTypeError("got generator function")
|
||||||
_tracing = 1
|
_tracing = 1
|
||||||
try:
|
try:
|
||||||
o = getouterframes(currentframe())[1]
|
outer = getouterframes(currentframe())[1]
|
||||||
s = o[4][0]
|
name = _findInstanceName(outer)
|
||||||
m = re_assname.match(s)
|
if name is None:
|
||||||
name = None
|
|
||||||
if m:
|
|
||||||
name = m.group('assname')
|
|
||||||
else:
|
|
||||||
raise TopLevelNameError
|
raise TopLevelNameError
|
||||||
h = HierExtr(name, dut, *args, **kwargs)
|
h = _HierExtr(name, dut, *args, **kwargs)
|
||||||
vcdpath = name + ".vcd"
|
vcdpath = name + ".vcd"
|
||||||
if path.exists(vcdpath):
|
if path.exists(vcdpath):
|
||||||
backup = vcdpath + '.' + str(path.getmtime(vcdpath))
|
backup = vcdpath + '.' + str(path.getmtime(vcdpath))
|
||||||
@ -98,7 +103,29 @@ def trace_sigs(dut, *args, **kwargs):
|
|||||||
return h.m
|
return h.m
|
||||||
|
|
||||||
|
|
||||||
class HierExtr(object):
|
def _findInstanceName(framerec):
|
||||||
|
f = framerec[0]
|
||||||
|
c = framerec[4][0]
|
||||||
|
m = rex_assign.match(c)
|
||||||
|
name = None
|
||||||
|
if m:
|
||||||
|
basename, index = m.groups()
|
||||||
|
if index:
|
||||||
|
il = []
|
||||||
|
for i in index[1:-1].split("]["):
|
||||||
|
try:
|
||||||
|
s = str(eval(i, f.f_globals, f.f_locals))
|
||||||
|
except:
|
||||||
|
break
|
||||||
|
il.append(s)
|
||||||
|
else:
|
||||||
|
name = basename + '[' + "][".join(il) + ']'
|
||||||
|
else:
|
||||||
|
name = basename
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
|
class _HierExtr(object):
|
||||||
|
|
||||||
def __init__(self, name, dut, *args, **kwargs):
|
def __init__(self, name, dut, *args, **kwargs):
|
||||||
self.names = [name]
|
self.names = [name]
|
||||||
@ -113,32 +140,27 @@ class HierExtr(object):
|
|||||||
raise NoInstancesError
|
raise NoInstancesError
|
||||||
self.m = _top
|
self.m = _top
|
||||||
instances.reverse()
|
instances.reverse()
|
||||||
# print instances
|
|
||||||
instances[0][1] = name
|
instances[0][1] = name
|
||||||
|
|
||||||
def extractor(self, frame, event, arg):
|
def extractor(self, frame, event, arg):
|
||||||
if event == "call":
|
if event == "call":
|
||||||
o = getouterframes(frame)[1]
|
outer = getouterframes(frame)[1]
|
||||||
s = o[4][0]
|
name = _findInstanceName(outer)
|
||||||
m = re_assname.match(s)
|
|
||||||
name = None
|
|
||||||
if m:
|
|
||||||
name = m.group('assname')
|
|
||||||
self.names.append(name)
|
self.names.append(name)
|
||||||
if name:
|
if name:
|
||||||
self.level += 1
|
self.level += 1
|
||||||
elif event == "return":
|
elif event == "return":
|
||||||
name = self.names.pop()
|
name = self.names.pop()
|
||||||
if name:
|
if name:
|
||||||
if _isGenSeq(arg):
|
if _isGenSeq(arg):
|
||||||
sigdict = {}
|
sigdict = {}
|
||||||
for dict in (frame.f_locals, frame.f_globals):
|
for dict in (frame.f_locals, frame.f_globals):
|
||||||
for n, v in dict.items():
|
for n, v in dict.items():
|
||||||
if isinstance(v, Signal):
|
if isinstance(v, Signal):
|
||||||
sigdict[n] = v
|
sigdict[n] = v
|
||||||
i = [self.level, name, sigdict]
|
i = [self.level, name, sigdict]
|
||||||
self.instances.append(i)
|
self.instances.append(i)
|
||||||
self.level -= 1
|
self.level -= 1
|
||||||
|
|
||||||
|
|
||||||
_codechars = ""
|
_codechars = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user