List of usage examples for org.objectweb.asm Opcodes ALOAD
int ALOAD
To view the source code for org.objectweb.asm Opcodes ALOAD.
Click Source Link
From source file:com.asakusafw.dag.compiler.codegen.ApplicationGenerator.java
License:Apache License
/** * Generates a class./*from w ww . ja va 2 s. co m*/ * @param contents the {@link GraphInfo} contents * @param target the target class * @return the generated class data */ public ClassData generate(Location contents, ClassDescription target) { ClassWriter writer = newWriter(target, AbstractApplication.class); defineEmptyConstructor(writer, method -> { method.visitVarInsn(Opcodes.ALOAD, 0); getConst(method, contents.toPath()); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(AbstractApplication.class).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(String.class)), false); }); writer.visitEnd(); return new ClassData(target, writer::toByteArray); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Returns the T_LOAD opcode./*from w w w . jav a 2 s . c om*/ * @param type the target type * @return the opcode */ public static int loadOpcodeOf(TypeDescription type) { Arguments.requireNonNull(type); if (type.getTypeKind() == TypeKind.BASIC) { switch (((BasicTypeDescription) type).getBasicTypeKind()) { case BOOLEAN: case BYTE: case CHAR: case SHORT: case INT: return Opcodes.ILOAD; case LONG: return Opcodes.LLOAD; case FLOAT: return Opcodes.FLOAD; case DOUBLE: return Opcodes.DLOAD; default: throw new AssertionError(type); } } return Opcodes.ALOAD; }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds an empty constructor./*w w w. j av a 2 s.c o m*/ * @param writer the target class * @param superClass the super class * @param body the constructor body */ public static void defineEmptyConstructor(ClassWriter writer, Class<?> superClass, Consumer<MethodVisitor> body) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), null, null); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(superClass).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), false); body.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds an adapter constructor./*www .j av a 2 s . c o m*/ * @param writer the target class * @param superClass the super class * @param body the constructor body */ public static void defineAdapterConstructor(ClassWriter writer, Class<?> superClass, Consumer<MethodVisitor> body) { MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(VertexProcessorContext.class)), null, null); method.visitVarInsn(Opcodes.ALOAD, 0); method.visitVarInsn(Opcodes.ALOAD, 1); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(superClass).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, typeOf(VertexProcessorContext.class)), false); body.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds a constructor with dependencies. * @param aClass the target class// ww w .j a v a 2 s. c om * @param writer the current writer * @param dependencies the target dependencies * @param callback the callback for building the extra constructor statements * @return the dependency map */ public static List<Tuple<VertexElement, FieldRef>> defineDependenciesConstructor(ClassDescription aClass, ClassVisitor writer, Iterable<? extends VertexElement> dependencies, Consumer<MethodVisitor> callback) { return defineDependenciesConstructor0(aClass, writer, dependencies, method -> { method.visitVarInsn(Opcodes.ALOAD, 0); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(Object.class).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), false); }, callback); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Adds a constructor with dependencies. * @param <T> the property type//from ww w.jav a 2s.c o m * @param context the current context * @param properties the dependency properties * @param aClass the target class * @param writer the current writer * @param callback the callback for building the extra constructor statements * @return the field map * @since 0.4.1 */ public static <T extends OperatorProperty> Map<T, FieldRef> defineDependenciesConstructor( OperatorNodeGenerator.Context context, List<? extends T> properties, ClassDescription aClass, ClassVisitor writer, Consumer<MethodVisitor> callback) { return defineDependenciesConstructor(context, properties, aClass, writer, method -> { method.visitVarInsn(Opcodes.ALOAD, 0); method.visitMethodInsn(Opcodes.INVOKESPECIAL, typeOf(Object.class).getInternalName(), CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE), false); }, callback); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
private static List<Tuple<VertexElement, FieldRef>> defineDependenciesConstructor0(ClassDescription aClass, ClassVisitor writer, Iterable<? extends VertexElement> dependencies, Consumer<MethodVisitor> superConstructor, Consumer<MethodVisitor> callback) { List<Tuple<VertexElement, FieldRef>> results = new ArrayList<>(); int index = 0; int varIndex = 1; List<Type> parameterTypes = new ArrayList<>(); List<Consumer<MethodVisitor>> ctor = new ArrayList<>(); for (VertexElement element : dependencies) { int current = index++; int currentVar = varIndex; String name = getDependencyId(current); Type type = typeOf(element.getRuntimeType()); parameterTypes.add(type);/*from w w w . j a v a2 s .com*/ FieldRef ref = defineField(writer, aClass, name, type); ctor.add(v -> { v.visitVarInsn(Opcodes.ALOAD, 0); v.visitVarInsn(loadOpcodeOf(element.getRuntimeType()), currentVar); putField(v, ref); }); varIndex += categoryOf(element.getRuntimeType()); results.add(new Tuple<>(element, ref)); } MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, Type.getMethodDescriptor(Type.VOID_TYPE, parameterTypes.stream().toArray(Type[]::new)), null, null); superConstructor.accept(method); ctor.forEach(c -> c.accept(method)); callback.accept(method); method.visitInsn(Opcodes.RETURN); method.visitMaxs(0, 0); method.visitEnd(); return results; }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Performs {@code T_STORE} instruction. * @param method the target method/*www . j a va 2 s. c o m*/ * @param sort the target type sort * @param index the target local variable index * @return the target local variable ref */ public static LocalVarRef putLocalVar(MethodVisitor method, int sort, int index) { int load; int store; switch (sort) { case Type.BOOLEAN: case Type.BYTE: case Type.SHORT: case Type.CHAR: case Type.INT: load = Opcodes.ILOAD; store = Opcodes.ISTORE; break; case Type.LONG: load = Opcodes.LLOAD; store = Opcodes.LSTORE; break; case Type.FLOAT: load = Opcodes.FLOAD; store = Opcodes.FSTORE; break; case Type.DOUBLE: load = Opcodes.DLOAD; store = Opcodes.DSTORE; break; case Type.ARRAY: case Type.OBJECT: load = Opcodes.ALOAD; store = Opcodes.ASTORE; break; default: throw new AssertionError(sort); } method.visitVarInsn(store, index); return new LocalVarRef(load, index); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Cast the local variable.//from ww w . jav a 2 s.c o m * @param method the writer * @param index the variable index * @param type the target type * @return the target variable */ public static LocalVarRef cast(MethodVisitor method, int index, TypeDescription type) { method.visitVarInsn(Opcodes.ALOAD, index); method.visitTypeInsn(Opcodes.CHECKCAST, AsmUtil.typeOf(type).getInternalName()); return putLocalVar(method, Type.OBJECT, index); }
From source file:com.asakusafw.dag.compiler.codegen.BufferOperatorGenerator.java
License:Apache License
private static ClassData generate0(List<? extends VertexElement> successors, ClassDescription target) { Arguments.require(successors.size() >= 2); TypeDescription dataType = getDataType(successors); ClassWriter writer = newWriter(target, Object.class, Result.class); FieldRef buffer = defineField(writer, target, "buffer", typeOf(dataType)); List<Tuple<VertexElement, FieldRef>> pairs = defineDependenciesConstructor(target, writer, successors, v -> {/*from ww w .j ava 2s . c o m*/ v.visitVarInsn(Opcodes.ALOAD, 0); getNew(v, dataType); putField(v, buffer); }); defineResultAdd(writer, method -> { LocalVarRef self = new LocalVarRef(Opcodes.ALOAD, 0); LocalVarRef input = cast(method, 1, dataType); self.load(method); getField(method, buffer); LocalVarRef buf = putLocalVar(method, Type.OBJECT, 2); for (int i = 0, n = pairs.size(); i < n; i++) { self.load(method); getField(method, pairs.get(i).right()); if (i < n - 1) { buf.load(method); input.load(method); copyDataModel(method, dataType); buf.load(method); } else { input.load(method); } invokeResultAdd(method); } }); writer.visitEnd(); return new ClassData(target, writer::toByteArray); }