1
1
"""
2
- Helper functions for reading and writing hardware files .
2
+ Helper functions for viewing the block visually .
3
3
4
- Each of the functions in inputoutput take a block and a file descriptor.
5
- The functions provided either read the file and update the Block
6
- accordingly, or write information from the Block out to the file.
4
+ Each of the functions in visualization take a block and a file descriptor.
5
+ The functions provided write the block as a given visual format to the file.
7
6
"""
8
7
9
8
from __future__ import print_function , unicode_literals
13
12
from .wire import WireVector , Input , Output , Const , Register
14
13
15
14
16
- # -----------------------------------------------------------------
17
- # __ ___
18
- # | |\ | |__) | | |
19
- # | | \| | \__/ |
20
-
21
- # ----------------------------------------------------------------
22
- # __ ___ __ ___
23
- # / \ | | | |__) | | |
24
- # \__/ \__/ | | \__/ |
25
- #
26
-
27
-
28
- def _trivialgraph_default_namer (thing , is_edge = True ):
29
- """ Returns a "good" string for thing in printed graphs. """
30
- if is_edge :
31
- if thing .name is None or thing .name .startswith ('tmp' ):
32
- return ''
33
- else :
34
- return '/' .join ([thing .name , str (len (thing ))])
35
- elif isinstance (thing , Const ):
36
- return str (thing .val )
37
- elif isinstance (thing , WireVector ):
38
- return thing .name or '??'
39
- else :
40
- try :
41
- return thing .op + str (thing .op_param or '' )
42
- except AttributeError :
43
- raise PyrtlError ('no naming rule for "%s"' % str (thing ))
44
-
45
-
46
15
def net_graph (block = None , split_state = False ):
47
16
""" Return a graph representation of the given block.
48
17
@@ -107,6 +76,29 @@ def net_graph(block=None, split_state=False):
107
76
return graph
108
77
109
78
79
+ # -----------------------------------------------------------------
80
+ # ___ __ ___
81
+ # | / _` |___
82
+ # | \__> |
83
+
84
+ def _trivialgraph_default_namer (thing , is_edge = True ):
85
+ """ Returns a "good" string for thing in printed graphs. """
86
+ if is_edge :
87
+ if thing .name is None or thing .name .startswith ('tmp' ):
88
+ return ''
89
+ else :
90
+ return '/' .join ([thing .name , str (len (thing ))])
91
+ elif isinstance (thing , Const ):
92
+ return str (thing .val )
93
+ elif isinstance (thing , WireVector ):
94
+ return thing .name or '??'
95
+ else :
96
+ try :
97
+ return thing .op + str (thing .op_param or '' )
98
+ except AttributeError :
99
+ raise PyrtlError ('no naming rule for "%s"' % str (thing ))
100
+
101
+
110
102
def output_to_trivialgraph (file , namer = _trivialgraph_default_namer , block = None , split_state = False ):
111
103
""" Walk the block and output it in trivial graph format to the open file.
112
104
@@ -139,6 +131,11 @@ def output_to_trivialgraph(file, namer=_trivialgraph_default_namer, block=None,
139
131
print ('%d %d %s' % (from_index , to_index , namer (edge )), file = file )
140
132
141
133
134
+ # -----------------------------------------------------------------
135
+ # __ __ __ __ __
136
+ # / _` |__) |__| |__) |__| \ / | /
137
+ # \__> | \ | | | | | \/ | /__
138
+
142
139
def _default_edge_namer (edge , is_to_splitmerge = False , extra_edge_info = None ):
143
140
"""
144
141
A function for naming an edge for use in the graphviz graph.
@@ -376,6 +373,11 @@ def block_to_graphviz_string(block=None, namer=_graphviz_default_namer, split_st
376
373
return rstring
377
374
378
375
376
+ # -----------------------------------------------------------------
377
+ # __ __
378
+ # /__` \ / / _`
379
+ # .__/ \/ \__>
380
+
379
381
def output_to_svg (file , block = None , split_state = True ):
380
382
""" Output the block as an SVG to the open file.
381
383
@@ -400,6 +402,11 @@ def block_to_svg(block=None, split_state=True):
400
402
raise PyrtlError ('need graphviz installed (try "pip install graphviz")' )
401
403
402
404
405
+ # -----------------------------------------------------------------
406
+ # ___
407
+ # |__| | |\/| |
408
+ # | | | | | |___
409
+
403
410
def trace_to_html (simtrace , trace_list = None , sortkey = None ):
404
411
""" Return a HTML block showing the trace.
405
412
0 commit comments