Java Code Examples for org.objectweb.asm.Opcodes#CALOAD

The following examples show how to use org.objectweb.asm.Opcodes#CALOAD . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From Concurnas with MIT License 5 votes vote down vote up
public static void applyArrayLoad(BytecodeOutputter mv, Type origType) {
	if(origType instanceof PrimativeType && origType.getArrayLevels() == 1 )
	{
		PrimativeTypeEnum ee = ((PrimativeType)origType).type;
		int op;
		switch(ee)
		{
			case BOOLEAN: op = Opcodes.BALOAD; break; 
			case CHAR: op = Opcodes.CALOAD; break; 
			case FLOAT: op = Opcodes.FALOAD; break; 
			case DOUBLE: op = Opcodes.DALOAD; break; 
			case SHORT: op = Opcodes.SALOAD; break; 
			case INT: op = Opcodes.IALOAD; break; 
			case BYTE: op = Opcodes.BALOAD; break; 
			default: op = Opcodes.LALOAD; break;//long 
		}
		mv.visitInsn(op);
		
	}
	else
	{//HERE BE PROBLEMS
		if(TypeCheckUtils.hasRefLevelsAndIsArray(origType)){
			mv.visitInsn(Opcodes.SWAP);
			extractAndCastArrayRef(mv, origType);
			mv.visitInsn(Opcodes.SWAP);
		}
		
		mv.visitInsn(Opcodes.AALOAD);
	}
}
 
Example 2
Source File: JVMImpl.java    From serianalyzer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param opcode
 * @return
 */
private static Type toType ( int opcode ) {
    switch ( opcode ) {
    case Opcodes.LLOAD:
        return Type.LONG_TYPE;
    case Opcodes.ILOAD:
        return Type.INT_TYPE;
    case Opcodes.FLOAD:
        return Type.FLOAT_TYPE;
    case Opcodes.DLOAD:
        return Type.DOUBLE_TYPE;
    case Opcodes.ALOAD:
        return Type.getType("Ljava/lang/Object;"); //$NON-NLS-1$
    case Opcodes.IALOAD:
        return Type.INT_TYPE;
    case Opcodes.LALOAD:
        return Type.LONG_TYPE;
    case Opcodes.FALOAD:
        return Type.FLOAT_TYPE;
    case Opcodes.DALOAD:
        return Type.DOUBLE_TYPE;
    case Opcodes.BALOAD:
        return Type.BYTE_TYPE;
    case Opcodes.CALOAD:
        return Type.CHAR_TYPE;
    case Opcodes.SALOAD:
        return Type.SHORT_TYPE;
    }
    return Type.VOID_TYPE;
}
 
Example 3
Source File: InstructionAssembler.java    From es6draft with MIT License 5 votes vote down vote up
public final void aload(Type type) {
    switch (type.getOpcode(Opcodes.IALOAD)) {
    case Opcodes.IALOAD:
        iaload();
        return;
    case Opcodes.LALOAD:
        laload();
        return;
    case Opcodes.FALOAD:
        faload();
        return;
    case Opcodes.DALOAD:
        daload();
        return;
    case Opcodes.AALOAD:
        aaload();
        return;
    case Opcodes.BALOAD:
        baload();
        return;
    case Opcodes.CALOAD:
        caload();
        return;
    case Opcodes.SALOAD:
        saload();
        return;
    default:
        throw new IllegalArgumentException();
    }
}
 
