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.asakusafw.dag.compiler.codegen.ValueSerDeGenerator.java

License:Apache License

private static void putDeserialize(DataModelReference reference, FieldRef buffer, ClassWriter writer) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "deserialize",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(DataInput.class)), null,
            new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
    LocalVarRef input = new LocalVarRef(Opcodes.ALOAD, 1);

    self.load(v);/* w ww.j a v a2s  .  c  o  m*/
    getField(v, buffer);
    LocalVarRef object = putLocalVar(v, Type.OBJECT, 2);
    for (PropertyReference property : reference.getProperties()) {
        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);
    }
    object.load(v);
    v.visitInsn(Opcodes.ARETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

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

License:Apache License

/**
 * Generates {@link VertexAdapter} class.
 * @param context the current context//from   www .  j  a  va 2  s  .  co  m
 * @param inputAdapter the {@link InputAdapter} class
 * @param dataTableAdapters the {@link DataTableAdapter} classes
 * @param operationAdapter the {@link OperationAdapter} class
 * @param outputAdapters the {@link OutputAdapter} classes
 * @param label the vertex label
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, ClassDescription inputAdapter,
        List<ClassDescription> dataTableAdapters, ClassDescription operationAdapter,
        List<ClassDescription> outputAdapters, String label, ClassDescription target) {
    ClassWriter writer = newWriter(target, VertexAdapter.class);
    defineEmptyConstructor(writer, VertexAdapter.class, v -> {
        LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
        putConf(v, target, self, inputAdapter, "input"); //$NON-NLS-1$
        for (ClassDescription dataTableAdapter : dataTableAdapters) {
            putConf(v, target, self, dataTableAdapter, "dataTable"); //$NON-NLS-1$
        }
        putConf(v, target, self, operationAdapter, "operation"); //$NON-NLS-1$
        for (ClassDescription outputAdapter : outputAdapters) {
            putConf(v, target, self, outputAdapter, "output"); //$NON-NLS-1$
        }
    });
    if (label != null) {
        defineToString(writer, label);
    }
    return new ClassData(target, writer::toByteArray);
}

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

License:Apache License

/**
 * Generates {@link DirectFileInputAdapter} class.
 * @param context the current context/*from ww w  . j a v  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, 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//w w  w  .  j a v  a2  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 av  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, 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/*  w  w w .  j a  v  a 2 s .co  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 2s  . 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);
        }
    });
}

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

License:Apache License

private static void putSerialize(DataModelReference reference, List<PropertyReference> properties,
        ClassWriter writer) {//from ww w  .j a  v a2  s  .  c o m
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "serializeValue",
            Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(Object.class), typeOf(DataOutput.class)), null,
            new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    LocalVarRef object = cast(v, 1, reference.getDeclaration());
    LocalVarRef output = new LocalVarRef(Opcodes.ALOAD, 2);
    for (PropertyReference property : properties) {
        object.load(v);
        getOption(v, property);
        output.load(v);
        v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "serialize",
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataOutput.class)),
                false);
    }
    v.visitInsn(Opcodes.RETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

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

License:Apache License

private static void putDeserialize(DataModelReference reference, List<PropertyReference> properties,
        FieldRef buffer, ClassWriter writer) {
    MethodVisitor v = writer.visitMethod(Opcodes.ACC_PUBLIC, "deserializePair",
            Type.getMethodDescriptor(typeOf(Object.class), typeOf(DataInput.class), typeOf(DataInput.class)),
            null, new String[] { typeOf(IOException.class).getInternalName(),
                    typeOf(InterruptedException.class).getInternalName(), });
    LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0);
    LocalVarRef valueInput = new LocalVarRef(Opcodes.ALOAD, 2);
    self.load(v);//  w  ww . j ava  2  s . com
    getField(v, buffer);
    LocalVarRef object = putLocalVar(v, Type.OBJECT, 3);
    for (PropertyReference property : properties) {
        object.load(v);
        getOption(v, property);
        valueInput.load(v);
        v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "deserialize",
                Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataInput.class)),
                false);
    }
    object.load(v);
    v.visitInsn(Opcodes.ARETURN);
    v.visitMaxs(0, 0);
    v.visitEnd();
}

From source file:com.asakusafw.dag.compiler.internalio.InternalInputAdapterGenerator.java

License:Apache License

/**
 * Generates {@link InternalInputAdapter} class.
 * @param context the current context/* www . j  a  va2s .c  o  m*/
 * @param spec the target input spec
 * @param target the target class
 * @return the generated class data
 */
public ClassData generate(ClassGeneratorContext context, Spec spec, ClassDescription target) {
    ClassWriter writer = newWriter(target, InternalInputAdapter.class);
    defineAdapterConstructor(writer, InternalInputAdapter.class, v -> {
        v.visitVarInsn(Opcodes.ALOAD, 0);
        getConst(v, spec.id);
        getArray(v, spec.paths.stream().toArray(String[]::new));
        getConst(v, spec.dataType);
        v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, target.getInternalName(), "bind", //$NON-NLS-1$
                Type.getMethodDescriptor(typeOf(InternalInputAdapter.class), typeOf(String.class),
                        typeOf(String[].class), typeOf(Class.class)),
                false);
        v.visitInsn(Opcodes.POP);
    });
    return new ClassData(target, writer::toByteArray);
}