/** * Helper method to generate an instance of a subclass of * {@link LoadInstruction} based on the specified {@link Type} that will * load the specified local variable * @param index the JVM stack frame index of the variable that is to be * loaded * @param type the {@link Type} of the variable * @return the generated {@link LoadInstruction} */ private static Instruction loadLocal(int index, Type type) { if (type == Type.BOOLEAN) { return new ILOAD(index); } else if (type == Type.INT) { return new ILOAD(index); } else if (type == Type.SHORT) { return new ILOAD(index); } else if (type == Type.LONG) { return new LLOAD(index); } else if (type == Type.BYTE) { return new ILOAD(index); } else if (type == Type.CHAR) { return new ILOAD(index); } else if (type == Type.FLOAT) { return new FLOAD(index); } else if (type == Type.DOUBLE) { return new DLOAD(index); } else { return new ALOAD(index); } }
/** * Helper method to generate an instance of a subclass of * {@link StoreInstruction} based on the specified {@link Type} that will * store a value in the specified local variable * @param index the JVM stack frame index of the variable that is to be * stored * @param type the {@link Type} of the variable * @return the generated {@link StoredInstruction} */ private static Instruction storeLocal(int index, Type type) { if (type == Type.BOOLEAN) { return new ISTORE(index); } else if (type == Type.INT) { return new ISTORE(index); } else if (type == Type.SHORT) { return new ISTORE(index); } else if (type == Type.LONG) { return new LSTORE(index); } else if (type == Type.BYTE) { return new ISTORE(index); } else if (type == Type.CHAR) { return new ISTORE(index); } else if (type == Type.FLOAT) { return new FSTORE(index); } else if (type == Type.DOUBLE) { return new DSTORE(index); } else { return new ASTORE(index); } }
/** * Returns an instruction for storing a value from the JVM stack * into this variable. */ public Instruction storeInstruction() { final Instruction instr = _storeInstruction; if (_storeInstruction == null) { _storeInstruction = _type.STORE(_local.getIndex()); } return _storeInstruction; }
private boolean visitInstruction( final Instruction i ) { final short opcode = i.getOpcode(); if ((InstructionConst.getInstruction(opcode) != null) && !(i instanceof ConstantPushInstruction) && !(i instanceof ReturnInstruction)) { // Handled below _out.println("il.append(InstructionConst." + i.getName().toUpperCase(Locale.ENGLISH) + ");"); return true; } return false; }
/** * Returns an instruction for loading the value of this variable onto * the JVM stack. */ public Instruction loadInstruction() { if (_loadInstruction == null) { _loadInstruction = _type.LOAD(_local.getIndex()); } return _loadInstruction; }
public Instruction SUB() { return InstructionConst.DSUB; }
/** * Set the instruction for loading the value of this variable onto the * JVM stack and returns the old instruction. */ public Instruction setLoadInstruction(Instruction instruction) { Instruction tmp = _loadInstruction; _loadInstruction = instruction; return tmp; }
/** * Set the instruction for storing a value from the stack into this * variable and returns the old instruction. */ public Instruction setStoreInstruction(Instruction instruction) { Instruction tmp = _storeInstruction; _storeInstruction = instruction; return tmp; }
public Instruction STORE(int slot) { return new ASTORE(slot); }
public Instruction POP() { return NOP; }
public Instruction ADD() { return InstructionConstants.IADD; }
public Instruction MUL() { return null; // should never be called }
public Instruction STORE(int slot) { return new DSTORE(slot); }
public Instruction REM() { return InstructionConstants.IREM; }
public Instruction NEG() { return InstructionConstants.INEG; }
public Instruction storeContextNode() { return storeCurrentNode(); }
public Instruction loadParameter(int index) { return new ALOAD(index + PARAM_START_INDEX); }
public Instruction storeParameter(int index) { return new ASTORE(index + PARAM_START_INDEX); }
public Instruction LOAD(int slot) { return new ALOAD(slot); }
public Instruction ADD() { return InstructionConstants.DADD; }
public Instruction SUB() { return InstructionConstants.DSUB; }
public Instruction MUL() { return InstructionConstants.DMUL; }
public Instruction STORE(int slot) { return new ISTORE(slot); }
public Instruction REM() { return InstructionConstants.DREM; }
public Instruction LOAD(int slot) { return new DLOAD(slot); }
public Instruction loadIterator() { return _aloadIterator; }
public Instruction CMP(boolean less) { return less ? InstructionConstants.DCMPG : InstructionConstants.DCMPL; }
public Instruction DUP() { return DUP2; }
public Instruction POP() { return POP; }
public Instruction DIV() { return null; // should never be called }
public Instruction REM() { return null; // should never be called }
public Instruction DIV() { return InstructionConst.IDIV; }
public Instruction LOAD(int slot) { return null; // should never be called }