+"""
+ This work is funded through NLnet under Grant 2019-02-012
+
+ License: LGPLv3+
+
+
+"""
from vcd.gtkw import GTKWSave, GTKWColor
from math import log2
def write_gtkw(gtkw_name, vcd_name, gtkw_dom, gtkw_style=None,
module=None, loc=None, color=None, base=None,
- zoom=None, marker=-1, clk_period=1e-6):
+ zoom=None, marker=-1, clk_period=1e-6,
+ time_resolution_unit="ps"):
""" Write a GTKWave document according to the supplied style and DOM.
:param gtkw_name: name of the generated GTKWave document
:param color: default trace color
:param base: default numerical base
:param loc: source code location to include as a comment
- :param zoom: initial zoom level, in GTKWave format
+ :param zoom: initial zoom level, in GTKWave format. Can also be "formal"
+ when the file comes from a formal engine
:param marker: initial location of a marker
:param clk_period: clock period in seconds, helping
- to set a reasonable initial zoom level
+ to set a reasonable initial zoom level.
+ Use together with ``time_resolution_unit``.
+ :param time_resolution_unit: use "ps" or "ns". Derived from the units of
+ the "timescale" on the VCD file. Used with
+ "clk_period" to set a default zoom level
**gtkw_style format**
Attribute choices:
- * module: instance path, for prepending to the signal name
+ * module: absolute path of the current module
+ * submodule: same as above, but relative
* color: trace color
* base: numerical base for value display
* display: alternate text to display in the signal pane
* comment: comment to display in the signal pane
* bit: select a bit from a wide signal. MSB is zero, unfortunately
+ * closed (for groups): this group starts closed
**gtkw_dom format**
In place of a class name, an inline class description can be used.
``(signal, {attribute: value, ...}, ...)``
+
+ An anonymous group can be used to apply a style to a group of signals.
+ ``({attribute: value}, [signal, signal, ...])``
"""
colors = {
'blue': GTKWColor.blue,
gtkw.dumpfile(vcd_name)
# set a reasonable zoom level
# also, move the marker to an interesting place
+ if zoom == "formal":
+ # output from formal engines looks good at this zoom level
+ zoom = -6.3
if zoom is None:
zoom = -42.8 - log2(clk_period)
+ # base zoom level is affected by time resolution units
+ if time_resolution_unit == "ns":
+ zoom = zoom + log2(1e3)
gtkw.zoom_markers(zoom, marker)
# create an empty style, if needed
elif isinstance(node, dict):
if 'comment' in node:
gtkw.blank(node['comment'])
+ # merge the submodule into the module path
+ if 'submodule' in node_style:
+ node_module = node_style['submodule']
+ if 'module' in node_style:
+ node_top_module = node_style['module']
+ node_module = node_top_module + '.' + node_module
+ # update the module path
+ node_style['module'] = node_module
+ # don't propagate this attribute to children
+ del node_style['submodule']
# emit the group delimiters and walk over the child list
if children is not None:
- gtkw.begin_group(node_name)
+ # see whether this group starts closed
+ closed = False
+ if 'closed' in node_style:
+ closed = node_style['closed']
+ del node_style['closed'] # do not inherit
+ # only emit a group if it has a name
+ if isinstance(node_name, str):
+ gtkw.begin_group(node_name, closed)
# pass on the group style to its children
walk(children, node_style)
- gtkw.end_group(node_name)
+ if isinstance(node_name, str):
+ gtkw.end_group(node_name)
# emit a trace, if the node is a signal
elif node_name is not None:
signal_name = node_name
node_color = colors.get(node_style.get('color'))
node_base = node_style.get('base')
display = node_style.get('display')
- if 'bit' not in node_style:
- gtkw.trace(signal_name, color=node_color,
- datafmt=node_base, alias=display)
- else:
+ if 'bit' in node_style:
bit = node_style['bit']
- gtkw.trace_bit(bit, signal_name, color=node_color,
- alias=display)
+ signal_name = f'({bit}){signal_name}'
+ gtkw.trace(signal_name, color=node_color,
+ datafmt=node_base, alias=display)
walk(gtkw_dom, root_style)