Example usage for org.objectweb.asm Opcodes POP

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

Introduction

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

Prototype

int POP

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

Click Source Link

Usage

From source file:com.asakusafw.dag.compiler.codegen.ExtractInputAdapterGenerator.java

License:Apache License

/**
 * Generates {@link ExtractInputAdapter} class.
 * @param context the current context/*w  w w.jav a2  s.  c  o m*/
 * @param input the target input spec
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, Spec input, ClassDescription target) {
    ClassWriter writer = newWriter(target, ExtractInputAdapter.class);
    defineAdapterConstructor(writer, ExtractInputAdapter.class, v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        getConst(v, input.id);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                Type.getMethodDescriptor(typeOf(ExtractInputAdapter.class), typeOf(String.class)), false);
        v.visitInsn(Opcodes.POP);
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.codegen.KeyValueSerDeGenerator.java

License:Apache License

private static void putDeserializeBody(MethodVisitor v, List<PropertyReference> props, LocalVarRef input,
        LocalVarRef object) {//from  w  w w.  j  a v  a2 s . c  om
    if (props.isEmpty()) {
        input.load(v);
        v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(DataInput.class).getInternalName(), "readByte",
                Type.getMethodDescriptor(Type.BYTE_TYPE), true);
        v.visitInsn(Opcodes.POP);
    } else {
        for (PropertyReference property : props) {
            object.load(v);
            getOption(v, property);
            input.load(v);
            v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "deserialize", Type
                    .getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataInput.class)),
                    false);
        }
    }
}

From source file:com.asakusafw.dag.compiler.codegen.OperationAdapterGenerator.java

License:Apache License

/**
 * Generates {@link OperationAdapter} class.
 * @param context the current context/*ww w .  jav  a2 s  . co  m*/
 * @param operation the target operation
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, OperationSpec operation, ClassDescription target) {
    ClassDescription inner = addInner(context, operation, target);
    ClassWriter writer = newWriter(target, BasicOperationAdapter.class);
    defineAdapterConstructor(writer, BasicOperationAdapter.class, v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        getConst(v, inner);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind",
                Type.getMethodDescriptor(typeOf(BasicOperationAdapter.class), typeOf(Class.class)), false);
        v.visitInsn(Opcodes.POP);
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.codegen.UnionRecordSerDeSupplierGenerator.java

License:Apache License

/**
 * Generates {@link UnionRecordSerDeSupplier} class.
 * @param context the current context//  w  ww  .ja va  2 s. co  m
 * @param upstreams the upstream specifications
 * @param downstream the downstream specification
 * @param target the target class
 * @return the generated class data
 */
public static ClassData generate(ClassGeneratorContext context, List<Upstream> upstreams, Downstream downstream,
        ClassDescription target) {
    Arguments.requireNonNull(context);
    Arguments.requireNonNull(upstreams);
    Arguments.requireNonNull(downstream);
    ClassWriter writer = newWriter(target, UnionRecordSerDeSupplier.class);
    defineEmptyConstructor(writer, UnionRecordSerDeSupplier.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        self.load(v);
        upstreams.forEach(s -> {
            // this.upstream(tags, elementSerDe)
            getList(v, s.tags);
            getConst(v, s.element);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(UnionRecordSerDeSupplier.class).getInternalName(),
                    "upstream", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(UnionRecordSerDeSupplier.class), typeOf(Collection.class),
                            typeOf(Class.class)),
                    false);
        });
        downstream.tags.forEach(s -> {
            // this.downstream(tag)
            getConst(v, s);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(UnionRecordSerDeSupplier.class).getInternalName(),
                    "downstream", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(UnionRecordSerDeSupplier.class), typeOf(String.class)),
                    false);
        });
        v.visitInsn(Opcodes.POP);
    });
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.codegen.VertexAdapterGenerator.java

License:Apache License

private static void putConf(MethodVisitor method, ClassDescription target, LocalVarRef self,
        ClassDescription value, String name) {
    self.load(method);//from  w w  w  . j av  a2s  . com
    getConst(method, value);
    method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), name,
            Type.getMethodDescriptor(typeOf(VertexAdapter.class), typeOf(Class.class)), false);
    method.visitInsn(Opcodes.POP);
}

From source file:com.asakusafw.dag.compiler.directio.DirectFileInputAdapterGenerator.java

License:Apache License

