PPI: Implement PPI dump
[senf.git] / PPI / drawmodules.py
1 #!/usr/bin/python
2
3 import sys
4
5 mode = "MODULE"
6
7 sys.stdout.write("""
8 digraph Modules {
9 node [shape=box, fontsize=10, fontname="Helvetica", height=.2];
10 edge [labelfontsize=8, labelfontname="Helvetica"]
11 """)
12
13 modules = {}
14 connectors = {}
15
16 for line in sys.stdin:
17     line = line.strip()
18     if line == "":
19         mode = "MODULE"
20     elif mode == "MODULE":
21         moduleid, module = line.split(' ',1);
22         connectorid = type = peerid = None
23         modules[moduleid] = (module, []);
24         mode = "CONNECTOR"
25     else:
26         connectorid, type = line.split(' ',1);
27         elts = type.rsplit(' ',1);
28         if elts[-1].startswith('0x'):
29             type, peerid = elts
30         else:
31             peerid = None
32         modules[moduleid][1].append((connectorid, type, peerid))
33         connectors[connectorid] = moduleid
34
35 for moduleid, (type, cs) in modules.iteritems():
36     type = type.split('<',1)[0]
37     type = type.rsplit('::',1)[-1]
38     sys.stdout.write('"%s" [label="%s (%s)"]\n' % (moduleid,  type, moduleid))
39
40 anonid = 0
41
42 for moduleid, (type, cs) in modules.iteritems():
43     for connectorid, type, peerid in cs:
44         opts = []
45         if "Passive" in type:
46             opts.append("arrowtail=odot");
47         if peerid:
48             opts.append('headlabel="%s"' % peerid)
49         opts.append('taillabel="%s"' % connectorid)
50         opts = ",".join(opts)
51         if opts:
52             opts = " [%s]" % opts
53         if "Output" in type and peerid is not None:
54             sys.stdout.write('"%s" -> "%s"%s\n' % (moduleid, connectors[peerid],opts))
55         elif peerid is None:
56             sys.stdout.write('anon%d [label="", shape=point, height=.05];\n' % anonid)
57             if "Output" in type:
58                 sys.stdout.write('"%s" -> anon%d%s;\n' % (moduleid, anonid, opts))
59             else:
60                 sys.stdout.write('anon%d -> "%s"%s;\n' % (anonid, moduleid, opts))
61             anonid += 1
62
63 sys.stdout.write("}\n")