Skip to content

Commit 75af837

Browse files
author
Vincent Rasquier
committed
Progress on edge and label + README
1 parent da24636 commit 75af837

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Second reason could be to provide different tools for JVM manipulation through G
1313

1414
| CLASS | PROGRESS % |
1515
| ----- | ---------- |
16-
| ClassReader | 60% |
16+
| ClassReader | 70% |
1717
| ClassVisitor | 100% |
1818
| MethodVisitor | 100% |
1919
| FieldVisitor | 100% |
@@ -22,8 +22,9 @@ Second reason could be to provide different tools for JVM manipulation through G
2222
| Handle | 100% |
2323
| Attribute | ? |
2424
| Context | ? |
25-
| Label | 80% |
25+
| Label | 90% |
2626
| TypeReference | ? |
2727
| Opcodes | ? |
2828
| Symbol | ? |
2929
| TypePath | 0% |
30+
| EDGE | 80% |

asm/edge.go

+4
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ type Edge struct {
1515
successor *Label
1616
nextEdge *Edge
1717
}
18+
19+
func NewEdge(info int, successor *Label, nextEdge *Edge) *Edge {
20+
return &Edge{info, successor, nextEdge}
21+
}

asm/label.go

+29-9
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,42 @@ func (l *Label) resolve(code []byte, bytecodeOffset int) bool {
137137
return hasAsmInstructions
138138
}
139139

140-
func (l *Label) markSubroutine(subroutineId int, numSubroutine int) {
140+
func (l *Label) markSubroutine(subroutineID int, numSubroutine int) {
141141
listOfBlocksToProcess := l
142142
listOfBlocksToProcess.nextListElement = EMPTY_LIST
143143
for listOfBlocksToProcess != EMPTY_LIST {
144144
basicBlock := listOfBlocksToProcess
145145
listOfBlocksToProcess = listOfBlocksToProcess.nextListElement
146146
basicBlock.nextListElement = nil
147-
if !basicBlock.isInSubroutine(subroutineId) {
148-
basicBlock.addToSubroutine(subroutineId, numSubroutine)
147+
if !basicBlock.isInSubroutine(subroutineID) {
148+
basicBlock.addToSubroutine(subroutineID, numSubroutine)
149149
listOfBlocksToProcess = basicBlock.pushSuccessors(listOfBlocksToProcess)
150150
}
151151
}
152152
}
153153

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+
}
156176
}
157177

158178
func (l *Label) pushSuccessors(listOfLabelsToProcess *Label) *Label {
@@ -170,9 +190,9 @@ func (l *Label) pushSuccessors(listOfLabelsToProcess *Label) *Label {
170190
return listOfLabelsToProcess
171191
}
172192

173-
func (l Label) isInSubroutine(subroutineId int) bool {
193+
func (l Label) isInSubroutine(subroutineID int) bool {
174194
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
176196
}
177197
return false
178198
}
@@ -189,10 +209,10 @@ func (l Label) isInSameSubroutine(basicBlock *Label) bool {
189209
return false
190210
}
191211

192-
func (l *Label) addToSubroutine(subroutineId int, numSubroutine int) {
212+
func (l *Label) addToSubroutine(subroutineID int, numSubroutine int) {
193213
if (l.flags & FLAG_SUBROUTINE_BODY) == 0 {
194214
l.flags |= FLAG_SUBROUTINE_BODY
195215
l.values = make([]int, numSubroutine/32+1)
196216
}
197-
l.values[subroutineId/32] |= (1 << (uint(subroutineId) % 32))
217+
l.values[subroutineID/32] |= (1 << (uint(subroutineID) % 32))
198218
}

0 commit comments

Comments
 (0)