Java Code Examples for org.objectweb.asm.Type#LONG_TYPE

The following examples show how to use org.objectweb.asm.Type#LONG_TYPE . 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: TypeUtils.java    From maple-ir with GNU General Public License v3.0 6 votes vote down vote up
public static Number rebox(Number cst, Type t) {
	if(t == Type.BYTE_TYPE) {
		return cst.byteValue();
	}  else if(t == Type.SHORT_TYPE) {
		return cst.shortValue();
	} else if(t == Type.INT_TYPE) {
		return cst.intValue();
	} else if(t == Type.LONG_TYPE) {
		return cst.longValue();
	} else if(t == Type.FLOAT_TYPE) {
		return cst.floatValue();
	} else if(t == Type.DOUBLE_TYPE) {
		return cst.doubleValue();
	} else {
		throw new UnsupportedOperationException(String.format("%s (%s) to %s", cst, cst.getClass(), t));
	}
}
 
Example 2
Source File: ComparisonExpr.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toCode(MethodVisitor visitor, BytecodeFrontend assembler) {
	left.toCode(visitor, assembler);
	right.toCode(visitor, assembler);

	if (left.getType() == Type.LONG_TYPE || right.getType() == Type.LONG_TYPE) {
		visitor.visitInsn(Opcodes.LCMP);
	} else if (left.getType() == Type.FLOAT_TYPE || right.getType() == Type.FLOAT_TYPE) {
		visitor.visitInsn(type == ValueComparisonType.GT ? Opcodes.FCMPG : Opcodes.FCMPL);
	} else if (left.getType() == Type.DOUBLE_TYPE || right.getType() == Type.DOUBLE_TYPE) {
		visitor.visitInsn(type == ValueComparisonType.GT ? Opcodes.DCMPG : Opcodes.DCMPL);
	} else {
		throw new IllegalArgumentException();
	}
}
 
