Example usage for org.objectweb.asm Opcodes ALOAD

List of usage examples for org.objectweb.asm Opcodes ALOAD

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ALOAD.

Prototype

int ALOAD

To view the source code for org.objectweb.asm Opcodes ALOAD.

Click Source Link

Usage

From source file:com.hea3ven.hardmodetweaks.core.ClassTransformerHardModeTweaks.java

License:Open Source License

private MethodNode createNewGetWorldTimeMethod(String methodName, boolean obfuscated) {
    // > long getWorldTime() {
    // >     return TimeTweaksManager.getWorldTime(this);
    // > }/* w ww .ja  v a  2 s. co m*/
    MethodNode getWorldTimeMethod = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC, methodName, "()J", null,
            null);
    getWorldTimeMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    getWorldTimeMethod.instructions
            .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/hea3ven/hardmodetweaks/TimeTweaksManager",
                    "getWorldTime", "(L" + WORLD_INFO.getPath(obfuscated) + ";)J"));
    getWorldTimeMethod.instructions.add(new InsnNode(Opcodes.LRETURN));
    return getWorldTimeMethod;
}

From source file:com.hea3ven.hardmodetweaks.core.ClassTransformerHardModeTweaks.java

License:Open Source License

private MethodNode createNewSetWorldTimeMethod(String methodName, boolean obfuscated) {
    // > void setWorldTime(long time) {
    // >     TimeTweaksManager.setWorldTime(this, time);
    // > }//from   www  . ja va2s.  c  om
    MethodNode setWorldTimeMethod = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC, methodName, "(J)V", null,
            null);
    setWorldTimeMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setWorldTimeMethod.instructions.add(new VarInsnNode(Opcodes.LLOAD, 1));
    setWorldTimeMethod.instructions
            .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/hea3ven/hardmodetweaks/TimeTweaksManager",
                    "setWorldTime", "(L" + WORLD_INFO.getPath(obfuscated) + ";J)V"));
    setWorldTimeMethod.instructions.add(new InsnNode(Opcodes.RETURN));
    return setWorldTimeMethod;
}

From source file:com.intellij.compiler.notNullVerification.ThrowOnNullMethodVisitor.java

License:Apache License

/**
 * Starts the visit of the method's code, if any (ie non abstract method).
 *///from   www  .  j a  v a2 s  .  c o  m
@Override
public void visitCode() {
    if (shouldInclude()) {
        if (!notNullParams.isEmpty()) {
            startGeneratedCodeLabel = new Label();
            mv.visitLabel(startGeneratedCodeLabel);
        }
        for (final Integer notNullParam : notNullParams) {
            int var = ((methodAccess & Opcodes.ACC_STATIC) == 0) ? 1 : 0;
            for (int i = 0; i < notNullParam + syntheticCount; ++i) {
                var += argumentTypes[i].getSize();
            }
            mv.visitVarInsn(Opcodes.ALOAD, var);

            final Label end = new Label();
            mv.visitJumpInsn(Opcodes.IFNONNULL, end);

            generateThrow(IAE_CLASS_NAME, getThrowMessage(notNullParam), end);
        }
    }
    mv.visitCode();
}

From source file:com.khubla.jvmbasic.jvmbasicc.compiler.RTLHelper.java

License:Open Source License

/**
 * push a value onto the Execution Context stack
 * <p>//w w  w .  j  a  v  a2s  .  c om
 * <code>
 * executionContext.push(db);
 * </code>
 * </p>
 */
public static void push(GenerationContext generationContext, double db) {
    generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
    generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
            EXECUTIONCONTEXT_NAME, JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
    generationContext.getMethodVisitor().visitLdcInsn(new Double(db));
    generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf",
            "(D)Ljava/lang/Double;");
    generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, JASIC_RUNTIME_EXECUTIONCONTEXT,
            "push", "(Ljava/lang/Double;)V");
}

From source file:com.khubla.jvmbasic.jvmbasicc.compiler.RTLHelper.java

License:Open Source License

/**
 * push a value onto the Execution Context stack
 * <p>//w  ww  .  j  a  va 2 s.  co m
 * <code>
 * executionContext.push(i);
 * </code>
 * </p>
 */
