InstructionHandle pushParams(InstructionList il, Method m) { Type[] params = mtab.typesOfParams(m); InstructionHandle pos = il.getStart(); for (int i = 0, param = 0; i < params.length; i++, param++) { if (params[i].equals(Type.BOOLEAN) || params[i].equals(Type.BYTE) || params[i].equals(Type.SHORT) || params[i].equals(Type.CHAR) || params[i].equals(Type.INT)) { il.insert(pos, new ILOAD(param)); } else if (params[i].equals(Type.FLOAT)) { il.insert(pos, new FLOAD(param)); } else if (params[i].equals(Type.LONG)) { il.insert(pos, new LLOAD(param)); param++; } else if (params[i].equals(Type.DOUBLE)) { il.insert(pos, new DLOAD(param)); param++; } else { il.insert(pos, new ALOAD(param)); } } return pos; }
void removeUnusedLocals(Method mOrig, MethodGen m) { InstructionList il = m.getInstructionList(); InstructionHandle[] ins = il.getInstructionHandles(); for (int i = 0; i < ins.length; i++) { Instruction in = ins[i].getInstruction(); if (in instanceof LocalVariableInstruction) { LocalVariableInstruction curr = (LocalVariableInstruction) in; if (mtab.getLocal(m, curr, ins[i].getPosition()) != null && curr.getIndex() < m.getMaxLocals() - 5 && !mtab.isLocalUsedInInlet(mOrig, curr.getIndex())) { if (curr instanceof IINC) { ins[i].setInstruction(new NOP()); } else if (curr instanceof LSTORE || curr instanceof DSTORE) { ins[i].setInstruction(new POP2()); } else if (curr instanceof StoreInstruction) { ins[i].setInstruction(new POP()); } else if (curr instanceof ALOAD) { ins[i].setInstruction(new ACONST_NULL()); } else if (curr instanceof FLOAD) { ins[i].setInstruction(new FCONST((float) 0.0)); } else if (curr instanceof ILOAD) { ins[i].setInstruction(new ICONST(0)); } else if (curr instanceof DLOAD) { ins[i].setInstruction(new DCONST(0.0)); } else if (curr instanceof LLOAD) { ins[i].setInstruction(new LCONST(0L)); } else { System.out.println("unhandled ins in " + "removeUnusedLocals: " + curr); System.exit(1); } } } } }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ public void visitFLOAD(FLOAD o){ int idx = o.getIndex(); if (idx < 0){ constraintViolated(o, "Index '"+idx+"' must be non-negative."); } else{ int maxminus1 = max_locals()-1; if (idx > maxminus1){ constraintViolated(o, "Index '"+idx+"' must not be greater than max_locals-1 '"+maxminus1+"'."); } } }
@SuppressWarnings("unused") // Called using reflection private Instruction createInstructionFload(Element inst) throws IllegalXMLVMException { int idx = Integer.parseInt(inst.getAttributeValue("index")); return new FLOAD(idx); }