Skip to content

Commit

Permalink
Merge pull request #144 from nicmcd/master
Browse files Browse the repository at this point in the history
Add 'directory' attribute to traceSignals.
  • Loading branch information
jandecaluwe committed Jan 26, 2016
2 parents fb70bb2 + 94bc28f commit 1f960db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
7 changes: 6 additions & 1 deletion doc/source/manual/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ Waveform tracing
This attribute is used to overwrite the default top-level instance name and the
basename of the VCD output filename.

.. attribute:: directory

This attribute is used to set the directory to which VCD files are written. By
default, the current working directory is used.

.. attribute:: timescale

This attribute is used to set the timescale corresponding to unit steps,
according to the VCD format. The assigned value should be a string.
The default timescale is "1ns".
Expand Down
27 changes: 11 additions & 16 deletions myhdl/_traceSignals.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,14 @@ class _error:
class _TraceSignalsClass(object):

__slot__ = ("name",
"directory",
"timescale",
"tracelists"
)

def __init__(self):
self.name = None
self.directory = None
self.timescale = "1ns"
self.tracelists = True

Expand All @@ -82,8 +84,14 @@ def __call__(self, dut, *args, **kwargs):
name = str(self.name)
if name is None:
raise TraceSignalsError(_error.TopLevelName)

if self.directory is None:
directory = ''
else:
directory = self.directory

h = _HierExtr(name, dut, *args, **kwargs)
vcdpath = name + ".vcd"
vcdpath = os.path.join(directory, name + ".vcd")
if path.exists(vcdpath):
backup = vcdpath + '.' + str(path.getmtime(vcdpath))
shutil.copyfile(vcdpath, backup)
Expand Down Expand Up @@ -111,7 +119,7 @@ def _genNameCode():
while 1:
yield _namecode(n)
n += 1

def _namecode(n):
q, r = divmod(n, _mod)
code = _codechars[r]
Expand Down Expand Up @@ -175,7 +183,7 @@ def _writeVcdSigs(f, hierarchy, tracelists):
else:
print("$var real 1 %s %s $end" % (s._code, n), file=f)
# Memory dump by Frederik Teichert, http://teichert-ing.de, date: 2011.03.28
# The Value Change Dump standard doesn't support multidimensional arrays so
# The Value Change Dump standard doesn't support multidimensional arrays so
# all memories are flattened and renamed.
if tracelists:
for n in memdict.keys():
Expand Down Expand Up @@ -207,16 +215,3 @@ def _writeVcdSigs(f, hierarchy, tracelists):
for s in siglist:
s._printVcd() # initial value
print("$end", file=f)













13 changes: 13 additions & 0 deletions myhdl/test/core/test_traceSignals.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,16 @@ def testBackupOutputFile(self, vcd_dir):
assert path.exists(pbak)
assert path.getsize(pbak) == size
assert path.getsize(p) < size

def testSetDirectory(self, vcd_dir):
traceSignals.directory = 'some_vcd_dir'
os.mkdir(path.join(str(vcd_dir), traceSignals.directory))
pdut = "%s.vcd" % top.__name__
psub = "%s.vcd" % fun.__name__
pdutd = path.join(traceSignals.directory, "%s.vcd" % top.__name__)
psubd = path.join(traceSignals.directory, "%s.vcd" % fun.__name__)
dut = traceSignals(top)
assert not path.exists(pdut)
assert not path.exists(psub)
assert path.exists(pdutd)
assert not path.exists(psubd)

0 comments on commit 1f960db

Please sign in to comment.