Search in sources :

Example 1 with Label

use of org.jetbrains.org.objectweb.asm.Label in project kotlin by JetBrains.

the class MethodInliner method prepareNode.

@NotNull
private MethodNode prepareNode(@NotNull MethodNode node, int finallyDeepShift) {
    final int capturedParamsSize = parameters.getCapturedParametersSizeOnStack();
    final int realParametersSize = parameters.getRealParametersSizeOnStack();
    Type[] types = Type.getArgumentTypes(node.desc);
    Type returnType = Type.getReturnType(node.desc);
    List<Type> capturedTypes = parameters.getCapturedTypes();
    Type[] allTypes = ArrayUtil.mergeArrays(types, capturedTypes.toArray(new Type[capturedTypes.size()]));
    node.instructions.resetLabels();
    MethodNode transformedNode = new MethodNode(InlineCodegenUtil.API, node.access, node.name, Type.getMethodDescriptor(returnType, allTypes), node.signature, null) {

        @SuppressWarnings("ConstantConditions")
        private final boolean GENERATE_DEBUG_INFO = InlineCodegenUtil.GENERATE_SMAP && inlineOnlySmapSkipper == null;

        private final boolean isInliningLambda = nodeRemapper.isInsideInliningLambda();

        private int getNewIndex(int var) {
            return var + (var < realParametersSize ? 0 : capturedParamsSize);
        }

        @Override
        public void visitVarInsn(int opcode, int var) {
            super.visitVarInsn(opcode, getNewIndex(var));
        }

        @Override
        public void visitIincInsn(int var, int increment) {
            super.visitIincInsn(getNewIndex(var), increment);
        }

        @Override
        public void visitMaxs(int maxStack, int maxLocals) {
            super.visitMaxs(maxStack, maxLocals + capturedParamsSize);
        }

        @Override
        public void visitLineNumber(int line, @NotNull Label start) {
            if (isInliningLambda || GENERATE_DEBUG_INFO) {
                super.visitLineNumber(line, start);
            }
        }

        @Override
        public void visitLocalVariable(@NotNull String name, @NotNull String desc, String signature, @NotNull Label start, @NotNull Label end, int index) {
            if (isInliningLambda || GENERATE_DEBUG_INFO) {
                String varSuffix = inliningContext.isRoot() && !InlineCodegenUtil.isFakeLocalVariableForInline(name) ? INLINE_FUN_VAR_SUFFIX : "";
                String varName = !varSuffix.isEmpty() && name.equals("this") ? name + "_" : name;
                super.visitLocalVariable(varName + varSuffix, desc, signature, start, end, getNewIndex(index));
            }
        }
    };
    node.accept(transformedNode);
    transformCaptured(transformedNode);
    transformFinallyDeepIndex(transformedNode, finallyDeepShift);
    return transformedNode;
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) Label(org.jetbrains.org.objectweb.asm.Label) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Label

use of org.jetbrains.org.objectweb.asm.Label in project kotlin by JetBrains.

the class RedundantBoxingMethodTransformer method ifEqual1Else0.

private static void ifEqual1Else0(@NotNull MethodNode node, @NotNull AbstractInsnNode insn) {
    LabelNode lNotEqual = new LabelNode(new Label());
    LabelNode lDone = new LabelNode(new Label());
    node.instructions.insertBefore(insn, new JumpInsnNode(Opcodes.IFNE, lNotEqual));
    node.instructions.insertBefore(insn, new InsnNode(Opcodes.ICONST_1));
    node.instructions.insertBefore(insn, new JumpInsnNode(Opcodes.GOTO, lDone));
    node.instructions.insertBefore(insn, lNotEqual);
    node.instructions.insertBefore(insn, new InsnNode(Opcodes.ICONST_0));
    node.instructions.insertBefore(insn, lDone);
}
Also used : Label(org.jetbrains.org.objectweb.asm.Label)

Example 3 with Label

use of org.jetbrains.org.objectweb.asm.Label in project kotlin by JetBrains.

the class SwitchCodegen method generateEntries.

