-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflowgraph.py
38 lines (28 loc) · 975 Bytes
/
flowgraph.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
class flowGraph:
"""
Represents a flow graph for assembly source code
"""
def __init__(self, blocks):
"""
Initialises some variables and calls the methods for building the graph.
"""
self.dotSource = ""
self.basicBlocks = blocks
self.buildGraph()
def buildGraph(self):
"""
Iterates over all basic blocks and builds the dot source for a
flowgraph.
"""
self.dotSource = "digraph flowgraph {"
for block in self.basicBlocks:
if block.targets:
for target in block.targets:
self.dotSource += block.name + " -> " + target.name + "\n"
else:
self.dotSource += block.name + " -> system\n"
self.dotSource += "}"
def saveToFile(self, sourcefolder, filename):
file = open(sourcefolder + filename, "w")
file.write(self.dotSource)
file.close()