Example 3
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getReturnOpcode(Type type) {
	if (type.getSort() >= Type.BOOLEAN && type.getSort() <= Type.INT) {
		return Opcodes.IRETURN;
	} else if (type == Type.LONG_TYPE) {
		return Opcodes.LRETURN;
	} else if (type == Type.FLOAT_TYPE) {
		return Opcodes.FRETURN;
	} else if (type == Type.DOUBLE_TYPE) {
		return Opcodes.DRETURN;
	} else if (type.getSort() >= Type.ARRAY && type.getSort() <= Type.OBJECT) {
		return Opcodes.ARETURN;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 4
Source File: LocalVariablesSorter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  Type varType;
  switch (opcode) {
    case Opcodes.LLOAD:
    case Opcodes.LSTORE:
      varType = Type.LONG_TYPE;
      break;
    case Opcodes.DLOAD:
    case Opcodes.DSTORE:
      varType = Type.DOUBLE_TYPE;
      break;
    case Opcodes.FLOAD:
    case Opcodes.FSTORE:
      varType = Type.FLOAT_TYPE;
      break;
    case Opcodes.ILOAD:
    case Opcodes.ISTORE:
      varType = Type.INT_TYPE;
      break;
    case Opcodes.ALOAD:
    case Opcodes.ASTORE:
    case Opcodes.RET:
      varType = OBJECT_TYPE;
      break;
    default:
      throw new IllegalArgumentException("Invalid opcode " + opcode);
  }
  super.visitVarInsn(opcode, remap(var, varType));
}
 
Example 5
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getDivideOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IDIV;
	} else if (type == Type.LONG_TYPE) {
		return LDIV;
	} else if (type == Type.FLOAT_TYPE) {
		return FDIV;
	} else if (type == Type.DOUBLE_TYPE) {
		return DDIV;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 6
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getMultiplyOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IMUL;
	} else if (type == Type.LONG_TYPE) {
		return LMUL;
	} else if (type == Type.FLOAT_TYPE) {
		return FMUL;
	} else if (type == Type.DOUBLE_TYPE) {
		return DMUL;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 7
Source File: ScottyMethodAdapter.java    From copper-engine with Apache License 2.0 5 votes vote down vote up
void pushLocals(StackInfo info) {
    super.visitIntInsn(SIPUSH, info.localsSize());
    super.visitTypeInsn(ANEWARRAY, "java/lang/Object");
    for (int i = 0; i < info.localsSize(); ++i) {
        Type t = info.getLocal(i);
        if (t != null) {
            super.visitInsn(DUP);
            super.visitIntInsn(SIPUSH, i);
            if (t == Type.BOOLEAN_TYPE || t == Type.BYTE_TYPE || t == Type.SHORT_TYPE || t == Type.INT_TYPE || t == Type.CHAR_TYPE) {
                super.visitVarInsn(ILOAD, i);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
            } else if (t == Type.FLOAT_TYPE) {
                super.visitVarInsn(FLOAD, i);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
            } else if (t == Type.LONG_TYPE) {
                super.visitVarInsn(LLOAD, i);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
            } else if (t == Type.DOUBLE_TYPE) {
                super.visitVarInsn(DLOAD, i);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
            } else if (t == StackInfo.AconstNullType) {
                super.visitInsn(ACONST_NULL);
            } else {
                super.visitVarInsn(ALOAD, i);
            }
            super.visitInsn(AASTORE);
        }
    }
}
 
Example 8
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getAddOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IADD;
	} else if (type == Type.LONG_TYPE) {
		return LADD;
	} else if (type == Type.FLOAT_TYPE) {
		return FADD;
	} else if (type == Type.DOUBLE_TYPE) {
		return DADD;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 9
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static Type resolveUnaryOpType(Type type) {
	if (type.getSort() >= Type.BOOLEAN && type.getSort() <= Type.INT) {
		return Type.INT_TYPE;
	} else if (type == Type.LONG_TYPE || type == Type.FLOAT_TYPE || type == Type.DOUBLE_TYPE) {
		return type;
	} else {
		throw new UnsupportedOperationException("Unsupported binop types: " + type);
	}
}
 
Example 10
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static int getBitShiftRightUnsignedOpcode(Type type) {
	if (type == Type.INT_TYPE) {
		return IUSHR;
	} else if (type == Type.LONG_TYPE) {
		return LUSHR;
	} else {
		throw new IllegalArgumentException(type.toString());
	}
}
 
Example 11
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static Type getCastType(int opcode) {
	switch (opcode) {
		case I2B:
			return Type.BYTE_TYPE;
		case I2C:
			return Type.CHAR_TYPE;
		case I2S:
			return Type.SHORT_TYPE;
		case L2I:
		case F2I:
		case D2I:
			return Type.INT_TYPE;
		case I2L:
		case F2L:
		case D2L:
			return Type.LONG_TYPE;
		case I2F:
		case L2F:
		case D2F:
			return Type.FLOAT_TYPE;
		case I2D:
		case L2D:
		case F2D:
			return Type.DOUBLE_TYPE;
		default:
			throw new IllegalArgumentException(Printer.OPCODES[opcode]);
	}
}
 
Example 12
Source File: TypeUtils.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public static Type getStoreType(int opcode) {
	if (opcode == ISTORE) {
		return Type.INT_TYPE;
	} else if (opcode == LSTORE) {
		return Type.LONG_TYPE;
	} else if (opcode == FSTORE) {
		return Type.FLOAT_TYPE;
	} else if (opcode == DSTORE) {
		return Type.DOUBLE_TYPE;
	} else if (opcode == ASTORE) {
		return OBJECT_TYPE;
	} else {
		throw new IllegalArgumentException(Printer.OPCODES[opcode]);
	}
}
 
Example 13
Source File: SerianalyzerMethodVisitor.java    From serianalyzer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param api
 */
@SuppressWarnings ( "javadoc" )
public SerianalyzerMethodVisitor ( SerianalyzerClassVisitorBase parent, MethodReference ref, DotName actualClass ) {
    super(Opcodes.ASM5);

    this.log = Verbose.getPerMethodLogger(ref);
    this.parent = parent;
    this.ref = ref;

    if ( this.log.isDebugEnabled() ) {
        this.log.debug("Method signature " + ref); //$NON-NLS-1$
        this.log.debug("Known callers are " + parent.getAnalyzer().getState().getMethodCallers().get(ref.comparable())); //$NON-NLS-1$
    }

    int i = 0;
    if ( !ref.isStatic() ) {
        Type t = ref.getTargetType();
        if ( t == null ) {
            t = Type.getObjectType(ref.getTypeNameString().replace('.', '/'));
        }
        if ( this.log.isDebugEnabled() ) {
            this.log.debug("Adding this with type " + t); //$NON-NLS-1$
        }
        this.stack.getVariable(i++).add(new FieldReference(actualClass, "this", t, ref.isCalleeTainted(), true)); //$NON-NLS-1$
    }
    else if ( this.log.isDebugEnabled() ) {
        this.log.debug("Static call"); //$NON-NLS-1$
    }

    Type[] argumentTypes = Type.getArgumentTypes(ref.getSignature());
    if ( ref.getArgumentTypes() != null && ref.getArgumentTypes().length == argumentTypes.length ) {
        argumentTypes = ref.getArgumentTypes();
    }
    else {
        this.log.debug("Do not have actual argument types " + ref.getArgumentTypes()); //$NON-NLS-1$
    }

    for ( int j = 0; j < argumentTypes.length; j++ ) {
        BasicVariable o = new BasicVariable(
            argumentTypes[ j ],
            "param" + j + ":" + argumentTypes[ j ], //$NON-NLS-1$ //$NON-NLS-2$
            ref.isParameterTainted(j),
            ref.isTaintParameterReturn(j));

        if ( argumentTypes[ j ] == Type.LONG_TYPE || argumentTypes[ j ] == Type.DOUBLE_TYPE ) {
            i++;
        }

        if ( this.log.isDebugEnabled() ) {
            this.log.debug("Adding parameter " + i + ": " + o); //$NON-NLS-1$ //$NON-NLS-2$
        }

        this.stack.getVariable(i++).add(o);
    }

}
 
Example 14
Source File: ConstantExpr.java    From maple-ir with GNU General Public License v3.0 4 votes vote down vote up
public static Type computeType(Object cst) {
		if (cst == null) {
			return Type.getType("Ljava/lang/Object;");
		} else if (cst instanceof Integer) {
			int val = ((Integer) cst).intValue();
			if (val >= Byte.MIN_VALUE && val <= Byte.MAX_VALUE) {
				return Type.BYTE_TYPE;
			} else if (val >= Short.MIN_VALUE && val <= Short.MAX_VALUE) {
				return Type.SHORT_TYPE;
			} else {
				return Type.INT_TYPE;
			}
//			return Type.INT_TYPE;
		} else if (cst instanceof Long) {
			return Type.LONG_TYPE;
		} else if (cst instanceof Float) {
			return Type.FLOAT_TYPE;
		} else if (cst instanceof Double) {
			return Type.DOUBLE_TYPE;
		} else if (cst instanceof String) {
			return Type.getType("Ljava/lang/String;");
		} else if (cst instanceof Type) {
			Type type = (Type) cst;
			if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
				return Type.getType("Ljava/lang/Class;");
			} else if (type.getSort() == Type.METHOD) {
				return Type.getType("Ljava/lang/invoke/MethodType;");
			} else {
				throw new RuntimeException("Invalid type: " + cst);
			}
		} else if (cst instanceof Handle) {
			return Type.getType("Ljava/lang/invoke/MethodHandle;");
		} else if (cst instanceof Boolean) {
			return Type.BOOLEAN_TYPE;
		} else if(cst instanceof Byte) {
			return Type.BYTE_TYPE;
		} else if (cst instanceof Character) {
			return Type.CHAR_TYPE;
		} else if(cst instanceof Short) {
			return Type.SHORT_TYPE;
		} else {
			throw new RuntimeException("Invalid type: " + cst);
		}
	}
 
