@@ -137,22 +137,42 @@ func (l *Label) resolve(code []byte, bytecodeOffset int) bool {
137
137
return hasAsmInstructions
138
138
}
139
139
140
- func (l * Label ) markSubroutine (subroutineId int , numSubroutine int ) {
140
+ func (l * Label ) markSubroutine (subroutineID int , numSubroutine int ) {
141
141
listOfBlocksToProcess := l
142
142
listOfBlocksToProcess .nextListElement = EMPTY_LIST
143
143
for listOfBlocksToProcess != EMPTY_LIST {
144
144
basicBlock := listOfBlocksToProcess
145
145
listOfBlocksToProcess = listOfBlocksToProcess .nextListElement
146
146
basicBlock .nextListElement = nil
147
- if ! basicBlock .isInSubroutine (subroutineId ) {
148
- basicBlock .addToSubroutine (subroutineId , numSubroutine )
147
+ if ! basicBlock .isInSubroutine (subroutineID ) {
148
+ basicBlock .addToSubroutine (subroutineID , numSubroutine )
149
149
listOfBlocksToProcess = basicBlock .pushSuccessors (listOfBlocksToProcess )
150
150
}
151
151
}
152
152
}
153
153
154
- func (l Label ) addSubroutineRetSuccessors (subroutineCaller * Label , numSubroutine int ) {
155
- //TODO
154
+ func (l * Label ) addSubroutineRetSuccessors (subroutineCaller * Label , numSubroutine int ) {
155
+ listOfProcessedBlocks := EMPTY_LIST
156
+ listOfBlocksToProcess := l
157
+ listOfBlocksToProcess .nextListElement = EMPTY_LIST
158
+ for listOfBlocksToProcess != EMPTY_LIST {
159
+ basicBlock := listOfBlocksToProcess
160
+ listOfBlocksToProcess = basicBlock .nextListElement
161
+ basicBlock .nextListElement = listOfProcessedBlocks
162
+ listOfProcessedBlocks = basicBlock
163
+
164
+ if (basicBlock .flags & FLAG_SUBROUTINE_END ) != 0 && ! basicBlock .isInSameSubroutine (subroutineCaller ) {
165
+ basicBlock .outgoingEdges = NewEdge (int (basicBlock .outputStackSize ), subroutineCaller .outgoingEdges .successor , basicBlock .outgoingEdges )
166
+ }
167
+
168
+ listOfBlocksToProcess = basicBlock .pushSuccessors (listOfBlocksToProcess )
169
+ }
170
+
171
+ for listOfProcessedBlocks != EMPTY_LIST {
172
+ nextListElement := listOfProcessedBlocks .nextListElement
173
+ listOfProcessedBlocks .nextListElement = nil
174
+ listOfProcessedBlocks = nextListElement
175
+ }
156
176
}
157
177
158
178
func (l * Label ) pushSuccessors (listOfLabelsToProcess * Label ) * Label {
@@ -170,9 +190,9 @@ func (l *Label) pushSuccessors(listOfLabelsToProcess *Label) *Label {
170
190
return listOfLabelsToProcess
171
191
}
172
192
173
- func (l Label ) isInSubroutine (subroutineId int ) bool {
193
+ func (l Label ) isInSubroutine (subroutineID int ) bool {
174
194
if (l .flags & FLAG_SUBROUTINE_BODY ) != 0 {
175
- return (l .values [subroutineId / 32 ] & (1 << (uint (subroutineId ) % 32 ))) != 0
195
+ return (l .values [subroutineID / 32 ] & (1 << (uint (subroutineID ) % 32 ))) != 0
176
196
}
177
197
return false
178
198
}
@@ -189,10 +209,10 @@ func (l Label) isInSameSubroutine(basicBlock *Label) bool {
189
209
return false
190
210
}
191
211
192
- func (l * Label ) addToSubroutine (subroutineId int , numSubroutine int ) {
212
+ func (l * Label ) addToSubroutine (subroutineID int , numSubroutine int ) {
193
213
if (l .flags & FLAG_SUBROUTINE_BODY ) == 0 {
194
214
l .flags |= FLAG_SUBROUTINE_BODY
195
215
l .values = make ([]int , numSubroutine / 32 + 1 )
196
216
}
197
- l .values [subroutineId / 32 ] |= (1 << (uint (subroutineId ) % 32 ))
217
+ l .values [subroutineID / 32 ] |= (1 << (uint (subroutineID ) % 32 ))
198
218
}
0 commit comments