speed up ==, hash, <, >, <=, and >= for plain_data
[nmutil.git] / src / nmutil / gtkw.py
index d279ac8ec69624a8852ed6f9ea804ad7da57a025..f26fc00cf17b1e0be1977f1c699aff5a37eb35d7 100644 (file)
@@ -1,3 +1,10 @@
+"""
+    This work is funded through NLnet under Grant 2019-02-012
+
+    License: LGPLv3+
+
+
+"""
 from vcd.gtkw import GTKWSave, GTKWColor
 from math import log2
 
@@ -16,7 +23,8 @@ def write_gtkw(gtkw_name, vcd_name, gtkw_dom, gtkw_style=None,
     :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.
@@ -35,12 +43,14 @@ def write_gtkw(gtkw_name, vcd_name, gtkw_dom, gtkw_style=None,
 
     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**
 
@@ -56,6 +66,9 @@ def write_gtkw(gtkw_name, vcd_name, gtkw_dom, gtkw_style=None,
 
     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,
@@ -76,6 +89,9 @@ def write_gtkw(gtkw_name, vcd_name, gtkw_dom, gtkw_style=None,
         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
@@ -136,12 +152,30 @@ def write_gtkw(gtkw_name, vcd_name, gtkw_dom, gtkw_style=None,
                 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