-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasicblock.py
136 lines (94 loc) · 2.99 KB
/
basicblock.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
132
133
134
135
136
"""
File: basicblock.py
Authors: Tim van Deurzen, Koos van Strien
Date: 26-02-2010
"""
from operations_new import *
class basicBlock:
"""
Represents a basic block
"""
def __init__(self, name, startLine):
"""
Initialises all class variables.
"""
self.name = name
self.startLine = startLine
self.target = None
self.previous = []
self.operations = []
self.genSet = []
self.killSet = []
self.labels = []
def __str__(self):
return str(self.startLine) + ": " + self.name
def interval(self):
"""
Gives a string representation if the line interval.
"""
return str(self.operations[0].lineNumber) + " - " + \
str(self.operations[len(self.operations) - 1].lineNumber)
def addOperation(self, line):
"""
Method for adding an operation to the operations allready inside this
basicblock.
"""
self.operations.append(line)
def numOperations(self):
"""
Count the number of operations within this basic block.
"""
return len(self.operations)
def exclude(self):
"""
Exclude the entire block from the code.
"""
for operation in self.operations:
operation.exclude()
def getLine(self, lineNumber):
"""
Returns a line of code, using the global line number, not the line
number within the block.
"""
return self.operation[lineNumber - self.startLine].code
def addGen(self, lineNumber):
"""
Appends a linenumber to the gen list.
"""
self.genSet.append(lineNumber)
def addKill(self, lineNumber):
"""
Appends a linenumber to the kill list.
"""
self.killSet.append(lineNumber)
def getLabel(self):
"""
Return the name / label of this basicblock.
"""
return self.name
def findLabel(self, label):
"""
Constructs a list of all available labels within this basic block.
"""
if label[0] == "$":
for operation in self.operations:
if operation.type == operation.LABEL and \
operation.getLabelName()[0:3] == label:
self.labels.append(label)
return True
elif label[0:2] == "__":
for operation in self.operations:
if operation.type == operation.LABEL and \
operation.getLabelName()[:-2] == label[2:]:
self.labels.append(label)
return True
return False
def hasLabel(self, label):
"""
Check the list of available labels or look for a label over every line
of code.
"""
if label in self.labels:
return True
else:
return self.findLabel(label)