protected void generateEntries() {
    // resolving entries' entryLabels and generating entries' code
    Iterator<Label> entryLabelsIterator = entryLabels.iterator();
    for (KtWhenEntry entry : expression.getEntries()) {
        v.visitLabel(entryLabelsIterator.next());
        FrameMap.Mark mark = codegen.myFrameMap.mark();
        codegen.gen(entry.getExpression(), resultType);
        mark.dropTo();
        if (!entry.isElse()) {
            v.goTo(endLabel);
        }
    }
}
Also used : KtWhenEntry(org.jetbrains.kotlin.psi.KtWhenEntry) FrameMap(org.jetbrains.kotlin.codegen.FrameMap) Label(org.jetbrains.org.objectweb.asm.Label)

Example 4 with Label

use of org.jetbrains.org.objectweb.asm.Label in project kotlin by JetBrains.

the class ExpressionCodegen method markLineNumberAfterInlineIfNeeded.

//we should generate additional linenumber info after inline call only if it used as argument
public void markLineNumberAfterInlineIfNeeded() {
    if (!shouldMarkLineNumbers) {
        //if it used as general argument
        if (myLastLineNumber > -1) {
            Label label = new Label();
            v.visitLabel(label);
            v.visitLineNumber(myLastLineNumber, label);
        }
    } else {
        //if it used as argument of infix call (in this case lineNumber for simple inlineCall also would be reset)
        myLastLineNumber = -1;
    }
}
Also used : Label(org.jetbrains.org.objectweb.asm.Label)

Example 5 with Label

use of org.jetbrains.org.objectweb.asm.Label in project kotlin by JetBrains.

the class ExpressionCodegen method generateInPrimitiveRange.

/*
     * Translates x in a..b to a <= x && x <= b
     * and x !in a..b to a > x || x > b for any primitive type
     */
private void generateInPrimitiveRange(StackValue argument, KtBinaryExpression rangeExpression, boolean isInverted) {
    Type rangeType = argument.type;
    int localVarIndex = myFrameMap.enterTemp(rangeType);
    // Load left bound
    gen(rangeExpression.getLeft(), rangeType);
    // Load x into local variable to avoid StackValue#put side-effects
    argument.put(rangeType, v);
    v.store(localVarIndex, rangeType);
    v.load(localVarIndex, rangeType);
    // If (x < left) goto L1
    Label l1 = new Label();
    emitGreaterThan(rangeType, l1);
    // If (x > right) goto L1
    v.load(localVarIndex, rangeType);
    gen(rangeExpression.getRight(), rangeType);
    emitGreaterThan(rangeType, l1);
    Label l2 = new Label();
    v.iconst(isInverted ? 0 : 1);
    v.goTo(l2);
    v.mark(l1);
    v.iconst(isInverted ? 1 : 0);
    v.mark(l2);
    myFrameMap.leaveTemp(rangeType);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) Type(org.jetbrains.org.objectweb.asm.Type) KotlinType(org.jetbrains.kotlin.types.KotlinType) Label(org.jetbrains.org.objectweb.asm.Label)

Aggregations

Label (org.jetbrains.org.objectweb.asm.Label)33 Type (org.jetbrains.org.objectweb.asm.Type)12 KotlinType (org.jetbrains.kotlin.types.KotlinType)11 IElementType (com.intellij.psi.tree.IElementType)10 Unit (kotlin.Unit)6 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)5 NotNull (org.jetbrains.annotations.NotNull)4 Nullable (org.jetbrains.annotations.Nullable)4 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)3 SourcePosition (com.intellij.debugger.SourcePosition)2 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)2 DebuggerUtilsEx (com.intellij.debugger.impl.DebuggerUtilsEx)2 MethodBytecodeUtil (com.intellij.debugger.jdi.MethodBytecodeUtil)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2 Pair (com.intellij.openapi.util.Pair)2 com.intellij.psi (com.intellij.psi)2 List (java.util.List)2 Opcodes (org.jetbrains.org.objectweb.asm.Opcodes)2