Example 15
Source File: ABICompilerClassVisitor.java    From AVM with MIT License 4 votes vote down vote up
private void callTheDecoder(MethodVisitor methodVisitor, Type type) {
    if (type == Type.BYTE_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneByte", "()B", false);
    } else if (type == Type.BOOLEAN_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneBoolean", "()Z", false);
    } else if (type == Type.CHAR_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneCharacter", "()C", false);
    } else if (type == Type.SHORT_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneShort", "()S", false);
    } else if (type == Type.INT_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneInteger", "()I", false);
    } else if (type == Type.LONG_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneLong", "()J", false);
    } else if (type == Type.FLOAT_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneFloat", "()F", false);
    } else if (type == Type.DOUBLE_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneDouble", "()D", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.BYTE_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneByteArray", "()[B", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.BOOLEAN_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneBooleanArray", "()[Z", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.CHAR_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneCharacterArray", "()[C", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.SHORT_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneShortArray", "()[S", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.INT_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneIntegerArray", "()[I", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.LONG_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneLongArray", "()[J", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.FLOAT_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneFloatArray", "()[F", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.DOUBLE_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneDoubleArray", "()[D", false);
    } else if (isString(type)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneString", "()Ljava/lang/String;", false);
    } else if (isAddress(type)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneAddress", "()Lavm/Address;", false);
    } else if(isBigInteger(type)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneBigInteger", "()Ljava/math/BigInteger;", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.BYTE_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DByteArray", "()[[B", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.BOOLEAN_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DBooleanArray", "()[[Z", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.CHAR_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DCharacterArray", "()[[C", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.SHORT_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DShortArray", "()[[S", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.INT_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DIntegerArray", "()[[I", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.LONG_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DLongArray", "()[[J", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.FLOAT_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DFloatArray", "()[[F", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.DOUBLE_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DDoubleArray", "()[[D", false);
    } else if (type.getSort() == Type.ARRAY && type.getDimensions() == 1 && isString(type.getElementType())) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneStringArray", "()[Ljava/lang/String;", false);
    } else if (type.getSort() == Type.ARRAY && type.getDimensions() == 1 && isAddress(type.getElementType())) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneAddressArray", "()[Lavm/Address;", false);
    } else if(type.getSort() == Type.ARRAY && type.getDimensions() == 1 && isBigInteger(type.getElementType())) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneBigIntegerArray", "()[Ljava/math/BigInteger;", false);
    } else {
        throw new ABICompilerException("Need to decode an unsupported ABI type");
    }
}
 
Example 16
Source File: ScottyMethodAdapter.java    From copper-engine with Apache License 2.0 4 votes vote down vote up
void recreateLocals(StackInfo info) {
    if (info.localsSize() == 0)
        return;
    visitVarInsn(ALOAD, 0);
    visitFieldInsn(GETFIELD, currentClassName, "__stack", "Ljava/util/Stack;");
    visitVarInsn(ALOAD, 0);
    visitFieldInsn(GETFIELD, currentClassName, "__stackPosition", "I");
    visitMethodInsn(INVOKEVIRTUAL, "java/util/Stack", "get", "(I)Ljava/lang/Object;");
    visitTypeInsn(CHECKCAST, "org/copperengine/core/StackEntry");
    visitFieldInsn(GETFIELD, "org/copperengine/core/StackEntry", "locals", "[Ljava/lang/Object;");
    for (int i = 0; i < info.localsSize(); ++i) {
        Type t = info.getLocal(i);
        if (t != null) {
            if (t != StackInfo.AconstNullType) {
                super.visitInsn(DUP);
                super.visitIntInsn(SIPUSH, i);
                super.visitInsn(AALOAD);
            } else {
                super.visitInsn(ACONST_NULL);
            }
            if (t == Type.BOOLEAN_TYPE || t == Type.BYTE_TYPE || t == Type.SHORT_TYPE || t == Type.INT_TYPE || t == Type.CHAR_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Integer.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
                super.visitVarInsn(ISTORE, i);
            } else if (t == Type.FLOAT_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Float.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
                super.visitVarInsn(FSTORE, i);
            } else if (t == Type.LONG_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Long.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
                super.visitVarInsn(LSTORE, i);
            } else if (t == Type.DOUBLE_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Double.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
                super.visitVarInsn(DSTORE, i);
            } else {
                if (!t.getInternalName().equals(Type.getInternalName(Object.class)) && t != StackInfo.AconstNullType)
                    super.visitTypeInsn(CHECKCAST, t.getInternalName());
                super.visitVarInsn(ASTORE, i);
            }
        }
    }
    visitInsn(POP);
}
 
Example 17
Source File: BasicValue.java    From Concurnas with MIT License 4 votes vote down vote up
@Override
public int getSize() {
  return type == Type.LONG_TYPE || type == Type.DOUBLE_TYPE ? 2 : 1;
}
 
Example 18
Source File: InstructionAdapter.java    From Concurnas with MIT License 4 votes vote down vote up
/**
 * Generates the instruction to cast from the first given type to the other.
 *
 * @param methodVisitor the method visitor to use to generate the instruction.
 * @param from a Type.
 * @param to a Type.
 */
static void cast(final MethodVisitor methodVisitor, final Type from, final Type to) {
  if (from != to) {
    if (from == Type.DOUBLE_TYPE) {
      if (to == Type.FLOAT_TYPE) {
        methodVisitor.visitInsn(Opcodes.D2F);
      } else if (to == Type.LONG_TYPE) {
        methodVisitor.visitInsn(Opcodes.D2L);
      } else {
        methodVisitor.visitInsn(Opcodes.D2I);
        cast(methodVisitor, Type.INT_TYPE, to);
      }
    } else if (from == Type.FLOAT_TYPE) {
      if (to == Type.DOUBLE_TYPE) {
        methodVisitor.visitInsn(Opcodes.F2D);
      } else if (to == Type.LONG_TYPE) {
        methodVisitor.visitInsn(Opcodes.F2L);
      } else {
        methodVisitor.visitInsn(Opcodes.F2I);
        cast(methodVisitor, Type.INT_TYPE, to);
      }
    } else if (from == Type.LONG_TYPE) {
      if (to == Type.DOUBLE_TYPE) {
        methodVisitor.visitInsn(Opcodes.L2D);
      } else if (to == Type.FLOAT_TYPE) {
        methodVisitor.visitInsn(Opcodes.L2F);
      } else {
        methodVisitor.visitInsn(Opcodes.L2I);
        cast(methodVisitor, Type.INT_TYPE, to);
      }
    } else {
      if (to == Type.BYTE_TYPE) {
        methodVisitor.visitInsn(Opcodes.I2B);
      } else if (to == Type.CHAR_TYPE) {
        methodVisitor.visitInsn(Opcodes.I2C);
      } else if (to == Type.DOUBLE_TYPE) {
        methodVisitor.visitInsn(Opcodes.I2D);
      } else if (to == Type.FLOAT_TYPE) {
        methodVisitor.visitInsn(Opcodes.I2F);
      } else if (to == Type.LONG_TYPE) {
        methodVisitor.visitInsn(Opcodes.I2L);
      } else if (to == Type.SHORT_TYPE) {
        methodVisitor.visitInsn(Opcodes.I2S);
      }
    }
  }
}
 
Example 19
Source File: ReflectiveFunctorFactory.java    From maple-ir with GNU General Public License v3.0 4 votes vote down vote up
@Override
public EvaluationFunctor<Boolean> branch(Type lt, Type rt, ConditionalJumpStmt.ComparisonType type) {
	Type opType = TypeUtils.resolveBinOpType(lt, rt);
	String name = lt.getClassName() + type.name() + rt.getClassName() + "OPTYPE" + opType.getClassName() + "RETbool";

	String desc = "(" + lt.getDescriptor() + rt.getDescriptor() + ")Z";

	if(cache.containsKey(name)) {
		return _get(name);
	}

	MethodNode m = makeBase(name, desc);
	{
		InsnList insns = new InsnList();
		
		insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(lt), 0));
		cast(insns, lt, opType);
		insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(rt), lt.getSize()));
		cast(insns, rt, opType);
		

		LabelNode trueSuccessor = new LabelNode();
		
		if (opType == Type.INT_TYPE) {
			insns.add(new JumpInsnNode(Opcodes.IF_ICMPEQ + type.ordinal(), trueSuccessor));
		} else if (opType == Type.LONG_TYPE) {
			insns.add(new InsnNode(Opcodes.LCMP));
			insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
		} else if (opType == Type.FLOAT_TYPE) {
			insns.add(new InsnNode((type == ConditionalJumpStmt.ComparisonType.LT || type == ConditionalJumpStmt.ComparisonType.LE) ? Opcodes.FCMPL : Opcodes.FCMPG));
			insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
		} else if (opType == Type.DOUBLE_TYPE) {
			insns.add(new InsnNode((type == ConditionalJumpStmt.ComparisonType.LT || type == ConditionalJumpStmt.ComparisonType.LE) ? Opcodes.DCMPL : Opcodes.DCMPG));
			insns.add(new JumpInsnNode(Opcodes.IFEQ + type.ordinal(), trueSuccessor));
		} else {
			throw new IllegalArgumentException(opType.toString());
		}
		
		branchReturn(insns, trueSuccessor);
		
		m.node.instructions = insns;
	}
	
	return buildBridge(m);
}
 
Example 20
Source File: ConstantValue.java    From radon with GNU General Public License v3.0 4 votes vote down vote up
public static ConstantValue fromLong(AbstractInsnNode insnNode, long value) {
    return new ConstantValue(insnNode, Type.LONG_TYPE, value);
}