/**
 * Generates {@link DirectFileInputAdapter} class.
 * @param context the current context// ww w  . j a va 2 s  .  com
 * @param input the target input spec
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, Spec input, ClassDescription target) {
    ClassWriter writer = newWriter(target, DirectFileInputAdapter.class);
    defineAdapterConstructor(writer, DirectFileInputAdapter.class, v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        getConst(v, input.id);
        getConst(v, input.basePath);
        getConst(v, input.resourcePattern);
        getConst(v, input.dataFormat);
        getConst(v, input.dataFilter);
        getConst(v, input.optional);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                Type.getMethodDescriptor(typeOf(DirectFileInputAdapter.class), typeOf(String.class),
                        typeOf(String.class), typeOf(String.class), typeOf(Class.class), typeOf(Class.class),
                        typeOf(boolean.class)),
                false);
        v.visitInsn(Opcodes.POP);
    });
    writer.visitEnd();
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.directio.DirectFileOutputCommitGenerator.java

License:Apache License

/**
 * Generates {@link DirectFileOutputCommit} class.
 * @param context the current context//from  w ww. jav  a  2 s  .  c o  m
 * @param specs the binding specs
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) {
    ClassWriter writer = newWriter(target, DirectFileOutputCommit.class);
    defineEmptyConstructor(writer, DirectFileOutputCommit.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        for (Spec spec : specs) {
            self.load(v);
            getConst(v, spec.id);
            getConst(v, spec.basePath);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(DirectFileOutputCommit.class), typeOf(String.class),
                            typeOf(String.class)),
                    false);
            v.visitInsn(Opcodes.POP);
        }
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.directio.DirectFileOutputPrepareGenerator.java

License:Apache License

/**
 * Generates {@link DirectFileOutputPrepare} class.
 * @param context the current context// w w w . j  a  v  a2s  .  c  om
 * @param specs the binding specs
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) {
    ClassWriter writer = newWriter(target, DirectFileOutputPrepare.class);
    defineEmptyConstructor(writer, DirectFileOutputPrepare.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        for (Spec spec : specs) {
            self.load(v);
            getConst(v, spec.id);
            getConst(v, spec.basePath);
            getConst(v, spec.outputPattern);
            getConst(v, spec.formatType);
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(DirectFileOutputPrepare.class), typeOf(String.class),
                            typeOf(String.class), typeOf(String.class), typeOf(Class.class)),
                    false);
            v.visitInsn(Opcodes.POP);
        }
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.directio.DirectFileOutputSetupGenerator.java

License:Apache License

/**
 * Generates {@link DirectFileOutputSetup} class.
 * @param context the current context/*from www  .  j a va 2s  .  c o m*/
 * @param specs the binding specs
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, List<Spec> specs, ClassDescription target) {
    ClassWriter writer = newWriter(target, DirectFileOutputSetup.class);
    defineEmptyConstructor(writer, DirectFileOutputSetup.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        for (Spec spec : specs) {
            self.load(v);
            getConst(v, spec.id);
            getConst(v, spec.basePath);
            getArray(v, spec.deletePatterns.stream().toArray(String[]::new));
            v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                    Type.getMethodDescriptor(typeOf(DirectFileOutputSetup.class), typeOf(String.class),
                            typeOf(String.class), typeOf(String[].class)),
                    false);
            v.visitInsn(Opcodes.POP);
        }
    });
    return new ClassData(target, writer::toByteArray);
}

From source file:com.asakusafw.dag.compiler.directio.OutputPatternSerDeGenerator.java

License:Apache License

private static void putCtor(ClassWriter writer, DataModelReference reference, FieldRef buffer,
        OutputPattern pattern, ClassDescription target) {
    defineEmptyConstructor(writer, OutputPatternSerDe.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        self.load(v);//from  w w  w .  j av  a 2  s  . com
        getNew(v, reference.getDeclaration());
        putField(v, buffer);

        for (CompiledSegment segment : pattern.getResourcePattern()) {
            self.load(v);
            switch (segment.getKind()) {
            case NOTHING:
                getConst(v, segment.getArgument());
                v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "text", //$NON-NLS-1$
                        Type.getMethodDescriptor(typeOf(OutputPatternSerDe.class), typeOf(String.class)),
                        false);
                break;
            case PROPERTY:
                switch (segment.getFormat()) {
                case NATURAL:
                    getEnumConstant(v, OutputPatternSerDe.Format.NATURAL);
                    break;
                case BYTE:
                    getEnumConstant(v, OutputPatternSerDe.Format.BYTE);
                    break;
                case SHORT:
                    getEnumConstant(v, OutputPatternSerDe.Format.SHORT);
                    break;
                case INT:
                    getEnumConstant(v, OutputPatternSerDe.Format.INT);
                    break;
                case LONG:
                    getEnumConstant(v, OutputPatternSerDe.Format.LONG);
                    break;
                case FLOAT:
                    getEnumConstant(v, OutputPatternSerDe.Format.FLOAT);
                    break;
                case DOUBLE:
                    getEnumConstant(v, OutputPatternSerDe.Format.DOUBLE);
                    break;
                case DECIMAL:
                    getEnumConstant(v, OutputPatternSerDe.Format.DECIMAL);
                    break;
                case DATE:
                    getEnumConstant(v, OutputPatternSerDe.Format.DATE);
                    break;
                case DATETIME:
                    getEnumConstant(v, OutputPatternSerDe.Format.DATETIME);
                    break;
                default:
                    throw new AssertionError(pattern.getResourcePatternString());
                }
                getConst(v, segment.getArgument());
                v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "property", //$NON-NLS-1$
                        Type.getMethodDescriptor(typeOf(OutputPatternSerDe.class),
                                typeOf(OutputPatternSerDe.Format.class), typeOf(String.class)),
                        false);
                break;
            case RANDOM:
                getInt(v, segment.getRandomNumber().getLowerBound());
                getInt(v, segment.getRandomNumber().getUpperBound());
                v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "random", //$NON-NLS-1$
                        Type.getMethodDescriptor(typeOf(OutputPatternSerDe.class), typeOf(int.class),
                                typeOf(int.class)),
                        false);
                break;
            default:
                throw new AssertionError(pattern.getResourcePatternString());
            }
            v.visitInsn(Opcodes.POP);
        }
    });
}