*/
map = new Hashtable();
for(int i=0; i < ihs.length; i++) {
if(ihs[i] instanceof BranchHandle) {
BranchInstruction bi = (BranchInstruction)ihs[i].getInstruction();
if(bi instanceof Select) { // Special cases LOOKUPSWITCH and TABLESWITCH
InstructionHandle[] targets = ((Select)bi).getTargets();
for(int j=0; j < targets.length; j++) {
put(targets[j], "Label" + label_counter++ + ":");
}
}
InstructionHandle ih = bi.getTarget();
put(ih, "Label" + label_counter++ + ":");
}
}
LocalVariableGen[] lvs = mg.getLocalVariables();
for(int i=0; i < lvs.length; i++) {
InstructionHandle ih = lvs[i].getStart();
put(ih, "Label" + label_counter++ + ":");
ih = lvs[i].getEnd();
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()));
}
}