public static void push(GenerationContext generationContext, int i) {
    generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
    generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
            EXECUTIONCONTEXT_NAME, JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
    generationContext.getMethodVisitor().visitIntInsn(Opcodes.BIPUSH, i);
    generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf",
            "(I)Ljava/lang/Integer;");
    generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, JASIC_RUNTIME_EXECUTIONCONTEXT,
            "push", "(Ljava/lang/Integer;)V");
}

From source file:com.khubla.jvmbasic.jvmbasicc.compiler.RTLHelper.java

License:Open Source License

/**
 * push a value onto the Execution Context stack
 * <p>/*from  ww w  .  j  a  va2  s  .  c o m*/
 * <code>
 * executionContext.push(str);
 * </code>
 * </p>
 */
public static void push(GenerationContext generationContext, String str) {
    generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
    generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
            EXECUTIONCONTEXT_NAME, JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
    generationContext.getMethodVisitor().visitLdcInsn(str);
    generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, JASIC_RUNTIME_EXECUTIONCONTEXT,
            "push", "(Ljava/lang/String;)V");
}

From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.absfuncRule.java

License:Open Source License

@Override
public boolean execute(GenerationContext generationContext) throws Exception {
    try {//  w  w w .jav a2 s .c  o  m
        /*
         * get the argument
         */
        Dispatcher.dispatchChildren(generationContext);
        /*
         * pop the argument and apply abs
         */
        generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
        generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
                RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
        generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
        generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
                RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH,
                "ABS", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;");
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
        return true;
    } catch (final Exception e) {
        throw new Exception("Exception in execute", e);
    }
}

From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.addingExpressionRule.java

License:Open Source License

@Override
public boolean execute(GenerationContext generationContext) throws Exception {
    try {//from   w  w w.  ja v  a 2s.c  o m
        /*
         * get the operands
         */
        Dispatcher.dispatchChildren(generationContext);
        /*
         * if there are 3 values, we add them
         */
        if (generationContext.getParseTree().getChildCount() == 3) {
            /*
             * operation
             */
            final AddingExpressionContext addingExpressionContext = (AddingExpressionContext) generationContext
                    .getParseTree();
            final CommonToken commonToken = (CommonToken) addingExpressionContext.getChild(1).getPayload();
            if (commonToken.getType() == jvmBasicParser.PLUS) {
                /*
                 * add
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitInsn(Opcodes.DADD);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double",
                        "valueOf", "(D)Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
            } else {
                /*
                 * swap the stack arguments so we have the prompt on top and the variable name next
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "swap", "()V");
                /*
                 * subtract
                 */
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
                generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD,
                        generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop",
                        "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue",
                        "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double",
                        "doubleValue", "()D");
                generationContext.getMethodVisitor().visitInsn(Opcodes.DSUB);
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double",
                        "valueOf", "(D)Ljava/lang/Double;");
                generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                        RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
            }
            return true;
        } else {
            /**
             * do nothing
             */
            return true;
        }
    } catch (final Exception e) {
        throw new Exception("Exception in execute", e);
    }
}

From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.atnfuncRule.java

License:Open Source License

@Override
public boolean execute(GenerationContext generationContext) throws Exception {
    try {//  w w  w . j ava  2s . c om
        /*
         * get the argument
         */
        Dispatcher.dispatchChildren(generationContext);
        /*
         * pop the argument and apply abs
         */
        generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
        generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
                RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
        generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
        generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
                RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH,
                "ATAN", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;");
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
        return true;
    } catch (final Exception e) {
        throw new Exception("Exception in execute", e);
    }
}

From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.cosfuncRule.java

License:Open Source License

@Override
public boolean execute(GenerationContext generationContext) throws Exception {
    try {/*  www. j  av  a  2 s  . co  m*/
        /*
         * get the argument
         */
        Dispatcher.dispatchChildren(generationContext);
        /*
         * pop the argument and apply abs
         */
        generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
        generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
                RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
        generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0);
        generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(),
                RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE);
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;");
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH,
                "COS", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;");
        generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL,
                RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V");
        return true;
    } catch (final Exception e) {
        throw new Exception("Exception in execute", e);
    }
}