forked from hacklabto/hacklab-engraver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hal_sigs_graphviz.py
executable file
·87 lines (63 loc) · 2.43 KB
/
hal_sigs_graphviz.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
#!/usr/bin/python
import string
print "digraph hal_nets {"
print """
graph [
rankdir = "LR"
];
node [
fontsize = "8"
];
"""
# defs
f = open("pin.out", "r")
component_hash={}
for line in f:
comp_name, pin_type, pin_dir, pin_value, pin_name = line.split()[:5]
part_name, part_pin_name = pin_name.rsplit('.', 1)
if pin_name.startswith("motion."):
part_name = pin_name
if not component_hash.has_key(part_name):
component_hash[part_name] = [];
component_hash[part_name].append(pin_name)
for comp in component_hash.keys():
comp_labels = ["<" + c + "> " + c for c in component_hash[comp]]
print "\"" + comp + "\"" + " ["
print "\tlabel = " + "\"" + string.join(comp_labels, " | ") + "\""
print "\tshape = \"record\""
print "]"
print "\n\n\n"
# nets
def component(component_hash,pin):
for lst in component_hash.values():
if pin in lst:
return component_hash.keys()[component_hash.values().index(lst)]
f = open("pin.out", "r")
net_list = []
for line in f:
sig_list = line.split()
sig_type, sig_value = sig_list[0:2]
sig_declarations = sig_list[2:]
for count in range(len(sig_declarations)):
if sig_declarations[count] in ["<==", "==>"]:
pin1 = sig_declarations[count - 1]
pin2 = sig_declarations[count + 1]
comp1 = component(component_hash, pin1)
if comp1 != None:
comp1 = "\"" + comp1 + "\"" + ":"
else:
comp1 = ""
comp2 = component(component_hash, pin2)
if comp2 != None:
comp2 = "\"" + comp2 + "\"" + ":"
else:
comp2 = ""
comp_pin1 = comp1 + "\"" + pin1 + "\""
comp_pin2 = comp2 + "\"" + pin2 + "\""
if sig_declarations[count] == "<==":
net_list.append(comp_pin2 + " -> " + comp_pin1) # "a <== b" ===>> "b -> a"
if sig_declarations[count] == "==>":
net_list.append(comp_pin1 + " -> " + comp_pin2) # "a ==> b" ===>> "a -> b"
for line in net_list:
print line + ";"
print "}"