List of usage examples for org.objectweb.asm Opcodes ILOAD
int ILOAD
To view the source code for org.objectweb.asm Opcodes ILOAD.
Click Source Link
From source file:org.spongepowered.asm.util.Locals.java
License:MIT License
/** * Injects appropriate LOAD opcodes into the supplied InsnList for each * entry in the supplied locals array starting at pos * //w w w. jav a2 s. co m * @param locals Local types (can contain nulls for uninitialised, TOP, or * RETURN values in locals) * @param insns Instruction List to inject into * @param pos Start position */ public static void loadLocals(Type[] locals, InsnList insns, int pos) { for (; pos < locals.length; pos++) { if (locals[pos] != null) { insns.add(new VarInsnNode(locals[pos].getOpcode(Opcodes.ILOAD), pos)); } } }
From source file:org.spongepowered.despector.emitter.bytecode.instruction.BytecodeLocalAccessEmitter.java
License:Open Source License
@Override public void emit(BytecodeEmitterContext ctx, LocalAccess arg, TypeSignature t) { MethodVisitor mv = ctx.getMethodVisitor(); TypeSignature type = arg.getLocal().getType(); if (type == ClassTypeSignature.INT || type == ClassTypeSignature.BOOLEAN || type == ClassTypeSignature.BYTE || type == ClassTypeSignature.SHORT || type == ClassTypeSignature.CHAR) { mv.visitVarInsn(Opcodes.ILOAD, arg.getLocal().getIndex()); } else if (type == ClassTypeSignature.LONG) { mv.visitVarInsn(Opcodes.LLOAD, arg.getLocal().getIndex()); } else if (type == ClassTypeSignature.FLOAT) { mv.visitVarInsn(Opcodes.FLOAD, arg.getLocal().getIndex()); } else if (type == ClassTypeSignature.DOUBLE) { mv.visitVarInsn(Opcodes.DLOAD, arg.getLocal().getIndex()); } else {/*from w w w .j a v a 2s . c o m*/ mv.visitVarInsn(Opcodes.ALOAD, arg.getLocal().getIndex()); } ctx.updateStack(1); }
From source file:org.spongepowered.eventimplgen.factory.ClassGenerator.java
License:MIT License
private void generateConstructor(ClassWriter classWriter, String internalName, CtTypeReference<?> parentType, List<Property> properties) { List<? extends Property> requiredProperties = getRequiredProperties(properties); StringBuilder builder = new StringBuilder(); builder.append("("); for (Property property : requiredProperties) { builder.append(getTypeDescriptor(property.getType())); }//from www . j a v a 2 s . c om builder.append(")V"); String methodDesc = builder.toString(); MethodVisitor mv = classWriter.visitMethod(0, "<init>", methodDesc, null, null); mv.visitCode(); // super() mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, ClassGenerator.getInternalName(parentType.getQualifiedName()), "<init>", "()V", false); // 0 is 'this', parameters start at 1 for (int i = 0, paramIndex = 1; i < requiredProperties.size(); i++, paramIndex++) { Property property = requiredProperties.get(i); Type type = Type.getType(getTypeDescriptor(property.getType())); int loadOpcode = type.getOpcode(Opcodes.ILOAD); boolean isPrimitive = property.getType().isPrimitive(); // Only if we have a null policy: // if (value == null) throw new NullPointerException(...) if (this.nullPolicy != NullPolicy.DISABLE_PRECONDITIONS) { boolean useNullTest = !isPrimitive && (((this.nullPolicy == NullPolicy.NON_NULL_BY_DEFAULT && !this.hasNullable(property.getAccessor())) || (this.nullPolicy == NullPolicy.NULL_BY_DEFAULT && this.hasNonnull(property.getAccessor()))) && isRequired(property)); if (useNullTest) { Label afterNullTest = new Label(); mv.visitVarInsn(loadOpcode, paramIndex); mv.visitJumpInsn(IFNONNULL, afterNullTest); mv.visitTypeInsn(NEW, "java/lang/NullPointerException"); mv.visitInsn(DUP); mv.visitLdcInsn("The property '" + property.getName() + "' was not provided!"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NullPointerException", "<init>", "(Ljava/lang/String;)V", false); mv.visitInsn(ATHROW); mv.visitLabel(afterNullTest); } } final boolean hasUseField = getUseField(parentType, property.getName()) != null; // stack: -> this mv.visitVarInsn(ALOAD, 0); // ProperObject newValue = (ProperObject) value mv.visitVarInsn(loadOpcode, paramIndex); //visitUnboxingMethod(mv, Type.getType(property.getType())); // this.field = newValue String desc = getTypeDescriptor(property.getLeastSpecificType()); if (hasUseField) { mv.visitFieldInsn(PUTFIELD, getInternalName(parentType.getQualifiedName()), property.getName(), desc); } else { mv.visitFieldInsn(PUTFIELD, internalName, property.getName(), desc); } // } if (type.equals(Type.LONG_TYPE) || type.equals(Type.DOUBLE_TYPE)) { paramIndex++; // Skip empty slot } } // super.init(); if (hasDeclaredMethod(parentType, "init")) { mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, getInternalName(parentType.getQualifiedName()), "init", "()V", false); } mv.visitInsn(RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.spongepowered.eventimplgen.factory.FactoryInterfaceGenerator.java
License:MIT License
private static void generateRealImpl(ClassWriter cw, CtType<?> event, String eventName, List<Property> params) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, EventImplGenTask.generateMethodName(event), getDescriptor(event, params), null, null); Label start = new Label(); Label end = new Label(); mv.visitCode();/*from ww w . java2 s. c om*/ mv.visitLabel(start); mv.visitTypeInsn(NEW, eventName); mv.visitInsn(DUP); int[] slots = new int[params.size()]; for (int i = 0, slot = 0; i < params.size(); i++, slot++) { Property param = params.get(i); slots[i] = slot; Type type = Type.getType(ClassGenerator.getTypeDescriptor(param.getType())); mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), slot); // Parameters start at slot 0 for static methods if (type.getSize() > 1) { slot++; // Skip over unusable following slot } } mv.visitMethodInsn(INVOKESPECIAL, eventName, "<init>", getDescriptor(null, params), false); mv.visitInsn(ARETURN); mv.visitLabel(end); for (int i = 0; i < params.size(); i++) { Property property = params.get(i); mv.visitLocalVariable(property.getName(), ClassGenerator.getTypeDescriptor(property.getType()), null, start, end, slots[i]); mv.visitParameter(property.getName(), 0); } mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:org.spongepowered.mod.asm.transformers.EventTransformer.java
License:MIT License
protected static MethodNode createSetCancelledMethod() { MethodNode methodNode = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC, "setCancelled", "(Z)V", null, null);//w w w. j av a 2 s . c o m methodNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); methodNode.instructions.add(new VarInsnNode(Opcodes.ILOAD, 1)); methodNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "net/minecraftforge/fml/common/eventhandler/Event", "setCanceled", "(Z)V", false)); methodNode.instructions.add(new InsnNode(Opcodes.RETURN)); methodNode.maxLocals = 1; methodNode.maxStack = 1; return methodNode; }
From source file:org.springsource.loaded.test.infra.MethodPrinter.java
License:Apache License
public void visitVarInsn(int opcode, int var) { if (opcode == Opcodes.ALOAD) { to.println(" ALOAD " + var); } else if (opcode == Opcodes.ASTORE) { to.println(" ASTORE " + var); } else if (opcode == Opcodes.ILOAD) { to.println(" ILOAD " + var); } else if (opcode == FLOAD) { to.println(" FLOAD " + var); } else if (opcode == LLOAD) { to.println(" LLOAD " + var); } else if (opcode == DLOAD) { to.println(" DLOAD " + var); } else if (opcode == ISTORE) { to.println(" ISTORE " + var); } else if (opcode == LSTORE) { to.println(" LSTORE " + var); } else {//from ww w . ja v a 2 s .c om throw new IllegalStateException(":" + opcode); } }
From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java
License:Apache License
private void buildEndMethod(ClassVisitor cv, String className, Dfa dfa) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "end", "()" + Type.getDescriptor(Matcher.class), null, null);/*w w w. j ava2 s .c o m*/ stateLabels = new Label[dfa.getStates().size()]; Arrays.setAll(stateLabels, i -> new Label()); int[] keys = new int[dfa.getStates().size()]; Arrays.setAll(keys, IntUnaryOperator.identity()); saveLabel = new Label(); errorLabel = new Label(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I"); mv.visitLookupSwitchInsn(errorLabel, keys, stateLabels); for (int i = 0; i < dfa.getStates().size(); ++i) { mv.visitLabel(stateLabels[i]); DfaTransition transition = dfa.getStates().get(i).getTransition(-1); if (transition == null) { mv.visitJumpInsn(Opcodes.GOTO, errorLabel); } else { DfaState target = transition.getTarget(); mv.visitIntInsn(Opcodes.SIPUSH, transition.getTarget().getIndex()); mv.visitVarInsn(Opcodes.ISTORE, 1); mv.visitIntInsn(Opcodes.SIPUSH, !target.isTerminal() ? -1 : target.getDomains()[0]); mv.visitVarInsn(Opcodes.ISTORE, 2); debug(mv, "DFA: " + i + " .-> " + target.getIndex() + " " + Arrays.toString(target.getDomains())); mv.visitJumpInsn(Opcodes.GOTO, saveLabel); } } mv.visitLabel(errorLabel); debug(mv, "DFA: error"); mv.visitInsn(Opcodes.ICONST_M1); mv.visitVarInsn(Opcodes.ISTORE, 1); mv.visitInsn(Opcodes.ICONST_M1); mv.visitVarInsn(Opcodes.ISTORE, 2); mv.visitLabel(saveLabel); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 1); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "state", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(3, 3); mv.visitEnd(); }
From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java
License:Apache License
private void buildWorkerMethod(ClassVisitor cv, String className, Dfa dfa) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "feed", "(Ljava/lang/String;IIZ)" + Type.getDescriptor(Matcher.class), null, null); mv.visitCode();//w ww.j a v a 2 s. c om mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I"); mv.visitVarInsn(Opcodes.ISTORE, 5); errorLabel = new Label(); saveLabel = new Label(); loopLabel = new Label(); continueLabel = new Label(); mv.visitLabel(loopLabel); generateLengthGuard(mv); stateLabels = new Label[dfa.getStates().size()]; Arrays.setAll(stateLabels, i -> new Label()); int[] keys = new int[dfa.getStates().size()]; Arrays.setAll(keys, IntUnaryOperator.identity()); mv.visitVarInsn(Opcodes.ILOAD, 5); mv.visitLookupSwitchInsn(errorLabel, keys, stateLabels); mv.visitLabel(continueLabel); mv.visitIincInsn(2, 1); mv.visitJumpInsn(Opcodes.GOTO, loopLabel); mv.visitLabel(errorLabel); debug(mv, "DFA: error"); mv.visitInsn(Opcodes.ICONST_M1); mv.visitVarInsn(Opcodes.ISTORE, 5); mv.visitLabel(saveLabel); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 5); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "state", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "index", "I"); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ARETURN); for (int i = 0; i < dfa.getStates().size(); ++i) { mv.visitLabel(stateLabels[i]); DfaState state = dfa.getStates().get(i); generateTransitions(state, mv); } mv.visitMaxs(3, 6); mv.visitEnd(); }
From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java
License:Apache License
private void generateLengthGuard(MethodVisitor mv) { mv.visitVarInsn(Opcodes.ILOAD, 3); mv.visitVarInsn(Opcodes.ILOAD, 2);/*from ww w. j ava 2 s .c om*/ mv.visitInsn(Opcodes.ISUB); mv.visitJumpInsn(Opcodes.IFLE, saveLabel); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ILOAD, 2); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "charAt", "(I)C", false); mv.visitVarInsn(Opcodes.ISTORE, 6); if (debugMode) { mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", Type.getDescriptor(PrintStream.class)); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("DFA <- "); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V", false); mv.visitInsn(Opcodes.DUP); mv.visitVarInsn(Opcodes.ILOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print", "(C)V", false); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "println", "()V", false); } }
From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java
License:Apache License
private void generateTransitions(DfaState source, MethodVisitor mv) { MapOfChars<DfaState> targets = getTransitions(source); MapOfChars<DfaState> rangeTargets = targets.clone(); List<Integer> keys = new ArrayList<>(); List<Label> labels = new ArrayList<>(); List<DfaState> singleTargets = new ArrayList<>(); for (MapOfCharsIterator<DfaState> iter = targets.iterate(); iter.hasValue(); iter.next()) { if (iter.getValue() == null) { continue; }/* w w w . ja v a 2s. co m*/ if (iter.getStart() + 1 == iter.getEnd()) { rangeTargets.fill(iter.getStart(), iter.getEnd(), null); keys.add(iter.getStart()); labels.add(new Label()); singleTargets.add(iter.getValue()); } } Label nonSingleChars = new Label(); if (!keys.isEmpty()) { mv.visitVarInsn(Opcodes.ILOAD, 6); mv.visitLookupSwitchInsn(nonSingleChars, keys.stream().mapToInt(Integer::intValue).toArray(), labels.toArray(new Label[0])); for (int i = 0; i < labels.size(); ++i) { mv.visitLabel(labels.get(i)); generateTransition(mv, source, singleTargets.get(i)); } } mv.visitLabel(nonSingleChars); generateBinaryMatcher(mv, source, rangeTargets); }