forked from ARM-software/CSAL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cs_topology_dot.py
132 lines (120 loc) · 4.51 KB
/
cs_topology_dot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
"""
Render a CoreSight topology as a 'dot' graph source.
Copyright (C) ARM Ltd. 2019. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from __future__ import print_function
import cs_topology
def generate_dot(p):
"""
Render the ATB topology as a dot/graphviz graph.
This is exclusive of the surrounding 'digraph', so other objects can be added.
Output is written to standard output.
"""
seq = 0
for d in p:
seq += 1
d.dotid = "D%u" % seq
d.dotshow = False
for ln in p.links:
if ln.linktype == cs_topology.CS_LINK_CTI:
continue
attrs = []
if ln.master.type == cs_topology.CS_DEVTYPE_REPLICATOR and not ln.master.is_hidden:
attrs.append("taillabel=\"%u\"" % ln.master_port)
if ln.slave.type == cs_topology.CS_DEVTYPE_FUNNEL and not ln.slave.is_hidden:
attrs.append("headlabel=\"%u\"" % ln.slave_port)
print(" %s -> %s [%s];" % (ln.master.dotid, ln.slave.dotid, ', '.join(attrs)))
ln.master.dotshow = True
ln.slave.dotshow = True
for d in p:
if not d.dotshow:
continue
if d.name is None:
d.name = "d_%u" % seq
# The type of the device is in most cases obvious from the name it was given in the SDF file.
if d.type == cs_topology.CS_DEVTYPE_FUNNEL:
shape = "invtrapezium"
elif d.type == cs_topology.CS_DEVTYPE_REPLICATOR:
shape = "trapezium"
else:
shape = "box"
if not d.is_hidden:
name = d.name # This generally indicates the type - e.g. it's derived from the type or a core name
# ETF and ETB
try:
name += "\\n%uK" % (d.ram_size_bytes / 1024)
except:
pass
if d.type == cs_topology.CS_DEVTYPE_BUFFER:
name += "\\nbuffer"
elif d.type == cs_topology.CS_DEVTYPE_ROUTER:
name += "\\nrouter"
# Funnels
try:
name += "\\n%u ports" % (d.port_count)
except:
pass
# ETMs
try:
name += "\\n%s" % (d.version_string)
except:
pass
# All devices should have a part number
try:
name += "\\n%03X" % (d.part_number)
except:
pass
else:
name = ""
print(" %s [label=\"%s\" shape=\"%s\"];" % (d.dotid, name, shape))
if d.type == cs_topology.CS_DEVTYPE_ROUTER:
print(" %sAXI [label=\"AXI\" shape=\"circle\"];" % (d.dotid))
try:
lab = "%u bits" % d.mem_width_bits
except:
lab = ""
print(" %s -> %sAXI [label=\"%s\"];" % (d.dotid, d.dotid, lab))
elif d.type == cs_topology.CS_DEVTYPE_PORT:
lab = "port"
try:
lab += "\\n%s bits" % d.port_sizes
except:
pass
print(" %sPORT [label=\"%s\"];" % (d.dotid, lab))
print(" %s -> %sPORT;" % (d.dotid, d.dotid))
def rank_all(x):
printed = False
for d in x:
if d.dotshow:
if not printed:
print(" subgraph {")
print(" rank=same;")
printed = True
print(" %s;" % d.dotid)
if printed:
print(" }")
rank_all([d for d in p if d.type == cs_topology.CS_DEVTYPE_CORE])
rank_all([d for d in p if d.type[0] == 3])
rank_all([d for d in p if d.type[0] == 1])
def generate_digraph(p, size="8,11", label="None"):
"""
Generate a complete digraph to standard output.
The caller can concatenate these to form a multipage document.
"""
print("digraph {")
if label is not None:
# Add the label. Hopefully no characters that need escaping.
print(" label=\"%s\";" % label)
print(" size=\"%s\";" % size)
generate_dot(p)
print("}")