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:lucee.transformer.bytecode.Page.java
License:Open Source License
/** * result byte code as binary array/*w w w. ja v a 2 s . c o m*/ * @param classFile * @return byte code * @throws IOException * @throws TemplateException */ public byte[] execute(PageSource source, Resource classFile) throws BytecodeException { /* // this is done that the Page can be executed more than once if(initFunctions==null) initFunctions=(ArrayList<IFunction>) functions.clone(); else functions=initFunctions; if(initThreads==null) initThreads=(ArrayList<TagThread>) threads.clone(); else threads=initThreads; methodCount=0; off=0; staticTextLocation=null; print.e(this.functions); print.e(this.threads);*/ Resource p = classFile.getParentResource().getRealResource(classFile.getName() + ".txt"); List<LitString> keys = new ArrayList<LitString>(); ClassWriter cw = ASMUtil.getClassWriter(); ArrayList<String> imports = new ArrayList<String>(); getImports(imports, this); // parent String parent = "lucee/runtime/PagePlus"; if (isComponent()) parent = "lucee/runtime/ComponentPage"; else if (isInterface()) parent = "lucee/runtime/InterfacePage"; cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, name, null, parent, null); cw.visitSource(this.pageSource.getPhyscalFile().getAbsolutePath(), "rel:" + this.pageSource.getFullRealpath()); // when adding more use ; as delimiter // // static constructor //GeneratorAdapter statConstrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC,STATIC_CONSTRUCTOR,null,null,cw); BytecodeContext statConstr = null;//new BytecodeContext(null,null,this,externalizer,keys,cw,name,statConstrAdapter,STATIC_CONSTRUCTOR,writeLog(),suppressWSbeforeArg); // constructor GeneratorAdapter constrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_PS, null, null, cw); BytecodeContext constr = new BytecodeContext(source, null, null, this, keys, cw, name, constrAdapter, CONSTRUCTOR_PS, writeLog(), suppressWSbeforeArg, output); constrAdapter.loadThis(); Type t = Types.PAGE_PLUS; if (isComponent()) t = Types.COMPONENT_PAGE; else if (isInterface()) t = Types.INTERFACE_PAGE; constrAdapter.invokeConstructor(t, CONSTRUCTOR); // call _init() constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); constrAdapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, constr.getClassName(), "initKeys", "()V"); // private static ImportDefintion[] test=new ImportDefintion[]{...}; { FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "imports", "[Llucee/runtime/component/ImportDefintion;", null, null); fv.visitEnd(); constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); ArrayVisitor av = new ArrayVisitor(); av.visitBegin(constrAdapter, Types.IMPORT_DEFINITIONS, imports.size()); int index = 0; Iterator<String> it = imports.iterator(); while (it.hasNext()) { av.visitBeginItem(constrAdapter, index++); constrAdapter.push(it.next()); ASMConstants.NULL(constrAdapter); constrAdapter.invokeStatic(Types.IMPORT_DEFINITIONS_IMPL, ID_GET_INSTANCE); av.visitEndItem(constrAdapter); } av.visitEnd(); constrAdapter.visitFieldInsn(Opcodes.PUTFIELD, name, "imports", "[Llucee/runtime/component/ImportDefintion;"); } // getVersion GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, VERSION, null, null, cw); adapter.push(version); adapter.returnValue(); adapter.endMethod(); // public ImportDefintion[] getImportDefintions() if (imports.size() > 0) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.visitFieldInsn(Opcodes.GETFIELD, name, "imports", "[Llucee/runtime/component/ImportDefintion;"); adapter.returnValue(); adapter.endMethod(); } else { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw); adapter.visitInsn(Opcodes.ICONST_0); adapter.visitTypeInsn(Opcodes.ANEWARRAY, "lucee/runtime/component/ImportDefintion"); adapter.returnValue(); adapter.endMethod(); } // getSourceLastModified adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, LAST_MOD, null, null, cw); adapter.push(lastModifed); adapter.returnValue(); adapter.endMethod(); // getCompileTime adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, COMPILE_TIME, null, null, cw); adapter.push(System.currentTimeMillis()); adapter.returnValue(); adapter.endMethod(); // newInstance/initComponent/call if (isComponent()) { Tag component = getComponent(); writeOutNewComponent(statConstr, constr, keys, cw, component); writeOutInitComponent(statConstr, constr, keys, cw, component); } else if (isInterface()) { Tag interf = getInterface(); writeOutNewInterface(statConstr, constr, keys, cw, interf); writeOutInitInterface(statConstr, constr, keys, cw, interf); } else { writeOutCall(statConstr, constr, keys, cw); } // udfCall Function[] functions = getFunctions(); ConditionVisitor cv; DecisionIntVisitor div; // less/equal than 10 functions if (isInterface()) { } else if (functions.length <= 10) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_CALL, null, new Type[] { Types.THROWABLE }, cw); BytecodeContext bc = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, UDF_CALL, writeLog(), suppressWSbeforeArg, output); if (functions.length == 0) { } else if (functions.length == 1) { ExpressionUtil.visitLine(bc, functions[0].getStart()); functions[0].getBody().writeOut(bc); ExpressionUtil.visitLine(bc, functions[0].getEnd()); } else writeOutUdfCallInner(bc, functions, 0, functions.length); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } // more than 10 functions else { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_CALL, null, new Type[] { Types.THROWABLE }, cw); BytecodeContext bc = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, UDF_CALL, writeLog(), suppressWSbeforeArg, output); cv = new ConditionVisitor(); cv.visitBefore(); int count = 0; for (int i = 0; i < functions.length; i += 10) { cv.visitWhenBeforeExpr(); div = new DecisionIntVisitor(); div.visitBegin(); adapter.loadArg(2); div.visitLT(); adapter.push(i + 10); div.visitEnd(bc); cv.visitWhenAfterExprBeforeBody(bc); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.visitVarInsn(Opcodes.ALOAD, 1); adapter.visitVarInsn(Opcodes.ALOAD, 2); adapter.visitVarInsn(Opcodes.ILOAD, 3); adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, createFunctionName(++count), "(Llucee/runtime/PageContext;Llucee/runtime/type/UDF;I)Ljava/lang/Object;"); adapter.visitInsn(Opcodes.ARETURN);//adapter.returnValue(); cv.visitWhenAfterBody(bc); } cv.visitAfter(bc); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); count = 0; Method innerCall; for (int i = 0; i < functions.length; i += 10) { innerCall = new Method(createFunctionName(++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, USER_DEFINED_FUNCTION, Types.INT_VALUE }); adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerCall, null, new Type[] { Types.THROWABLE }, cw); writeOutUdfCallInner( new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, innerCall, writeLog(), suppressWSbeforeArg, output), functions, i, i + 10 > functions.length ? functions.length : i + 10); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } } // threadCall TagThread[] threads = getThreads(); if (true) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, THREAD_CALL, null, new Type[] { Types.THROWABLE }, cw); if (threads.length > 0) writeOutThreadCallInner(new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, THREAD_CALL, writeLog(), suppressWSbeforeArg, output), threads, 0, threads.length); //adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } // udfDefaultValue // less/equal than 10 functions if (isInterface()) { } else if (functions.length <= 10) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_DEFAULT_VALUE, null, new Type[] { Types.PAGE_EXCEPTION }, cw); if (functions.length > 0) writeUdfDefaultValueInner( new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, UDF_DEFAULT_VALUE, writeLog(), suppressWSbeforeArg, output), functions, 0, functions.length); adapter.loadArg(DEFAULT_VALUE); adapter.returnValue(); adapter.endMethod(); } else { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_DEFAULT_VALUE, null, new Type[] { Types.PAGE_EXCEPTION }, cw); BytecodeContext bc = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, UDF_DEFAULT_VALUE, writeLog(), suppressWSbeforeArg, output); cv = new ConditionVisitor(); cv.visitBefore(); int count = 0; for (int i = 0; i < functions.length; i += 10) { cv.visitWhenBeforeExpr(); div = new DecisionIntVisitor(); div.visitBegin(); adapter.loadArg(1); div.visitLT(); adapter.push(i + 10); div.visitEnd(bc); cv.visitWhenAfterExprBeforeBody(bc); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.visitVarInsn(Opcodes.ALOAD, 1); adapter.visitVarInsn(Opcodes.ILOAD, 2); adapter.visitVarInsn(Opcodes.ILOAD, 3); adapter.visitVarInsn(Opcodes.ALOAD, 4); adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, "udfDefaultValue" + (++count), "(Llucee/runtime/PageContext;IILjava/lang/Object;)Ljava/lang/Object;"); adapter.visitInsn(Opcodes.ARETURN);//adapter.returnValue(); cv.visitWhenAfterBody(bc); } cv.visitAfter(bc); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); count = 0; Method innerDefaultValue; for (int i = 0; i < functions.length; i += 10) { innerDefaultValue = new Method("udfDefaultValue" + (++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, Types.INT_VALUE, Types.INT_VALUE, Types.OBJECT }); adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerDefaultValue, null, new Type[] { Types.PAGE_EXCEPTION }, cw); writeUdfDefaultValueInner( new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, innerDefaultValue, writeLog(), suppressWSbeforeArg, output), functions, i, i + 10 > functions.length ? functions.length : i + 10); adapter.loadArg(DEFAULT_VALUE); //adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } } // register fields { GeneratorAdapter aInit = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, _INIT, null, null, cw); BytecodeContext bcInit = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, aInit, _INIT, writeLog(), suppressWSbeforeArg, output); registerFields(bcInit, keys); aInit.returnValue(); aInit.endMethod(); } //setPageSource(pageSource); constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); constrAdapter.visitVarInsn(Opcodes.ALOAD, 1); constrAdapter.invokeVirtual(t, SET_PAGE_SOURCE); constrAdapter.returnValue(); constrAdapter.endMethod(); return cw.toByteArray(); }
From source file:lucee.transformer.bytecode.Page.java
License:Open Source License
private void writeOutNewComponent(BytecodeContext statConstr, BytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component) throws BytecodeException { GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_COMPONENT_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw); BytecodeContext bc = new BytecodeContext(null, statConstr, constr, this, keys, cw, name, adapter, NEW_COMPONENT_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output); Label methodBegin = new Label(); Label methodEnd = new Label(); adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0); ExpressionUtil.visitLine(bc, component.getStart()); adapter.visitLabel(methodBegin);//from w ww .ja v a 2 s . c o m int comp = adapter.newLocal(Types.COMPONENT_IMPL); adapter.newInstance(Types.COMPONENT_IMPL); adapter.dup(); Attribute attr; // ComponentPage adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.checkCast(Types.COMPONENT_PAGE); // !!! also check CFMLScriptTransformer.addMetaData if you do any change here !!! // Output attr = component.removeAttribute("output"); if (attr != null) { ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); } else ASMConstants.NULL(adapter); // synchronized attr = component.removeAttribute("synchronized"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_VALUE); else adapter.push(false); // extends attr = component.removeAttribute("extends"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // implements attr = component.removeAttribute("implements"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // hint attr = component.removeAttribute("hint"); if (attr != null) { Expression value = attr.getValue(); if (!(value instanceof Literal)) { value = LitString.toExprString("[runtime expression]"); } ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF); } else adapter.push(""); // dspName attr = component.removeAttribute("displayname"); if (attr == null) attr = component.getAttribute("display"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // callpath adapter.visitVarInsn(Opcodes.ALOAD, 2); // relpath adapter.visitVarInsn(Opcodes.ILOAD, 3); // style attr = component.removeAttribute("style"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // persistent attr = component.removeAttribute("persistent"); boolean persistent = false; if (attr != null) { persistent = ASMUtil.toBoolean(attr, component.getStart()).booleanValue(); } // persistent attr = component.removeAttribute("accessors"); boolean accessors = false; if (attr != null) { accessors = ASMUtil.toBoolean(attr, component.getStart()).booleanValue(); } adapter.push(persistent); adapter.push(accessors); //ExpressionUtil.writeOutSilent(attr.getValue(),bc, Expression.MODE_VALUE); //adapter.visitVarInsn(Opcodes.ALOAD, 4); createMetaDataStruct(bc, component.getAttributes(), component.getMetaData()); adapter.invokeConstructor(Types.COMPONENT_IMPL, CONSTR_COMPONENT_IMPL); adapter.storeLocal(comp); //Component Impl(ComponentPage componentPage,boolean output, String extend, String hint, String dspName) // initComponent(pc,c); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.loadArg(0); adapter.loadLocal(comp); adapter.invokeVirtual(Types.COMPONENT_PAGE, INIT_COMPONENT); adapter.visitLabel(methodEnd); // return component; adapter.loadLocal(comp); adapter.returnValue(); //ExpressionUtil.visitLine(adapter, component.getEndLine()); adapter.endMethod(); }
From source file:lucee.transformer.bytecode.Page.java
License:Open Source License
private void writeOutNewInterface(BytecodeContext statConstr, BytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag interf) throws BytecodeException { GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_INTERFACE_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw); BytecodeContext bc = new BytecodeContext(null, statConstr, constr, this, keys, cw, name, adapter, NEW_INTERFACE_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output); Label methodBegin = new Label(); Label methodEnd = new Label(); adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0); ExpressionUtil.visitLine(bc, interf.getStart()); adapter.visitLabel(methodBegin);//www . jav a 2 s. co m //ExpressionUtil.visitLine(adapter, interf.getStartLine()); int comp = adapter.newLocal(Types.INTERFACE_IMPL); adapter.newInstance(Types.INTERFACE_IMPL); adapter.dup(); Attribute attr; // Interface Page adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.checkCast(Types.INTERFACE_PAGE); // extened attr = interf.removeAttribute("extends"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // hint attr = interf.removeAttribute("hint"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // dspName attr = interf.removeAttribute("displayname"); if (attr == null) attr = interf.getAttribute("display"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // callpath adapter.visitVarInsn(Opcodes.ALOAD, 1); // relpath adapter.visitVarInsn(Opcodes.ILOAD, 2); // interface udfs adapter.visitVarInsn(Opcodes.ALOAD, 3); createMetaDataStruct(bc, interf.getAttributes(), interf.getMetaData()); adapter.invokeConstructor(Types.INTERFACE_IMPL, CONSTR_INTERFACE_IMPL); adapter.storeLocal(comp); // initInterface(pc,c); adapter.visitVarInsn(Opcodes.ALOAD, 0); //adapter.loadArg(0); adapter.loadLocal(comp); adapter.invokeVirtual(Types.INTERFACE_PAGE, INIT_INTERFACE); adapter.visitLabel(methodEnd); // return interface; adapter.loadLocal(comp); adapter.returnValue(); //ExpressionUtil.visitLine(adapter, interf.getEndLine()); adapter.endMethod(); }
From source file:lucee.transformer.bytecode.statement.tag.TagLoop.java
License:Open Source License
/** * write out list loop// ww w . j av a2 s. co m * @param adapter * @throws TemplateException */ private void writeOutTypeListArray(BytecodeContext bc, boolean isArray) throws BytecodeException { ForVisitor forVisitor = new ForVisitor(); loopVisitor = forVisitor; GeneratorAdapter adapter = bc.getAdapter(); //List.listToArrayRemoveEmpty("", 'c') int array = adapter.newLocal(Types.ARRAY); int len = adapter.newLocal(Types.INT_VALUE); if (isArray) { getAttribute("array").getValue().writeOut(bc, Expression.MODE_REF); } else { // array=List.listToArrayRemoveEmpty(list, delimter) getAttribute("list").getValue().writeOut(bc, Expression.MODE_REF); if (containsAttribute("delimiters")) { getAttribute("delimiters").getValue().writeOut(bc, Expression.MODE_REF); adapter.invokeStatic(Types.LIST_UTIL, LIST_TO_ARRAY_REMOVE_EMPTY_SS); } else { adapter.visitIntInsn(Opcodes.BIPUSH, 44);// ',' //adapter.push(','); adapter.invokeStatic(Types.LIST_UTIL, LIST_TO_ARRAY_REMOVE_EMPTY_SC); } } adapter.storeLocal(array); // int len=array.size(); adapter.loadLocal(array); adapter.invokeInterface(Types.ARRAY, SIZE); adapter.storeLocal(len); //VariableInterpreter.getVariableReference(pc,Caster.toString(index)); Attribute attrIndex = getAttribute("index"); int index = -1; if (attrIndex != null) { index = adapter.newLocal(Types.VARIABLE_REFERENCE); adapter.loadArg(0); attrIndex.getValue().writeOut(bc, Expression.MODE_REF); adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE); adapter.storeLocal(index); } //VariableInterpreter.getVariableReference(pc,Caster.toString(item)); Attribute attrItem = getAttribute("item"); int item = -1; if (attrItem != null) { item = adapter.newLocal(Types.VARIABLE_REFERENCE); adapter.loadArg(0); attrItem.getValue().writeOut(bc, Expression.MODE_REF); adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE); adapter.storeLocal(item); } int obj = 0; if (isArray) obj = adapter.newLocal(Types.OBJECT); // for(int i=1;i<=len;i++) { int i = forVisitor.visitBegin(adapter, 1, false); // index.set(pc, list.get(i)); if (isArray) { // value adapter.loadLocal(array); adapter.visitVarInsn(Opcodes.ILOAD, i); ASMConstants.NULL(adapter); adapter.invokeInterface(Types.ARRAY, GET); adapter.dup(); adapter.storeLocal(obj); Label endIf = new Label(); //adapter.loadLocal(obj); adapter.visitJumpInsn(Opcodes.IFNONNULL, endIf); adapter.goTo(forVisitor.getContinueLabel()); adapter.visitLabel(endIf); if (item == -1) adapter.loadLocal(index); else adapter.loadLocal(item); adapter.loadArg(0); adapter.loadLocal(obj); } else { if (item == -1) adapter.loadLocal(index); else adapter.loadLocal(item); adapter.loadArg(0); adapter.loadLocal(array); adapter.visitVarInsn(Opcodes.ILOAD, i); adapter.invokeInterface(Types.ARRAY, GETE); } adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET); adapter.pop(); // key if (index != -1 && item != -1) { adapter.loadLocal(index); adapter.loadArg(0); adapter.visitVarInsn(Opcodes.ILOAD, i); adapter.cast(Types.INT_VALUE, Types.DOUBLE_VALUE); adapter.invokeStatic(Types.CASTER, Methods_Caster.TO_DOUBLE[Methods_Caster.DOUBLE]); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET); adapter.pop(); } getBody().writeOut(bc); forVisitor.visitEnd(bc, len, true, getStart()); }
From source file:lucee.transformer.bytecode.util.ASMUtil.java
License:Open Source License
public static int loadFor(Type type) { if (type.equals(Types.BOOLEAN_VALUE) || type.equals(Types.INT_VALUE) || type.equals(Types.CHAR) || type.equals(Types.SHORT_VALUE)) return Opcodes.ILOAD; if (type.equals(Types.FLOAT_VALUE)) return Opcodes.FLOAD; if (type.equals(Types.LONG_VALUE)) return Opcodes.LLOAD; if (type.equals(Types.DOUBLE_VALUE)) return Opcodes.DLOAD; return Opcodes.ALOAD; }
From source file:me.themallard.bitmmo.api.transformer.Transformer.java
License:Open Source License
protected final void createSetter(ClassNode cn, FieldNode fn, String name) { MethodVisitor mv = cn.visitMethod(Opcodes.ACC_PUBLIC, name, "(" + fn.desc + ")V", null, null); mv.visitVarInsn(Opcodes.ALOAD, 0);//from w w w . j av a 2 s.c o m mv.visitVarInsn(Type.getType(fn.desc).getOpcode(Opcodes.ILOAD), 1); mv.visitFieldInsn(Opcodes.PUTFIELD, cn.name, fn.name, fn.desc); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:name.martingeisse.minimal.compiler.Compiler.java
License:Open Source License
/** * Compiles a {@link MethodNode} to MCode. * /*from w w w . j a va 2 s. co m*/ * @param methodNode the method node to compile * @return the compiled code */ public ImmutableList<MCodeEntry> compile(final MethodNode methodNode) { for (int i = 0; i < methodNode.instructions.size(); i++) { final AbstractInsnNode instruction = methodNode.instructions.get(i); if (instruction instanceof LineNumberNode) { // ignored } else if (instruction instanceof FrameNode) { // this could be useful in the future } else if (instruction instanceof LabelNode) { label(((LabelNode) instruction).getLabel()); } else if (instruction instanceof InsnNode) { switch (instruction.getOpcode()) { case Opcodes.ICONST_M1: iconst(-1); break; case Opcodes.ICONST_0: iconst(0); break; case Opcodes.ICONST_1: iconst(1); break; case Opcodes.ICONST_2: iconst(2); break; case Opcodes.ICONST_3: iconst(3); break; case Opcodes.ICONST_4: iconst(4); break; case Opcodes.ICONST_5: iconst(5); break; default: unsupported(instruction); break; } } else if (instruction instanceof VarInsnNode) { final VarInsnNode varInsnNode = (VarInsnNode) instruction; switch (varInsnNode.getOpcode()) { case Opcodes.ILOAD: iload(varInsnNode.var); break; case Opcodes.ISTORE: istore(varInsnNode.var); break; default: unsupported(instruction); break; } } else if (instruction instanceof IincInsnNode) { final IincInsnNode iincInsnNode = (IincInsnNode) instruction; iinc(iincInsnNode.var, iincInsnNode.incr); } else if (instruction instanceof JumpInsnNode) { final JumpInsnNode jumpInsnNode = (JumpInsnNode) instruction; switch (jumpInsnNode.getOpcode()) { case Opcodes.IFEQ: case Opcodes.IFNE: case Opcodes.IFLT: case Opcodes.IFGE: case Opcodes.IFGT: case Opcodes.IFLE: branch1(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode()); break; case Opcodes.IF_ICMPEQ: case Opcodes.IF_ICMPNE: case Opcodes.IF_ICMPLT: case Opcodes.IF_ICMPGE: case Opcodes.IF_ICMPGT: case Opcodes.IF_ICMPLE: branch2(jumpInsnNode.label.getLabel(), jumpInsnNode.getOpcode()); break; case Opcodes.IFNULL: case Opcodes.IFNONNULL: // unsupported: one-argument reference comparison operator unsupported(instruction); break; case Opcodes.IF_ACMPEQ: case Opcodes.IF_ACMPNE: // unsupported: two-argument reference comparison operator unsupported(instruction); break; case Opcodes.GOTO: jump(jumpInsnNode.label.getLabel()); break; case Opcodes.JSR: jsr(jumpInsnNode.label.getLabel()); break; default: unsupported(instruction); break; } } else if (instruction instanceof IntInsnNode) { final IntInsnNode intInsnNode = (IntInsnNode) instruction; if (instruction.getOpcode() == Opcodes.BIPUSH || instruction.getOpcode() == Opcodes.SIPUSH) { iconst(intInsnNode.operand); } else { // NEWARRAY unsupported(instruction); } } else if (instruction instanceof MethodInsnNode) { final MethodInsnNode methodInsnNode = (MethodInsnNode) instruction; if (methodInsnNode.getOpcode() == Opcodes.INVOKESTATIC) { if (methodInsnNode.owner.replace('/', '.').equals(Native.class.getName())) { nativeCall(methodInsnNode.name, methodInsnNode.desc); } else { unsupported(instruction); } } else { unsupported(instruction); } } else { unsupported(instruction); } } return builder.build(); }
From source file:net.sourceforge.cobertura.instrument.pass1.DetectIgnoredCodeMethodVisitor.java
License:GNU General Public License
public void visitVarInsn(int opcode, int i1) { super.visitVarInsn(opcode, i1); if (ignoredStatus.isTrivial() && opcode != Opcodes.ILOAD && opcode != Opcodes.LLOAD && opcode != Opcodes.FLOAD && opcode != Opcodes.DLOAD && opcode != Opcodes.ALOAD) { markNotTrivial();//from ww w . j av a 2 s . c o m } }
From source file:net.sourceforge.cobertura.instrument.pass3.AbstractCodeProvider.java
License:GNU General Public License
public void generateCodeThatIncrementsCoberturaCounterIfVariableEqualsAndCleanVariable( MethodVisitor nextMethodVisitor, Integer neededJumpCounterIdVariableValue, Integer counterIdToIncrement, int lastJumpIdVariableIndex, String className) { nextMethodVisitor.visitLdcInsn((int) neededJumpCounterIdVariableValue); nextMethodVisitor.visitVarInsn(Opcodes.ILOAD, lastJumpIdVariableIndex); Label afterJump = new Label(); nextMethodVisitor.visitJumpInsn(Opcodes.IF_ICMPNE, afterJump); generateCodeThatIncrementsCoberturaCounter(nextMethodVisitor, counterIdToIncrement, className); generateCodeThatZeroJumpCounterIdVariable(nextMethodVisitor, lastJumpIdVariableIndex); nextMethodVisitor.visitLabel(afterJump); }
From source file:net.sourceforge.cobertura.instrument.pass3.AtomicArrayCodeProvider.java
License:GNU General Public License
public void generateCodeThatIncrementsCoberturaCounterFromInternalVariable(MethodVisitor nextMethodVisitor, int lastJumpIdVariableIndex, String className) { /*cobertura_counters.incrementAndGet(value('lastJumpIdVariableIndex'));*/ /*cobertura_counters.*/ nextMethodVisitor.visitFieldInsn(Opcodes.GETSTATIC, className, COBERTURA_COUNTERS_FIELD_NAME, COBERTURA_COUNTERS_FIELD_TYPE); /*index:*/// w ww .j ava 2 s. c om nextMethodVisitor.visitVarInsn(Opcodes.ILOAD, lastJumpIdVariableIndex); nextMethodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(AtomicIntegerArray.class), "incrementAndGet", "(I)I"); nextMethodVisitor.visitInsn(Opcodes.POP); }