put(ih, "Label" + label_counter++ + ":");
}
CodeExceptionGen[] ehs = mg.getExceptionHandlers();
for(int i=0; i < ehs.length; i++) {
CodeExceptionGen c = ehs[i];
InstructionHandle ih = c.getStartPC();
put(ih, "Label" + label_counter++ + ":");
ih = c.getEndPC();
put(ih, "Label" + label_counter++ + ":");
ih = c.getHandlerPC();
put(ih, "Label" + label_counter++ + ":");
}
LineNumberGen[] lns = mg.getLineNumbers();
for(int i=0; i < lns.length; i++) {
InstructionHandle ih = lns[i].getInstruction();
put(ih, ".line " + lns[i].getSourceLine());
}
/* Pass 2: Output code.
*/
for(int i=0; i < lvs.length; i++) {
LocalVariableGen l = lvs[i];
out.println(".var " + l.getIndex() + " is " + l.getName() + " " +
l.getType().getSignature() +
" from " + get(l.getStart()) +
" to " + get(l.getEnd()));
}
out.print("\n");
for(int i=0; i < ihs.length; i++) {
InstructionHandle ih = ihs[i];
Instruction inst = ih.getInstruction();
String str = (String)map.get(ih);
if(str != null) {
out.println(str);
}
if(inst instanceof BranchInstruction) {
if(inst instanceof Select) { // Special cases LOOKUPSWITCH and TABLESWITCH
Select s = (Select)inst;
int[] matchs = s.getMatchs();
InstructionHandle[] targets = s.getTargets();
if(s instanceof TABLESWITCH) {
out.println("\ttableswitch " + matchs[0] + " " +
matchs[matchs.length - 1]);
for(int j=0; j < targets.length; j++) {
out.println("\t\t" + get(targets[j]));
}
} else { // LOOKUPSWITCH
out.println("\tlookupswitch ");
for(int j=0; j < targets.length; j++) {
out.println("\t\t" + matchs[j] + " : " + get(targets[j]));
}
}
out.println("\t\tdefault: " + get(s.getTarget())); // Applies for both
} else {
BranchInstruction bi = (BranchInstruction)inst;
ih = bi.getTarget();
str = get(ih);
out.println("\t" + Constants.OPCODE_NAMES[bi.getOpcode()] + " " + str);
}
} else {
out.println("\t" + inst.toString(cp.getConstantPool()));
}
}
out.print("\n");
for(int i=0; i < ehs.length; i++) {
CodeExceptionGen c = ehs[i];
ObjectType caught = c.getCatchType();
String class_name = (caught == null)? // catch any exception, used when compiling finally
"all" : caught.getClassName().replace('.', '/');
out.println(".catch " + class_name + " from " +
get(c.getStartPC()) + " to " + get(c.getEndPC()) +
" using " + get(c.getHandlerPC()));
}
printEndMethod(code);
}