TOPLEVEL = new SubroutineImpl();
// Calculate "real" subroutines.
Set sub_leaders = new HashSet(); // Elements: InstructionHandle
for (int i=0; i<all.length; i++){
Instruction inst = all[i].getInstruction();
if (inst instanceof JsrInstruction){
sub_leaders.add(((JsrInstruction) inst).getTarget());
}
}
// Build up the database.
Iterator iter = sub_leaders.iterator();
while (iter.hasNext()){
SubroutineImpl sr = new SubroutineImpl();
InstructionHandle astore = (InstructionHandle) (iter.next());
sr.setLocalVariable( ((ASTORE) (astore.getInstruction())).getIndex() );
subroutines.put(astore, sr);
}
// Fake it a bit. We want a virtual "TopLevel" subroutine.
subroutines.put(all[0], TOPLEVEL);
sub_leaders.add(all[0]);
// Tell the subroutines about their JsrInstructions.
// Note that there cannot be a JSR targeting the top-level
// since "Jsr 0" is disallowed in Pass 3a.
// Instructions shared by a subroutine and the toplevel are
// disallowed and checked below, after the BFS.
for (int i=0; i<all.length; i++){
Instruction inst = all[i].getInstruction();
if (inst instanceof JsrInstruction){
InstructionHandle leader = ((JsrInstruction) inst).getTarget();
((SubroutineImpl) getSubroutine(leader)).addEnteringJsrInstruction(all[i]);
}
}