List of usage examples for org.objectweb.asm Opcodes ISUB
int ISUB
To view the source code for org.objectweb.asm Opcodes ISUB.
Click Source Link
From source file:jpcsp.Allegrex.compiler.CompilerContext.java
License:Open Source License
/** * Generate the required Java code to call a syscall function. * The code generated must match the Java behavior implemented in * jpcsp.HLE.modules.HLEModuleFunctionReflection * * The following code is generated:/* w ww . ja v a 2s . co m*/ * if (func.getFirmwareVersion() <= RuntimeContext.firmwareVersion) { * if (!fastSyscall) { * RuntimeContext.preSyscall(); * } * if (func.checkInsideInterrupt()) { * if (IntrManager.getInstance.isInsideInterrupt()) { * cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT; * goto afterSyscall; * } * } * if (func.checkDispatchThreadEnabled()) { * if (!Modules.ThreadManForUserModule.isDispatchThreadEnabled()) { * cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT; * goto afterSyscall; * } * } * if (func.isUnimplemented()) { * Modules.getLogger(func.getModuleName()).warn("Unimplemented <function name> parameterName1=parameterValue1, parameterName2=parameterValue2, ..."); * } * foreach parameter { * loadParameter(parameter); * } * try { * returnValue = <module name>.<function name>(...parameters...); * storeReturnValue(); * if (parameterReader.hasErrorPointer()) { * errorPointer.setValue(0); * } * } catch (SceKernelErrorException e) { * errorCode = e.errorCode; * if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) { * Modules.getLogger(func.getModuleName()).debug(String.format("<function name> return errorCode 0x%08X", errorCode)); * } * if (parameterReader.hasErrorPointer()) { * errorPointer.setValue(errorCode); * cpu.gpr[_v0] = 0; * } else { * cpu.gpr[_v0] = errorCode; * } * reload cpu.gpr[_ra]; // an exception is always clearing the whole stack * } * afterSyscall: * if (fastSyscall) { * RuntimeContext.postSyscallFast(); * } else { * RuntimeContext.postSyscall(); * } * } else { * Modules.getLogger(func.getModuleName()).warn("<function name> is not supported in firmware version <firmwareVersion>, it requires at least firmware version <function firmwareVersion>"); * cpu.gpr[_v0] = -1; * } * * @param func the syscall function * @param fastSyscall true if this is a fast syscall (i.e. without context switching) * false if not (i.e. a syscall where context switching could happen) */ private void visitSyscall(HLEModuleFunction func, boolean fastSyscall) { // The compilation of a syscall requires more stack size than usual maxStackSize = SYSCALL_MAX_STACK_SIZE; boolean needFirmwareVersionCheck = true; if (func.getFirmwareVersion() >= 999) { // Dummy version number meaning valid for all versions needFirmwareVersionCheck = false; } else if (isCodeInstructionInKernelMemory()) { // When compiling code in the kernel memory space, do not perform any version check. // This is used by overwritten HLE functions. needFirmwareVersionCheck = false; } else { // When compiling code loaded from flash0, do not perform any version check. // This is used by overwritten HLE functions. SceModule module = Managers.modules.getModuleByAddress(codeInstruction.getAddress()); if (module != null && module.pspfilename != null && module.pspfilename.startsWith("flash0:")) { if (log.isDebugEnabled()) { log.debug(String.format("syscall from a flash0 module(%s, '%s'), no firmware version check", module, module.pspfilename)); } needFirmwareVersionCheck = false; } } Label unsupportedVersionLabel = null; if (needFirmwareVersionCheck) { unsupportedVersionLabel = new Label(); loadImm(func.getFirmwareVersion()); mv.visitFieldInsn(Opcodes.GETSTATIC, runtimeContextInternalName, "firmwareVersion", "I"); mv.visitJumpInsn(Opcodes.IF_ICMPGT, unsupportedVersionLabel); } // Save the syscall parameter to locals for debugging if (!fastSyscall) { saveParametersToLocals(); } if (!fastSyscall) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "preSyscall", "()V"); } Label afterSyscallLabel = new Label(); if (func.checkInsideInterrupt()) { // if (IntrManager.getInstance().isInsideInterrupt()) { // if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) { // Modules.getLogger(func.getModuleName()).debug("<function name> return errorCode 0x80020064 (ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT)"); // } // cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT; // goto afterSyscall // } mv.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(IntrManager.class), "getInstance", "()" + Type.getDescriptor(IntrManager.class)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(IntrManager.class), "isInsideInterrupt", "()Z"); Label notInsideInterrupt = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, notInsideInterrupt); loadModuleLoggger(func); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "isDebugEnabled", "()Z"); Label notDebug = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, notDebug); loadModuleLoggger(func); mv.visitLdcInsn( String.format("%s returning errorCode 0x%08X (ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT)", func.getFunctionName(), SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "debug", "(" + Type.getDescriptor(Object.class) + ")V"); mv.visitLabel(notDebug); storeRegister(_v0, SceKernelErrors.ERROR_KERNEL_CANNOT_BE_CALLED_FROM_INTERRUPT); mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel); mv.visitLabel(notInsideInterrupt); } if (func.checkDispatchThreadEnabled()) { // if (!Modules.ThreadManForUserModule.isDispatchThreadEnabled() || !Interrupts.isInterruptsEnabled()) { // if (Modules.getLogger(func.getModuleName()).isDebugEnabled()) { // Modules.getLogger(func.getModuleName()).debug("<function name> return errorCode 0x800201A7 (ERROR_KERNEL_WAIT_CAN_NOT_WAIT)"); // } // cpu.gpr[_v0] = SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT; // goto afterSyscall // } loadModule("ThreadManForUser"); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(ThreadManForUser.class), "isDispatchThreadEnabled", "()Z"); Label returnError = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, returnError); loadProcessor(); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Processor.class), "isInterruptsEnabled", "()Z"); Label noError = new Label(); mv.visitJumpInsn(Opcodes.IFNE, noError); mv.visitLabel(returnError); loadModuleLoggger(func); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "isDebugEnabled", "()Z"); Label notDebug = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, notDebug); loadModuleLoggger(func); mv.visitLdcInsn(String.format("%s returning errorCode 0x%08X (ERROR_KERNEL_WAIT_CAN_NOT_WAIT)", func.getFunctionName(), SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT)); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "debug", "(" + Type.getDescriptor(Object.class) + ")V"); mv.visitLabel(notDebug); storeRegister(_v0, SceKernelErrors.ERROR_KERNEL_WAIT_CAN_NOT_WAIT); mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel); mv.visitLabel(noError); } logSyscallStart(func); if (func.hasStackUsage()) { loadMemory(); loadRegister(_sp); loadImm(func.getStackUsage()); mv.visitInsn(Opcodes.ISUB); loadImm(0); loadImm(func.getStackUsage()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, memoryInternalName, "memset", "(IBI)V"); } // Collecting the parameters and calling the module function... CompilerParameterReader parameterReader = new CompilerParameterReader(this); loadModule(func.getModuleName()); parameterReader.incrementCurrentStackSize(); Label tryStart = new Label(); Label tryEnd = new Label(); Label catchSceKernelErrorException = new Label(); mv.visitTryCatchBlock(tryStart, tryEnd, catchSceKernelErrorException, Type.getInternalName(SceKernelErrorException.class)); Class<?>[] parameterTypes = func.getHLEModuleMethod().getParameterTypes(); Class<?> returnType = func.getHLEModuleMethod().getReturnType(); StringBuilder methodDescriptor = new StringBuilder(); methodDescriptor.append("("); Annotation[][] paramsAnotations = func.getHLEModuleMethod().getParameterAnnotations(); int paramIndex = 0; for (Class<?> parameterType : parameterTypes) { methodDescriptor.append(Type.getDescriptor(parameterType)); loadParameter(parameterReader, func, parameterType, paramsAnotations[paramIndex], afterSyscallLabel, catchSceKernelErrorException); paramIndex++; } methodDescriptor.append(")"); methodDescriptor.append(Type.getDescriptor(returnType)); mv.visitLabel(tryStart); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(func.getHLEModuleMethod().getDeclaringClass()), func.getFunctionName(), methodDescriptor.toString()); storeReturnValue(func, returnType); if (parameterReader.hasErrorPointer()) { // errorPointer.setValue(0); mv.visitVarInsn(Opcodes.ALOAD, LOCAL_ERROR_POINTER); loadImm(0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(TErrorPointer32.class), "setValue", "(I)V"); } loadRegister(_v0); logSyscallEnd(func, false); mv.visitInsn(Opcodes.POP); mv.visitLabel(tryEnd); mv.visitJumpInsn(Opcodes.GOTO, afterSyscallLabel); // catch (SceKernelErrorException e) { // errorCode = e.errorCode; // if (Modules.log.isDebugEnabled()) { // Modules.log.debug(String.format("<function name> return errorCode 0x%08X", errorCode)); // } // if (hasErrorPointer()) { // errorPointer.setValue(errorCode); // cpu.gpr[_v0] = 0; // } else { // cpu.gpr[_v0] = errorCode; // } // } mv.visitLabel(catchSceKernelErrorException); mv.visitFieldInsn(Opcodes.GETFIELD, Type.getInternalName(SceKernelErrorException.class), "errorCode", "I"); logSyscallEnd(func, true); if (parameterReader.hasErrorPointer()) { // errorPointer.setValue(errorCode); // cpu.gpr[_v0] = 0; mv.visitVarInsn(Opcodes.ALOAD, LOCAL_ERROR_POINTER); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(TErrorPointer32.class), "setValue", "(I)V"); storeRegister(_v0, 0); } else { // cpu.gpr[_v0] = errorCode; storeRegister(_v0); } // Reload the $ra register, the stack is lost after an exception CodeInstruction previousInstruction = codeBlock.getCodeInstruction(codeInstruction.getAddress() - 4); if (previousInstruction != null && previousInstruction.getInsn() == Instructions.JR) { int jumpRegister = (previousInstruction.getOpcode() >> 21) & 0x1F; loadRegister(jumpRegister); } mv.visitLabel(afterSyscallLabel); if (fastSyscall) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "postSyscallFast", "()V"); } else { mv.visitMethodInsn(Opcodes.INVOKESTATIC, runtimeContextInternalName, "postSyscall", "()V"); } if (needFirmwareVersionCheck) { Label afterVersionCheckLabel = new Label(); mv.visitJumpInsn(Opcodes.GOTO, afterVersionCheckLabel); mv.visitLabel(unsupportedVersionLabel); loadModuleLoggger(func); mv.visitLdcInsn(String.format( "%s is not supported in firmware version %d, it requires at least firmware version %d", func.getFunctionName(), RuntimeContext.firmwareVersion, func.getFirmwareVersion())); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Logger.class), "warn", "(" + Type.getDescriptor(Object.class) + ")V"); storeRegister(_v0, -1); mv.visitLabel(afterVersionCheckLabel); } }
From source file:lucee.transformer.bytecode.statement.tag.TagGroupUtil.java
License:Open Source License
public static void writeOutTypeQuery(final TagGroup tag, BytecodeContext bc) throws BytecodeException { final GeneratorAdapter adapter = bc.getAdapter(); tag.setNumberIterator(adapter.newLocal(NUMBER_ITERATOR)); boolean isOutput = tag.getType() == TagGroup.TAG_OUTPUT; ParseBodyVisitor pbv = isOutput ? new ParseBodyVisitor() : null; if (isOutput) pbv.visitBegin(bc);/* w ww .jav a2s .c om*/ // Query query=pc.getQuery(@query); tag.setQuery(adapter.newLocal(Types.QUERY)); adapter.loadArg(0); Expression val = tag.getAttribute("query").getValue(); val.writeOut(bc, Expression.MODE_REF); if (val instanceof LitString) adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_QUERY_STRING); else adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_QUERY_OBJ); adapter.storeLocal(tag.getQuery()); tag.setPID(adapter.newLocal(Types.INT_VALUE)); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_ID); adapter.storeLocal(tag.getPID()); // int startAt=query.getCurrentrow(); final int startAt = adapter.newLocal(Types.INT_VALUE); adapter.loadLocal(tag.getQuery()); adapter.loadLocal(tag.getPID()); //adapter.loadArg(0); //adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_ID); adapter.invokeInterface(Types.QUERY, TagLoop.GET_CURRENTROW_1); adapter.storeLocal(startAt); // if(query.getRecordcount()>0) { DecisionIntVisitor div = new DecisionIntVisitor(); div.visitBegin(); adapter.loadLocal(tag.getQuery()); adapter.invokeInterface(Types.QUERY, GET_RECORDCOUNT); div.visitGT(); adapter.push(0); div.visitEnd(bc); Label ifRecCount = new Label(); adapter.ifZCmp(Opcodes.IFEQ, ifRecCount); // startrow int from = adapter.newLocal(Types.INT_VALUE); Attribute attrStartRow = tag.getAttribute("startrow"); if (attrStartRow != null) { // NumberRange.range(@startrow,1) //attrStartRow.getValue().writeOut(bc, Expression.MODE_VALUE); CastInt.toExprInt(attrStartRow.getValue()).writeOut(bc, Expression.MODE_VALUE); //adapter.visitInsn(Opcodes.D2I); adapter.push(1); adapter.invokeStatic(Types.NUMBER_RANGE, RANGE); //adapter.visitInsn(Opcodes.D2I); } else { adapter.push(1); } adapter.storeLocal(from); // numberIterator adapter.loadLocal(from); adapter.loadLocal(tag.getQuery()); adapter.invokeInterface(Types.QUERY, GET_RECORDCOUNT); //adapter.visitInsn(Opcodes.I2D); Attribute attrMaxRow = tag.getAttribute("maxrows"); Attribute attrEndRow = tag.getAttribute("endrow"); if (attrMaxRow != null) { CastInt.toExprInt(attrMaxRow.getValue()).writeOut(bc, Expression.MODE_VALUE); adapter.invokeStatic(NUMBER_ITERATOR, LOAD_MAX); } else if (attrEndRow != null) { CastInt.toExprInt(attrEndRow.getValue()).writeOut(bc, Expression.MODE_VALUE); adapter.invokeStatic(NUMBER_ITERATOR, LOAD_END); } else { adapter.invokeStatic(NUMBER_ITERATOR, LOAD_2); } adapter.storeLocal(tag.getNumberIterator()); // Group Attribute attrGroup = tag.getAttribute("group"); Attribute attrGroupCS = tag.getAttribute("groupcasesensitive"); tag.setGroup(adapter.newLocal(Types.STRING)); final int groupCaseSensitive = adapter.newLocal(Types.BOOLEAN_VALUE); if (attrGroup != null) { attrGroup.getValue().writeOut(bc, Expression.MODE_REF); adapter.storeLocal(tag.getGroup()); if (attrGroupCS != null) attrGroupCS.getValue().writeOut(bc, Expression.MODE_VALUE); else adapter.push(false); adapter.storeLocal(groupCaseSensitive); } // pc.us().addQuery(query); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, US); adapter.loadLocal(tag.getQuery()); adapter.invokeInterface(UNDEFINED, ADD_QUERY); // current final int current = adapter.newLocal(Types.INT_VALUE); adapter.loadLocal(from); adapter.push(1); adapter.visitInsn(Opcodes.ISUB); adapter.storeLocal(current); // Try TryFinallyVisitor tfv = new TryFinallyVisitor(new OnFinally() { public void _writeOut(BytecodeContext bc) { // query.reset(); // query.go(startAt); adapter.loadLocal(tag.getQuery()); adapter.loadLocal(startAt); adapter.loadLocal(tag.getPID()); //adapter.loadArg(0); //adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_ID); adapter.invokeInterface(Types.QUERY, TagLoop.GO); adapter.pop(); // pc.us().removeQuery(); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, US); adapter.invokeInterface(UNDEFINED, REMOVE_QUERY); // NumberIterator.release(ni); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeStatic(NUMBER_ITERATOR, REALEASE); } }, null); tfv.visitTryBegin(bc); WhileVisitor wv = new WhileVisitor(); if (tag instanceof TagLoop) ((TagLoop) tag).setLoopVisitor(wv); wv.visitBeforeExpression(bc); //while(ni.isValid()) { adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(current); adapter.push(1); adapter.visitInsn(Opcodes.IADD); adapter.invokeVirtual(NUMBER_ITERATOR, IS_VALID_1); wv.visitAfterExpressionBeforeBody(bc); // if(!query.go(ni.current()))break; adapter.loadLocal(tag.getQuery()); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.loadLocal(tag.getPID()); adapter.invokeInterface(Types.QUERY, TagLoop.GO); NotVisitor.visitNot(bc); Label _if = new Label(); adapter.ifZCmp(Opcodes.IFEQ, _if); wv.visitBreak(bc); adapter.visitLabel(_if); if (attrGroup != null) { // NumberIterator oldNi=numberIterator; int oldNi = adapter.newLocal(NUMBER_ITERATOR); adapter.loadLocal(tag.getNumberIterator()); adapter.storeLocal(oldNi); // numberIterator=NumberIterator.load(ni,query,group,grp_case); adapter.loadArg(0); adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(tag.getQuery()); adapter.loadLocal(tag.getGroup()); adapter.loadLocal(groupCaseSensitive); adapter.invokeStatic(NUMBER_ITERATOR, LOAD_5); adapter.storeLocal(tag.getNumberIterator()); // current=oldNi.current(); adapter.loadLocal(oldNi); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.storeLocal(current); tag.getBody().writeOut(bc); //tmp(adapter,current); // NumberIterator.release(ni); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeStatic(NUMBER_ITERATOR, REALEASE); // numberIterator=oldNi; adapter.loadLocal(oldNi); adapter.storeLocal(tag.getNumberIterator()); } else { // current=ni.current(); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.storeLocal(current); tag.getBody().writeOut(bc); } // ni.setCurrent(current+1); /*adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(current); adapter.push(1); adapter.visitInsn(Opcodes.IADD); adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT);*/ wv.visitAfterBody(bc, tag.getEnd()); tfv.visitTryEnd(bc); adapter.visitLabel(ifRecCount); if (isOutput) pbv.visitEnd(bc); }
From source file:lucee.transformer.bytecode.statement.tag.TagGroupUtil.java
License:Open Source License
public static void writeOutTypeGroup(TagGroup tag, BytecodeContext bc) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); boolean isOutput = tag.getType() == TagGroup.TAG_OUTPUT; ParseBodyVisitor pbv = isOutput ? new ParseBodyVisitor() : null; if (isOutput) pbv.visitBegin(bc);/* w w w .j a v a 2s . com*/ // Group Attribute attrGroup = tag.getAttribute("group"); tag.setGroup(adapter.newLocal(Types.STRING)); attrGroup.getValue().writeOut(bc, Expression.MODE_REF); adapter.storeLocal(tag.getGroup()); // Group Case Sensitve Attribute attrGroupCS = tag.getAttribute("groupcasesensitive"); int groupCaseSensitive = adapter.newLocal(Types.BOOLEAN_VALUE); if (attrGroupCS != null) attrGroupCS.getValue().writeOut(bc, Expression.MODE_VALUE); else adapter.push(true); adapter.storeLocal(groupCaseSensitive); TagGroup parent = getParentTagGroupQuery(tag, tag.getType()); tag.setNumberIterator(parent.getNumberIterator()); tag.setQuery(parent.getQuery()); //queryImpl = parent.getQueryImpl(); // current int current = adapter.newLocal(Types.INT_VALUE); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.storeLocal(current); // current int icurrent = adapter.newLocal(Types.INT_VALUE); adapter.loadLocal(current); adapter.push(1); adapter.visitInsn(Opcodes.ISUB); adapter.storeLocal(icurrent); WhileVisitor wv = new WhileVisitor(); if (tag instanceof TagLoop) ((TagLoop) tag).setLoopVisitor(wv); wv.visitBeforeExpression(bc); //while(ni.isValid()) { adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(icurrent); adapter.push(1); adapter.visitInsn(Opcodes.IADD); adapter.invokeVirtual(NUMBER_ITERATOR, IS_VALID_1); wv.visitAfterExpressionBeforeBody(bc); // if(!query.go(ni.current()))break; adapter.loadLocal(tag.getQuery()); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_ID); adapter.invokeInterface(Types.QUERY, TagLoop.GO); NotVisitor.visitNot(bc); Label _if = new Label(); adapter.ifZCmp(Opcodes.IFEQ, _if); wv.visitBreak(bc); adapter.visitLabel(_if); // NumberIterator oldNi=numberIterator; int oldNi = adapter.newLocal(NUMBER_ITERATOR); adapter.loadLocal(tag.getNumberIterator()); adapter.storeLocal(oldNi); // numberIterator=NumberIterator.load(ni,query,group,grp_case); adapter.loadArg(0); adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(tag.getQuery()); adapter.loadLocal(tag.getGroup()); adapter.loadLocal(groupCaseSensitive); adapter.invokeStatic(NUMBER_ITERATOR, LOAD_5); adapter.storeLocal(tag.getNumberIterator()); // current=oldNi.current(); adapter.loadLocal(oldNi); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.storeLocal(icurrent); tag.getBody().writeOut(bc); //tmp(adapter,current); // NumberIterator.release(ni); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeStatic(NUMBER_ITERATOR, REALEASE); // numberIterator=oldNi; adapter.loadLocal(oldNi); adapter.storeLocal(tag.getNumberIterator()); // ni.setCurrent(current+1); /*adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(icurrent); adapter.push(1); adapter.visitInsn(Opcodes.IADD); adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT); */ wv.visitAfterBody(bc, tag.getEnd()); //query.go(ni.current(),pc.getId()) resetCurrentrow(adapter, tag, current); // ni.first(); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, FIRST); adapter.pop(); if (isOutput) pbv.visitEnd(bc); }
From source file:lucee.transformer.bytecode.statement.tag.TagGroupUtil.java
License:Open Source License
public static void writeOutTypeInnerGroup(TagGroup tag, BytecodeContext bc) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); TagGroup parent = getParentTagGroupQuery(tag, tag.getType()); tag.setNumberIterator(parent.getNumberIterator()); tag.setQuery(parent.getQuery());/*from ww w . ja va2s .co m*/ //queryImpl = parent.getQueryImpl(); int current = adapter.newLocal(Types.INT_VALUE); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.storeLocal(current); // inner current int icurrent = adapter.newLocal(Types.INT_VALUE); adapter.loadLocal(current); adapter.push(1); adapter.visitInsn(Opcodes.ISUB); adapter.storeLocal(icurrent); WhileVisitor wv = new WhileVisitor(); if (tag instanceof TagLoop) ((TagLoop) tag).setLoopVisitor(wv); wv.visitBeforeExpression(bc); //while(ni.isValid()) { adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(icurrent); adapter.push(1); adapter.visitInsn(Opcodes.IADD); adapter.invokeVirtual(NUMBER_ITERATOR, IS_VALID_1); wv.visitAfterExpressionBeforeBody(bc); // if(!query.go(ni.current()))break; adapter.loadLocal(tag.getQuery()); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_ID); adapter.invokeInterface(Types.QUERY, TagLoop.GO); /*OLD adapter.invokeInterface(Types.QUERY, TagLoop.GO_1); */ NotVisitor.visitNot(bc); Label _if = new Label(); adapter.ifZCmp(Opcodes.IFEQ, _if); wv.visitBreak(bc); adapter.visitLabel(_if); // current=ni.current(); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.storeLocal(icurrent); tag.getBody().writeOut(bc); // ni.setCurrent(current+1); /*adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(icurrent); adapter.push(1); adapter.visitInsn(Opcodes.IADD); adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT);*/ wv.visitAfterBody(bc, tag.getEnd()); resetCurrentrow(adapter, tag, current); // ni.first(); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, FIRST); adapter.pop(); }
From source file:lucee.transformer.bytecode.statement.tag.TagGroupUtil.java
License:Open Source License
public static void writeOutTypeInnerQuery(TagGroup tag, BytecodeContext bc) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); //if(tr ue)return ; TagGroup parent = getParentTagGroupQuery(tag, tag.getType()); tag.setNumberIterator(parent.getNumberIterator()); tag.setQuery(parent.getQuery());//from w w w .j a v a 2 s .co m tag.setPID(parent.getPID()); //queryImpl = parent.getQueryImpl(); //int currentOuter=ni.current(); int current = adapter.newLocal(Types.INT_VALUE); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.storeLocal(current); // current int icurrent = adapter.newLocal(Types.INT_VALUE); adapter.loadLocal(current); adapter.push(1); adapter.visitInsn(Opcodes.ISUB); adapter.storeLocal(icurrent); WhileVisitor wv = new WhileVisitor(); if (tag instanceof TagLoop) ((TagLoop) tag).setLoopVisitor(wv); wv.visitBeforeExpression(bc); //while(ni.isValid()) { adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(icurrent); adapter.push(1); adapter.visitInsn(Opcodes.IADD); adapter.invokeVirtual(NUMBER_ITERATOR, IS_VALID_1); wv.visitAfterExpressionBeforeBody(bc); // if(!query.go(ni.current()))break; adapter.loadLocal(tag.getQuery()); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.loadLocal(tag.getPID()); adapter.invokeInterface(Types.QUERY, TagLoop.GO); NotVisitor.visitNot(bc); Label _if = new Label(); adapter.ifZCmp(Opcodes.IFEQ, _if); wv.visitBreak(bc); adapter.visitLabel(_if); // current=ni.current(); adapter.loadLocal(tag.getNumberIterator()); adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT); adapter.storeLocal(icurrent); tag.getBody().writeOut(bc); // ni.setCurrent(current+1); /*adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(icurrent); adapter.push(1); adapter.visitInsn(Opcodes.IADD); adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT);*/ wv.visitAfterBody(bc, tag.getEnd()); // ni.setCurrent(currentOuter); adapter.loadLocal(tag.getNumberIterator()); adapter.loadLocal(current); adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT); adapter.loadLocal(tag.getQuery()); adapter.loadLocal(current); adapter.loadLocal(tag.getPID()); //adapter.loadArg(0); //adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_ID); adapter.invokeInterface(Types.QUERY, TagLoop.GO); adapter.pop(); //adapter.pop(); }
From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java
License:Apache License
public void visitInsn(int opcode) { switch (opcode) { case Opcodes.NOP: break;/* ww w .ja v a2s . c o m*/ case Opcodes.ACONST_NULL: push("null", Object.class); break; case Opcodes.ICONST_M1: case Opcodes.ICONST_0: case Opcodes.ICONST_1: case Opcodes.ICONST_2: case Opcodes.ICONST_3: case Opcodes.ICONST_4: case Opcodes.ICONST_5: push(Integer.toString(opcode - Opcodes.ICONST_0), Type.INT_TYPE); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: push(Integer.toString(opcode - Opcodes.LCONST_0), Type.LONG_TYPE); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: push(Integer.toString(opcode - Opcodes.FCONST_0), Type.FLOAT_TYPE); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: push(Integer.toString(opcode - Opcodes.DCONST_0), Type.DOUBLE_TYPE); break; case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: { Type opType = getType(Opcodes.IALOAD, opcode); StackValue idx = pop(Type.INT_TYPE); StackValue arr = popArray(opType); push(arr.description + "[" + idx.description + "]", opType); } break; case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: { Type opType = getType(Opcodes.IASTORE, opcode); pop(opType); pop(Type.INT_TYPE); popArray(opType); } break; case Opcodes.POP: pop(); break; case Opcodes.POP2: pop(2); break; case Opcodes.DUP: push(peek()); break; case Opcodes.DUP2: push(peek(2)); push(peek(1)); break; case Opcodes.DUP_X1: { StackValue a = pop(); StackValue b = pop(); push(a); push(b); push(a); } break; case Opcodes.DUP_X2: { StackValue a = pop(); StackValue b = pop(); StackValue c = pop(); push(a); push(c); push(b); push(a); } break; case Opcodes.DUP2_X1: { StackValue a = popValue(false); StackValue b = pop(); StackValue c = pop(); push(b); push(a); push(c); push(b); push(a); } case Opcodes.DUP2_X2: { StackValue a = popValue(false); StackValue b = pop(); StackValue c = popValue(false); StackValue d = pop(); push(b); push(a); push(d); push(c); push(b); push(a); } break; case Opcodes.SWAP: { StackValue a = pop(); StackValue b = pop(); push(a); push(b); } break; case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: math(Opcodes.IADD, opcode, "+"); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: math(Opcodes.ISUB, opcode, "-"); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: math(Opcodes.IMUL, opcode, "*"); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: math(Opcodes.IDIV, opcode, "/"); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: math(Opcodes.IREM, opcode, "%"); break; case Opcodes.IAND: case Opcodes.LAND: math(Opcodes.IAND, opcode, "&"); break; case Opcodes.IOR: case Opcodes.LOR: math(Opcodes.IOR, opcode, "|"); break; case Opcodes.IXOR: case Opcodes.LXOR: math(Opcodes.IXOR, opcode, "^"); break; case Opcodes.INEG: case Opcodes.LNEG: case Opcodes.FNEG: case Opcodes.DNEG: { Type type = getType(Opcodes.INEG, opcode); StackValue a = pop(type); push("-" + a.description, type); } break; case Opcodes.ISHL: case Opcodes.LSHL: { Type type = getType(Opcodes.ISHL, opcode); StackValue n = pop(Type.INT_TYPE); StackValue a = pop(type); push(a.description + "<<" + n.description, type); } break; case Opcodes.ISHR: case Opcodes.LSHR: { Type type = getType(Opcodes.ISHR, opcode); StackValue n = pop(Type.INT_TYPE); StackValue a = pop(type); push(a.description + ">>" + n.description, type); } break; case Opcodes.IUSHR: case Opcodes.LUSHR: { Type type = getType(Opcodes.IUSHR, opcode); StackValue n = pop(Type.INT_TYPE); StackValue a = pop(type); push(a.description + ">>>" + n.description, type); } case Opcodes.LCMP: { StackValue a = pop(Type.LONG_TYPE); StackValue b = pop(Type.LONG_TYPE); push(a.description + " cmp " + b.description + " {-1|0|1}", Type.LONG_TYPE); } break; case Opcodes.I2L: case Opcodes.I2F: case Opcodes.I2D: case Opcodes.L2I: case Opcodes.L2F: case Opcodes.L2D: case Opcodes.F2I: case Opcodes.F2L: case Opcodes.F2D: case Opcodes.D2I: case Opcodes.D2L: case Opcodes.D2F: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: cast(opcode); break; case Opcodes.ARETURN: case Opcodes.ATHROW: popObject(); break; case Opcodes.RETURN: break; default: throw new IllegalArgumentException("Unsupported opcode " + opcode + " - " + OPCODES[opcode]); } print(opcode, ""); /* * FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN, * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW, * MONITORENTER, or MONITOREXIT */ }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitInsn(final int opcode) { T t = null;//from w w w .j a v a 2 s . co m int iValue = Integer.MIN_VALUE; Object oValue = null; switch (opcode) { case Opcodes.NOP: // nothing to do, ignore break; /******* * ADD * *******/ case Opcodes.DADD: t = T.DOUBLE; // fall through case Opcodes.FADD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IADD: if (t == null) { t = T.INT; } // fall through case Opcodes.LADD: if (t == null) { t = T.LONG; } add(new ADD(this.ops.size(), opcode, this.line, t)); break; /********* * ALOAD * *********/ case Opcodes.AALOAD: t = T.REF; // fall through case Opcodes.BALOAD: if (t == null) { t = T.SMALL; } // fall through case Opcodes.CALOAD: if (t == null) { t = T.CHAR; } // fall through case Opcodes.DALOAD: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FALOAD: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IALOAD: if (t == null) { t = T.INT; } // fall through case Opcodes.LALOAD: if (t == null) { t = T.LONG; } // fall through case Opcodes.SALOAD: if (t == null) { t = T.SHORT; } add(new ALOAD(this.ops.size(), opcode, this.line, t)); break; /******* * AND * *******/ case Opcodes.IAND: t = T.AINT; // fall through case Opcodes.LAND: if (t == null) { t = T.LONG; } add(new AND(this.ops.size(), opcode, this.line, t)); break; /*************** * ARRAYLENGTH * ***************/ case Opcodes.ARRAYLENGTH: add(new ARRAYLENGTH(this.ops.size(), opcode, this.line)); break; /********** * ASTORE * **********/ case Opcodes.AASTORE: t = T.REF; // fall through case Opcodes.BASTORE: if (t == null) { t = T.SMALL; } // fall through case Opcodes.CASTORE: if (t == null) { t = T.CHAR; } // fall through case Opcodes.DASTORE: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FASTORE: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IASTORE: if (t == null) { t = T.INT; } // fall through case Opcodes.LASTORE: if (t == null) { t = T.LONG; } // fall through case Opcodes.SASTORE: if (t == null) { t = T.SHORT; } add(new ASTORE(this.ops.size(), opcode, this.line, t)); break; /******** * CAST * ********/ case Opcodes.D2F: t = T.DOUBLE; oValue = T.FLOAT; // fall through case Opcodes.D2I: if (t == null) { t = T.DOUBLE; oValue = T.INT; } // fall through case Opcodes.D2L: if (t == null) { t = T.DOUBLE; oValue = T.LONG; } // fall through case Opcodes.F2D: if (t == null) { t = T.FLOAT; oValue = T.DOUBLE; } // fall through case Opcodes.F2I: if (t == null) { t = T.FLOAT; oValue = T.INT; } // fall through case Opcodes.F2L: if (t == null) { t = T.FLOAT; oValue = T.LONG; } // fall through case Opcodes.I2B: if (t == null) { t = T.INT; oValue = T.BYTE; } // fall through case Opcodes.I2C: if (t == null) { t = T.INT; oValue = T.CHAR; } // fall through case Opcodes.I2D: if (t == null) { t = T.INT; oValue = T.DOUBLE; } // fall through case Opcodes.I2F: if (t == null) { t = T.INT; oValue = T.FLOAT; } // fall through case Opcodes.I2L: if (t == null) { t = T.INT; oValue = T.LONG; } // fall through case Opcodes.I2S: if (t == null) { t = T.INT; oValue = T.SHORT; } // fall through case Opcodes.L2D: if (t == null) { t = T.LONG; oValue = T.DOUBLE; } // fall through case Opcodes.L2F: if (t == null) { t = T.LONG; oValue = T.FLOAT; } // fall through case Opcodes.L2I: if (t == null) { t = T.LONG; oValue = T.INT; } assert oValue instanceof T; add(new CAST(this.ops.size(), opcode, this.line, t, (T) oValue)); break; /******* * CMP * *******/ case Opcodes.DCMPG: t = T.DOUBLE; iValue = CMP.T_G; // fall through case Opcodes.DCMPL: if (t == null) { t = T.DOUBLE; iValue = CMP.T_L; } // fall through case Opcodes.FCMPG: if (t == null) { t = T.FLOAT; iValue = CMP.T_G; } // fall through case Opcodes.FCMPL: if (t == null) { t = T.FLOAT; iValue = CMP.T_L; } // fall through case Opcodes.LCMP: if (t == null) { t = T.LONG; iValue = CMP.T_0; } add(new CMP(this.ops.size(), opcode, this.line, t, iValue)); break; /******* * DIV * *******/ case Opcodes.DDIV: t = T.DOUBLE; // fall through case Opcodes.FDIV: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IDIV: if (t == null) { t = T.INT; } // fall through case Opcodes.LDIV: if (t == null) { t = T.LONG; } add(new DIV(this.ops.size(), opcode, this.line, t)); break; /******* * DUP * *******/ case Opcodes.DUP: oValue = DUP.Kind.DUP; // fall through case Opcodes.DUP_X1: if (oValue == null) { oValue = DUP.Kind.DUP_X1; } // fall through case Opcodes.DUP_X2: if (oValue == null) { oValue = DUP.Kind.DUP_X2; } // fall through case Opcodes.DUP2: if (oValue == null) { oValue = DUP.Kind.DUP2; } // fall through case Opcodes.DUP2_X1: if (oValue == null) { oValue = DUP.Kind.DUP2_X1; } // fall through case Opcodes.DUP2_X2: if (oValue == null) { oValue = DUP.Kind.DUP2_X2; } add(new DUP(this.ops.size(), opcode, this.line, (DUP.Kind) oValue)); break; /*********** * MONITOR * ***********/ case Opcodes.MONITORENTER: oValue = MONITOR.Kind.ENTER; // fall through case Opcodes.MONITOREXIT: if (oValue == null) { oValue = MONITOR.Kind.EXIT; } add(new MONITOR(this.ops.size(), opcode, this.line, (MONITOR.Kind) oValue)); break; /******* * MUL * *******/ case Opcodes.DMUL: t = T.DOUBLE; // fall through case Opcodes.FMUL: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IMUL: if (t == null) { t = T.INT; } // fall through case Opcodes.LMUL: if (t == null) { t = T.LONG; } add(new MUL(this.ops.size(), opcode, this.line, t)); break; /******* * NEG * *******/ case Opcodes.DNEG: t = T.DOUBLE; // fall through case Opcodes.FNEG: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.INEG: if (t == null) { t = T.INT; } // fall through case Opcodes.LNEG: if (t == null) { t = T.LONG; } add(new NEG(this.ops.size(), opcode, this.line, t)); break; /****** * OR * ******/ case Opcodes.IOR: t = T.AINT; // fall through case Opcodes.LOR: if (t == null) { t = T.LONG; } add(new OR(this.ops.size(), opcode, this.line, t)); break; /******* * POP * *******/ case Opcodes.POP: oValue = POP.Kind.POP; // fall through case Opcodes.POP2: if (oValue == null) { oValue = POP.Kind.POP2; } add(new POP(this.ops.size(), opcode, this.line, (POP.Kind) oValue)); break; /******** * PUSH * ********/ case Opcodes.ACONST_NULL: t = T.REF; // fall through case Opcodes.DCONST_0: if (t == null) { oValue = 0D; t = T.DOUBLE; } // fall through case Opcodes.FCONST_0: if (t == null) { oValue = 0F; t = T.FLOAT; } // fall through case Opcodes.ICONST_0: if (t == null) { oValue = 0; t = T.getJvmIntT(0); } // fall through case Opcodes.LCONST_0: if (t == null) { oValue = 0L; t = T.LONG; } // fall through case Opcodes.DCONST_1: if (t == null) { oValue = 1D; t = T.DOUBLE; } // fall through case Opcodes.FCONST_1: if (t == null) { oValue = 1F; t = T.FLOAT; } // fall through case Opcodes.ICONST_1: if (t == null) { oValue = 1; t = T.getJvmIntT(1); } // fall through case Opcodes.LCONST_1: if (t == null) { oValue = 1L; t = T.LONG; } // fall through case Opcodes.FCONST_2: if (t == null) { oValue = 2F; t = T.FLOAT; } // fall through case Opcodes.ICONST_2: if (t == null) { oValue = 2; t = T.getJvmIntT(2); } // fall through case Opcodes.ICONST_3: if (t == null) { oValue = 3; t = T.getJvmIntT(3); } // fall through case Opcodes.ICONST_4: if (t == null) { oValue = 4; t = T.getJvmIntT(4); } // fall through case Opcodes.ICONST_5: if (t == null) { oValue = 5; t = T.getJvmIntT(5); } // fall through case Opcodes.ICONST_M1: if (t == null) { oValue = -1; t = T.getJvmIntT(-1); } add(new PUSH(this.ops.size(), opcode, this.line, t, oValue)); break; /******* * REM * *******/ case Opcodes.DREM: t = T.DOUBLE; // fall through case Opcodes.FREM: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IREM: if (t == null) { t = T.INT; } // fall through case Opcodes.LREM: if (t == null) { t = T.LONG; } add(new REM(this.ops.size(), opcode, this.line, t)); break; /********** * RETURN * **********/ case Opcodes.ARETURN: t = T.REF; // fall through case Opcodes.DRETURN: if (t == null) { t = T.DOUBLE; } // fall through case Opcodes.FRETURN: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.IRETURN: if (t == null) { t = T.AINT; } // fall through case Opcodes.LRETURN: if (t == null) { t = T.LONG; } // fall through case Opcodes.RETURN: if (t == null) { t = T.VOID; } add(new RETURN(this.ops.size(), opcode, this.line, t)); break; /******* * SHL * *******/ case Opcodes.ISHL: t = T.INT; // fall through case Opcodes.LSHL: if (t == null) { t = T.LONG; } add(new SHL(this.ops.size(), opcode, this.line, t, T.INT)); break; /******* * SHR * *******/ case Opcodes.ISHR: case Opcodes.IUSHR: t = T.INT; // fall through case Opcodes.LSHR: case Opcodes.LUSHR: if (t == null) { t = T.LONG; } add(new SHR(this.ops.size(), opcode, this.line, t, T.INT, opcode == Opcodes.IUSHR || opcode == Opcodes.LUSHR)); break; /******* * SUB * *******/ case Opcodes.DSUB: t = T.DOUBLE; // fall through case Opcodes.FSUB: if (t == null) { t = T.FLOAT; } // fall through case Opcodes.ISUB: if (t == null) { t = T.INT; } // fall through case Opcodes.LSUB: if (t == null) { t = T.LONG; } add(new SUB(this.ops.size(), opcode, this.line, t)); break; /******** * SWAP * ********/ case Opcodes.SWAP: add(new SWAP(this.ops.size(), opcode, this.line)); break; /********* * THROW * *********/ case Opcodes.ATHROW: add(new THROW(this.ops.size(), opcode, this.line)); break; /******* * XOR * *******/ case Opcodes.IXOR: t = T.AINT; // fall through case Opcodes.LXOR: { if (t == null) { t = T.LONG; } add(new XOR(this.ops.size(), opcode, this.line, t)); break; } default: log.warn(getM() + ": Unknown insn opcode '" + opcode + "'!"); } }
From source file:org.evosuite.instrumentation.error.ErrorConditionChecker.java
License:Open Source License
/** * <p>// w w w. j av a 2 s . co m * overflowDistance * </p> * * @param op1 * a int. * @param op2 * a int. * @param opcode * a int. * @return a int. */ public static int overflowDistance(int op1, int op2, int opcode) { switch (opcode) { case Opcodes.IADD: int result = overflowDistanceAdd(op1, op2); logger.debug("O: " + op1 + " + " + op2 + " = " + (op1 + op2) + " -> " + result); return result; case Opcodes.ISUB: return overflowDistanceSub(op1, op2); case Opcodes.IMUL: return overflowDistanceMul(op1, op2); case Opcodes.IDIV: return overflowDistanceDiv(op1, op2); } return Integer.MAX_VALUE; }
From source file:org.evosuite.instrumentation.error.ErrorConditionChecker.java
License:Open Source License
public static int underflowDistance(int op1, int op2, int opcode) { switch (opcode) { case Opcodes.IADD: int result = underflowDistanceAdd(op1, op2); logger.debug("U: " + op1 + " + " + op2 + " = " + (op1 + op2) + " -> " + result); return result; case Opcodes.ISUB: return underflowDistanceSub(op1, op2); case Opcodes.IMUL: return underflowDistanceMul(op1, op2); }// w w w . j a v a 2s .c om return Integer.MAX_VALUE; }
From source file:org.evosuite.instrumentation.error.OverflowInstrumentation.java
License:Open Source License
@Override public void visitInsn(int opcode) { // Overflow checks switch (opcode) { case Opcodes.IADD: case Opcodes.ISUB: case Opcodes.IMUL: mv.visitInsn(Opcodes.DUP2);// ww w . j a v a2 s . com mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(III)I", false); insertBranchWithoutException(Opcodes.IFGT); case Opcodes.IDIV: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(III)I", false); insertBranchWithoutException(Opcodes.IFGT); break; case Opcodes.FADD: case Opcodes.FSUB: case Opcodes.FMUL: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(FFI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.FDIV: mv.visitInsn(Opcodes.DUP2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(FFI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; case Opcodes.DADD: case Opcodes.DSUB: case Opcodes.DMUL: int loc = mv.newLocal(Type.DOUBLE_TYPE); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(DDI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.DDIV: loc = mv.newLocal(Type.DOUBLE_TYPE); mv.storeLocal(loc); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(DDI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; case Opcodes.LADD: case Opcodes.LSUB: case Opcodes.LMUL: int loc2 = mv.newLocal(Type.LONG_TYPE); mv.storeLocal(loc2); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc2); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "underflowDistance", "(JJI)I", false); insertBranchWithoutException(Opcodes.IFGE); case Opcodes.LDIV: loc2 = mv.newLocal(Type.LONG_TYPE); mv.storeLocal(loc2); mv.visitInsn(Opcodes.DUP2); mv.loadLocal(loc2); mv.visitInsn(Opcodes.DUP2_X2); mv.visitLdcInsn(opcode); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CHECKER, "overflowDistance", "(JJI)I", false); insertBranchWithoutException(Opcodes.IFGE); break; } }