Example 4
Source File: StackHelper.java    From zelixkiller with GNU General Public License v3.0 4 votes vote down vote up
public InsnValue loadFromArray(AbstractInsnNode insn, InsnValue value1, InsnValue indexValue) throws AnalyzerException {
	Object indexObj = indexValue.getValue(), arrayObj = value1.getValue();
	int index = indexObj == null ? -1 : ((Number) indexObj).intValue();
	boolean arrayNotSimulated = arrayObj == null;
	Type t = arrayNotSimulated ? null : Type.getType(arrayObj.getClass());
	switch (insn.getOpcode()) {
	case Opcodes.IALOAD:
		if (arrayNotSimulated) {
			return InsnValue.INT_VALUE;
		}
		// Sometimes Object[] contain values. Stringer obfuscator does this.
		// TODO: Have this sort of check for others?
		boolean oarr = t.equals(InsnValue.REFERENCE_ARR_VALUE.getType());
		if (oarr) {
			int[] ia = (int[]) arrayObj;
			return InsnValue.intValue(ia[index]);
		}else{
			Object[] obarr = (Object[]) arrayObj;
			Object o = obarr[index];
			if (o == null){
				return InsnValue.INT_VALUE;
			}
			return InsnValue.intValue(((Number) o).intValue());
		}
	case Opcodes.LALOAD:
		if (arrayNotSimulated) {
			return InsnValue.LONG_VALUE;
		}
		long[] la = (long[]) arrayObj;
		return InsnValue.longValue(la[index]);
	case Opcodes.FALOAD:
		if (arrayNotSimulated) {
			return InsnValue.FLOAT_VALUE;
		}
		float[] fa = (float[]) arrayObj;
		return InsnValue.floatValue(fa[index]);
	case Opcodes.DALOAD:
		if (arrayNotSimulated) {
			return InsnValue.DOUBLE_VALUE;
		}
		double[] da = (double[]) arrayObj;
		return InsnValue.doubleValue(da[index]);
	case Opcodes.AALOAD:
		// TODO: Check if it's an object array, but the contents aren't objects
		return InsnValue.REFERENCE_VALUE;
	case Opcodes.BALOAD:
		if (arrayNotSimulated) {
			return InsnValue.BYTE_VALUE;
		}
		boolean db = t.equals(InsnValue.DOUBLE_ARR_VALUE.getType()), in = t.equals(InsnValue.INT_ARR_VALUE.getType()), saa = t.equals(InsnValue.SHORT_ARR_VALUE.getType());
		if (db) {
			double[] dba = (double[]) arrayObj;
			return InsnValue.intValue(dba[index]);
		} else if (in) {
			int[] ina = (int[]) arrayObj;
			return InsnValue.intValue(ina[index]);
		} else if (saa){
			short[] saaa = (short[]) arrayObj;
			return InsnValue.intValue(saaa[index]);
		} else {
			System.err.println("UNKNOWN TYPE BALOAD: " + t);
			throw new RuntimeException();
		}

	case Opcodes.CALOAD:
		if (arrayNotSimulated) {
			return InsnValue.CHAR_VALUE;
		}
		char[] ca = (char[]) arrayObj;
		return InsnValue.charValue(ca[index]);
	case Opcodes.SALOAD:
		if (arrayNotSimulated) {
			return InsnValue.SHORT_VALUE;
		}
		short[] sa = (short[]) arrayObj;
		return InsnValue.intValue((short) sa[index]);
	}

	return null;
}
 
Example 5
Source File: ArrayLoadExpression.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static int tryReduce(List<Instruction> instructions, int index) {
    Instruction instr = instructions.get(index);
    switch (instr.getOpcode()) {
        case Opcodes.AALOAD:
        case Opcodes.FALOAD:
        case Opcodes.CALOAD:
        case Opcodes.DALOAD:
        case Opcodes.BALOAD:
        case Opcodes.IALOAD:
        case Opcodes.LALOAD:
        case Opcodes.SALOAD:
            break;
        default:
            return -1;
    }
    
    if (index < 2) {
        return -1;
    }
    
    Instruction indexInstr = instructions.get(index-1);
    if (!(indexInstr instanceof AssignableExpression)) {
        return -1;
    }
    
    Instruction arrInstr = instructions.get(index-2);
    if (!(arrInstr instanceof AssignableExpression)) {
        return -1;
    }
    
    ArrayLoadExpression out = new ArrayLoadExpression();
    out.loadInstruction = instr;
    out.indexInstruction = indexInstr;
    out.targetArrayInstruction = arrInstr;
    
    instructions.remove(index-2);
    instructions.remove(index-2);
    instructions.remove(index-2);
    instructions.add(index-2, out);
    return index-2;
}