Merge branch 'master' of git.libre-soc.org:soc
[soc.git] / src / soc / experiment / alu_fsm.py
index f3973682b915555528eb823e46d14a52748dcf94..596fc3d49764081c40bf075e8098919a6f5e1979 100644 (file)
@@ -251,14 +251,18 @@ def write_gtkw_v1(base_name, top_dut_name, loc):
             gtkw.trace(dut + "n_ready_i", color=style_input)
 
 
-def write_gtkw(gtkw_name, vcd_name, gtkw_style, gtkw_dom,
-               loc=None, zoom=-22.9, marker=-1):
+def write_gtkw(gtkw_name, vcd_name, gtkw_dom, gtkw_style=None,
+               module=None, loc=None, color=None, base=None,
+               zoom=-22.9, marker=-1):
     """ Write a GTKWave document according to the supplied style and DOM.
 
     :param gtkw_name: name of the generated GTKWave document
     :param vcd_name: name of the waveform file
-    :param gtkw_style: style for signals, classes and groups
     :param gtkw_dom: DOM style description for the trace pane
+    :param gtkw_style: style for signals, classes and groups
+    :param module: default module
+    :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 marker: initial location of a marker
@@ -315,10 +319,23 @@ def write_gtkw(gtkw_name, vcd_name, gtkw_style, gtkw_dom,
         # also, move the marker to an interesting place
         gtkw.zoom_markers(zoom, marker)
 
-        if '' in gtkw_style:
-            root_style = gtkw_style['']
-        else:
-            root_style = dict()
+        # create an empty style, if needed
+        if gtkw_style is None:
+            gtkw_style = dict()
+
+        # create an empty root selector, if needed
+        root_style = gtkw_style.get('', dict())
+
+        # apply styles to the root selector, if provided
+        if module is not None:
+            root_style['module'] = module
+        if color is not None:
+            root_style['color'] = color
+        if base is not None:
+            root_style['base'] = base
+        # base cannot be None, use 'hex' by default
+        if root_style.get('base') is None:
+            root_style['base'] = 'hex'
 
         # recursively walk the DOM
         def walk(dom, style):
@@ -351,6 +368,10 @@ def write_gtkw(gtkw_name, vcd_name, gtkw_style, gtkw_dom,
                     # node is a group if it has a child list
                     if isinstance(node[-1], list):
                         children = node[-1]
+                # comment
+                elif isinstance(node, dict):
+                    if 'comment' in node:
+                        gtkw.blank(node['comment'])
                 # emit the group delimiters and walk over the child list
                 if children is not None:
                     gtkw.begin_group(node_name)
@@ -362,12 +383,14 @@ def write_gtkw(gtkw_name, vcd_name, gtkw_style, gtkw_dom,
                     signal_name = node_name
                     # prepend module name to signal
                     if 'module' in node_style:
-                        signal_name = node_style['module'] + '.' + signal_name
-                    color = colors.get(node_style.get('color'))
-                    base = node_style.get('base')
+                        node_module = node_style['module']
+                        if node_module is not None:
+                            signal_name = node_module + '.' + signal_name
+                    node_color = colors.get(node_style.get('color'))
+                    node_base = node_style.get('base')
                     display = node_style.get('display')
-                    gtkw.trace(signal_name, color=color, datafmt=base,
-                               alias=display)
+                    gtkw.trace(signal_name, color=node_color,
+                               datafmt=node_base, alias=display)
 
         walk(gtkw_dom, root_style)
 
@@ -392,7 +415,7 @@ def test_shifter():
     # Style for signals, classes and groups
     gtkwave_style = {
         # Root selector. Gives default attributes for every signal.
-        '': {'module': 'top.shf', 'base': 'dec'},
+        '': {'base': 'dec'},
         # color the traces, according to class
         # class names are not hardcoded, they are just strings
         'in': {'color': 'orange'},
@@ -442,8 +465,8 @@ def test_shifter():
     ]
 
     write_gtkw("test_shifter_v2.gtkw", "test_shifter.vcd",
-               gtkwave_style, gtkwave_desc,
-               loc=__file__, marker=10500000)
+               gtkwave_desc,  gtkwave_style,
+               module="top.shf", loc=__file__, marker=10500000)
 
     sim = Simulator(m)
     sim.add_clock(1e-6)