-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot-graph.py
29 lines (25 loc) · 1.05 KB
/
dot-graph.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
import csv
lval = {}
file_of_block = 'forward_block.csv'
file_of_graph = 'forward_block.gv'
with open(file_of_block, newline='') as inp:
reader = csv.reader(inp)
for row in reader:
lval[row[0]] = 1
with open(file_of_block, newline='') as inp:
reader = csv.reader(inp)
with open(file_of_graph, 'w', newline='') as out:
out.write("digraph G{\nnode[shape = record];\n")
for row in reader:
out.write('i{a1}[label = "<f0> {a1} | <tag> {tag} | '.format(
a1=row[0], tag=row[1]))
for i in range(2, len(row) - 1):
col = row[i]
out.write('<i{a}> | '.format(a=row[i]))
out.write('<minor_collections> {count}"]\n'.format(count = row[-1]))
for i in range(2, len(row) - 1):
if row[i] in lval:
# only addresses that appear on the lhs can be linked
out.write('"i{ptr}":i{child} -> "i{child}":f0\n'.format(
ptr=row[0], child=row[i]))
out.write("}\n")