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.formulacompiler.compiler.internal.bytecode.HelperCompilerForFoldApply.java
License:Open Source License
private void compileMerge() throws CompilerException { final Label exit; if (mustDetectEmptiness) { final Label notEmpty = mv().newLabel(); mv().visitVarInsn(Opcodes.ILOAD, indexVar); mv().ifZCmp(Opcodes.IFGT, notEmpty); expressionCompiler().compile(fold.whenEmpty()); exit = mv().newLabel();//w w w .j av a 2 s. c om mv().goTo(exit); mv().mark(notEmpty); } else { exit = null; } if (fold.isMergedExplicitly()) { if (mustCount) { letIndexVarAs(fold.countName()); } else if (fold.isCounted()) { letDict().let(fold.countName(), DataType.NUMERIC, new CompilableExpressionNode( new ExpressionNodeForConstantValue(staticCount, DataType.NUMERIC))); } expressionCompiler().compile(fold.merge()); } else { assert 1 == accuVars.length; compileAccumulatorLoad(0); } if (null != exit) mv().mark(exit); }
From source file:org.formulacompiler.compiler.internal.bytecode.HelperCompilerForFoldChained.java
License:Open Source License
private void compileAccumulatorLoad() { mv().visitVarInsn(accuType.getOpcode(Opcodes.ILOAD), accuVar); }
From source file:org.formulacompiler.compiler.internal.bytecode.IndexerCompiler.java
License:Open Source License
@Override protected void compileBody() throws CompilerException { final ExpressionNodeForArrayReference arrayNode = this.node; final ExpressionCompiler valCompiler = expressionCompiler(arrayNode.getDataType()); final GeneratorAdapter mv = mv(); final List<ExpressionNode> vals = arrayNode.arguments(); final int valCnt = vals.size(); if (valCnt > 0) { mv.visitVarInsn(Opcodes.ILOAD, 1); // index // gen switch final int[] valIdxs = new int[valCnt]; for (int i = 0; i < valCnt; i++) { valIdxs[i] = i;/*w w w.ja v a 2 s.com*/ } compileTableSwitch(valIdxs, new TableSwitchGenerator() { @Override protected void generateCase(int _key, Label _end) throws CompilerException { final ExpressionNode val = vals.get(_key); valCompiler.compile(val); mv.returnValue(); } }); } mv.throwException(ExpressionCompiler.FORMULA_ERROR_TYPE, "#VALUE/REF! because index is out of range in INDEX"); }
From source file:org.formulacompiler.compiler.internal.bytecode.LinearizerCompiler.java
License:Open Source License
@Override protected void compileBody() throws CompilerException { final GeneratorAdapter mv = mv(); final Label outOfRange = mv.newLabel(); // range check row mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(1);//from w w w . ja v a 2 s. c o m mv.ifICmp(mv.LT, outOfRange); mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(this.rows); mv.ifICmp(mv.GT, outOfRange); // range check col mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(1); mv.ifICmp(mv.LT, outOfRange); mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(this.cols); mv.ifICmp(mv.GT, outOfRange); // (<row> - 1) * <num_cols>) + (<col> - 1); mv.visitVarInsn(Opcodes.ILOAD, 1); // row mv.push(1); mv.visitInsn(Opcodes.ISUB); mv.push(this.cols); mv.visitInsn(Opcodes.IMUL); mv.visitVarInsn(Opcodes.ILOAD, 2); // col mv.push(1); mv.visitInsn(Opcodes.ISUB); mv.visitInsn(Opcodes.IADD); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(outOfRange); mv.throwException(ExpressionCompiler.FORMULA_ERROR_TYPE, "#VALUE/REF! because index is out of range in INDEX"); }
From source file:org.glassfish.pfl.tf.spi.Util.java
License:Open Source License
public int wrapArg(MethodVisitor mv, int argIndex, Type atype) { info(2, "Emitting code to wrap argument at " + argIndex + " of type " + atype); switch (atype.getSort()) { case Type.BOOLEAN: mv.visitVarInsn(Opcodes.ILOAD, argIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Boolean.class), "valueOf", "(Z)Ljava/lang/Boolean;"); break;/*from w w w .j ava 2 s . c o m*/ case Type.BYTE: mv.visitVarInsn(Opcodes.ILOAD, argIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Byte.class), "valueOf", "(B)Ljava/lang/Byte;"); break; case Type.CHAR: mv.visitVarInsn(Opcodes.ILOAD, argIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Character.class), "valueOf", "(C)Ljava/lang/Character;"); break; case Type.SHORT: mv.visitVarInsn(Opcodes.ILOAD, argIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Short.class), "valueOf", "(S)Ljava/lang/Short;"); break; case Type.INT: mv.visitVarInsn(Opcodes.ILOAD, argIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Integer.class), "valueOf", "(I)Ljava/lang/Integer;"); break; case Type.LONG: mv.visitVarInsn(Opcodes.LLOAD, argIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Long.class), "valueOf", "(J)Ljava/lang/Long;"); break; case Type.DOUBLE: mv.visitVarInsn(Opcodes.DLOAD, argIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Double.class), "valueOf", "(D)Ljava/lang/Double;"); break; case Type.FLOAT: mv.visitVarInsn(Opcodes.FLOAD, argIndex); mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(Float.class), "valueOf", "(F)Ljava/lang/Float;"); break; default: mv.visitVarInsn(Opcodes.ALOAD, argIndex); break; } return argIndex + atype.getSize(); }
From source file:org.glassfish.pfl.tf.spi.Util.java
License:Open Source License
public void loadFromXReturn(MethodVisitor mv, int returnOpcode, LocalVariableNode holder) { switch (returnOpcode) { case Opcodes.RETURN: // NOP/* w w w. ja v a 2 s . com*/ break; case Opcodes.ARETURN: mv.visitVarInsn(Opcodes.ALOAD, holder.index); break; case Opcodes.IRETURN: mv.visitVarInsn(Opcodes.ILOAD, holder.index); break; case Opcodes.LRETURN: mv.visitVarInsn(Opcodes.LLOAD, holder.index); break; case Opcodes.FRETURN: mv.visitVarInsn(Opcodes.FLOAD, holder.index); break; case Opcodes.DRETURN: mv.visitVarInsn(Opcodes.DLOAD, holder.index); break; } }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedCollectionProxyClassGenerator.java
License:Apache License
private <T> void generateConstructors(ClassWriter visitor, Class<? extends T> implClass, Type superclassType) { for (Constructor<?> constructor : implClass.getConstructors()) { Type[] paramTypes = new Type[constructor.getParameterTypes().length]; for (int i = 0; i < paramTypes.length; i++) { paramTypes[i] = Type.getType(constructor.getParameterTypes()[i]); }/*from www .j av a 2s. co m*/ String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, paramTypes); MethodVisitor constructorVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, CONSTRUCTOR_NAME, methodDescriptor, CONCRETE_SIGNATURE, NO_EXCEPTIONS); constructorVisitor.visitCode(); putThisOnStack(constructorVisitor); for (int i = 0; i < paramTypes.length; i++) { constructorVisitor.visitVarInsn(paramTypes[i].getOpcode(Opcodes.ILOAD), i + 1); } constructorVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), CONSTRUCTOR_NAME, methodDescriptor, false); finishVisitingMethod(constructorVisitor); } }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
@Override public void visit(BinaryExpression node) throws ASTVisitorException { node.getExpression1().accept(this); Type expr1Type = ASTUtils.getSafeType(node.getExpression1()); node.getExpression2().accept(this); Type expr2Type = ASTUtils.getSafeType(node.getExpression2()); Type maxType = TypeUtils.maxType(expr1Type, expr2Type); // cast top of stack to max if (!maxType.equals(expr2Type)) { widen(maxType, expr2Type); }/* w w w . ja v a2s. com*/ System.out.println("^^^^^^^^^^^^^^^^^^^ binary op: " + node.getOperator()); System.out.println(" type1: " + expr1Type + " type2: " + expr2Type); System.out.println(" max type: " + !maxType.equals(expr1Type)); // cast second from top to max if (!maxType.equals(expr1Type)) { System.out.println("not to be dispalyed"); LocalIndexPool lip = ASTUtils.getSafeLocalIndexPool(node); int localIndex = -1; if (expr2Type.equals(Type.DOUBLE_TYPE) || expr1Type.equals(Type.DOUBLE_TYPE)) { localIndex = lip.getLocalIndex(expr2Type); mn.instructions.add(new VarInsnNode(expr2Type.getOpcode(Opcodes.ISTORE), localIndex)); } else { mn.instructions.add(new InsnNode(Opcodes.SWAP)); } widen(maxType, expr1Type); if (expr2Type.equals(Type.DOUBLE_TYPE) || expr1Type.equals(Type.DOUBLE_TYPE)) { mn.instructions.add(new VarInsnNode(expr2Type.getOpcode(Opcodes.ILOAD), localIndex)); lip.freeLocalIndex(localIndex, expr2Type); } else { mn.instructions.add(new InsnNode(Opcodes.SWAP)); } } // if (ASTUtils.isBooleanExpression(node)) { handleBooleanOperator(node, node.getOperator(), maxType); } else if (maxType.equals(TypeUtils.STRING_TYPE)) { mn.instructions.add(new InsnNode(Opcodes.SWAP)); handleStringOperator(node, node.getOperator()); } else { handleNumberOperator(node, node.getOperator(), maxType); } }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
@Override public void visit(IdentifierExpression node) throws ASTVisitorException { previousIsIdentifier = false;/*from w w w . j a va2 s. c o m*/ if (node.getExpressions() != null) { node.getExpressions().accept(this); SymTable<SymTableEntry> symbols = Registry.getInstance() .getExistingClass(Type.getType("Lorg/hua/customclasses/" + cn.name + ";")); SymTableEntry sEntry = symbols.lookup(node.getIdentifier()); if (sEntry != null) { mn.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getType("Lorg/hua/customclasses/" + cn.name + ";").getInternalName(), node.getIdentifier(), Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE), false)); } else { //search all classes //if the function is static and defined in another class, ok //else error String nodeId = node.getIdentifier(); boolean foundStaticOtherClass = false; String classFound; Map<Type, SymTable<SymTableEntry>> classes = Registry.getInstance().getClasses(); Iterator<Map.Entry<Type, SymTable<SymTableEntry>>> entries = classes.entrySet().iterator(); while (entries.hasNext()) { Map.Entry<Type, SymTable<SymTableEntry>> entry = entries.next(); if (entry.getValue().lookup(nodeId) != null) { if (entry.getValue().lookup(nodeId).isIsStatic()) { foundStaticOtherClass = true; classFound = entry.getKey().toString(); break; } } } if (!foundStaticOtherClass) { ASTUtils.error(node, "This static(?) method could not be found"); } } } else { Type type = ASTUtils.getSafeType(node); SymTable<SymTableEntry> symbols = Registry.getInstance() .getExistingClass(Type.getType("Lorg/hua/customclasses/" + cn.name + ";")); SymTableEntry csEntry = symbols.lookup(node.getIdentifier()); //i think this is useless, because fields are not seperate identifier, but string ids in accessorExpressions if (csEntry != null) { mn.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, cn.name, node.getIdentifier(), csEntry.getType().getDescriptor())); return; } SymTable<SymTableEntry> sTable = ASTUtils.getSafeEnv(node); SymTableEntry sEntry = sTable.lookup(node.getIdentifier()); previousIsIdentifier = true; mn.instructions.add(new VarInsnNode(type.getOpcode(Opcodes.ILOAD), sEntry.getIndex())); System.out.println( "&&&&&&&&&&&&&&&&&&&&&&&&&&&& INDEX: " + sEntry.getIndex() + " id: " + node.getIdentifier()); } }
From source file:org.hua.ast.visitors.BytecodeGeneratorASTVisitor.java
@Override public void visit(NullExpression node) throws ASTVisitorException { mn.instructions.add(new VarInsnNode(Opcodes.ILOAD, Opcodes.NULL)); }