List of usage examples for org.objectweb.asm Opcodes LOR
int LOR
To view the source code for org.objectweb.asm Opcodes LOR.
Click Source Link
From source file:edu.mit.streamjit.util.bytecode.MethodResolver.java
License:Open Source License
private void interpret(InsnNode insn, FrameState frame, BBInfo block) { ReturnType returnType = block.block.getParent().getType().getReturnType(); switch (insn.getOpcode()) { case Opcodes.NOP: break;// ww w.j ava 2 s .c o m //<editor-fold defaultstate="collapsed" desc="Stack manipulation opcodes (pop, dup, swap)"> case Opcodes.POP: assert frame.stack.peek().getType().getCategory() == 1; frame.stack.pop(); break; case Opcodes.POP2: final int[][][] pop2Permutations = { { { 1, 1 }, {} }, { { 2 }, {} } }; conditionallyPermute(frame, pop2Permutations); break; case Opcodes.DUP: final int[][][] dupPermutations = { { { 1 }, { 1, 1 } } }; conditionallyPermute(frame, dupPermutations); break; case Opcodes.DUP_X1: final int[][][] dup_x1Permutations = { { { 1, 1 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup_x1Permutations); break; case Opcodes.DUP_X2: final int[][][] dup_x2Permutations = { { { 1, 1, 1 }, { 1, 3, 2, 1 } }, { { 1, 2 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup_x2Permutations); break; case Opcodes.DUP2: final int[][][] dup2Permutations = { { { 1, 1 }, { 2, 1, 2, 1 } }, { { 2 }, { 1, 1 } } }; conditionallyPermute(frame, dup2Permutations); break; case Opcodes.DUP2_X1: final int[][][] dup2_x1Permutations = { { { 1, 1, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 1 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup2_x1Permutations); break; case Opcodes.DUP2_X2: final int[][][] dup2_x2Permutations = { { { 1, 1, 1, 1 }, { 2, 1, 4, 3, 2, 1 } }, { { 2, 1, 1 }, { 1, 3, 2, 1 } }, { { 3, 2, 1 }, { 2, 1, 3, 2, 1 } }, { { 2, 2 }, { 1, 2, 1 } } }; conditionallyPermute(frame, dup2_x2Permutations); break; case Opcodes.SWAP: final int[][][] swapPermutations = { { { 1, 1 }, { 1, 2 } } }; conditionallyPermute(frame, swapPermutations); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Constant-stacking opcodes (iconst_0, etc.; see also bipush, sipush)"> case Opcodes.ACONST_NULL: frame.stack.push(module.constants().getNullConstant()); break; case Opcodes.ICONST_M1: frame.stack.push(module.constants().getSmallestIntConstant(-1)); break; case Opcodes.ICONST_0: frame.stack.push(module.constants().getSmallestIntConstant(0)); break; case Opcodes.ICONST_1: frame.stack.push(module.constants().getSmallestIntConstant(1)); break; case Opcodes.ICONST_2: frame.stack.push(module.constants().getSmallestIntConstant(2)); break; case Opcodes.ICONST_3: frame.stack.push(module.constants().getSmallestIntConstant(3)); break; case Opcodes.ICONST_4: frame.stack.push(module.constants().getSmallestIntConstant(4)); break; case Opcodes.ICONST_5: frame.stack.push(module.constants().getSmallestIntConstant(5)); break; case Opcodes.LCONST_0: frame.stack.push(module.constants().getConstant(0L)); break; case Opcodes.LCONST_1: frame.stack.push(module.constants().getConstant(1L)); break; case Opcodes.FCONST_0: frame.stack.push(module.constants().getConstant(0f)); break; case Opcodes.FCONST_1: frame.stack.push(module.constants().getConstant(1f)); break; case Opcodes.FCONST_2: frame.stack.push(module.constants().getConstant(2f)); break; case Opcodes.DCONST_0: frame.stack.push(module.constants().getConstant(0d)); break; case Opcodes.DCONST_1: frame.stack.push(module.constants().getConstant(1d)); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Return opcodes"> case Opcodes.IRETURN: assert returnType.isSubtypeOf(typeFactory.getType(int.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.LRETURN: assert returnType.isSubtypeOf(typeFactory.getType(long.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.FRETURN: assert returnType.isSubtypeOf(typeFactory.getType(float.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.DRETURN: assert returnType.isSubtypeOf(typeFactory.getType(double.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.ARETURN: assert returnType.isSubtypeOf(typeFactory.getType(Object.class)); assert frame.stack.peek().getType().isSubtypeOf(returnType); block.block.instructions().add(new ReturnInst(returnType, frame.stack.pop())); break; case Opcodes.RETURN: assert returnType instanceof VoidType || method.isConstructor(); block.block.instructions().add(new ReturnInst(typeFactory.getVoidType())); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Unary math opcodes (negation)"> //Unary minus is rendered as a multiplication by -1. (The obvious //other choice, subtraction from 0, is not equivalent for floats and //doubles due to negative zero.) case Opcodes.INEG: frame.stack.push(module.constants().getSmallestIntConstant(-1)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.LNEG: frame.stack.push(module.constants().getConstant(-1L)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.FNEG: frame.stack.push(module.constants().getConstant(-1f)); binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.DNEG: frame.stack.push(module.constants().getConstant(-1d)); binary(BinaryInst.Operation.MUL, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Binary math opcodes"> case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: binary(BinaryInst.Operation.ADD, frame, block); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: binary(BinaryInst.Operation.SUB, frame, block); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: binary(BinaryInst.Operation.MUL, frame, block); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: binary(BinaryInst.Operation.DIV, frame, block); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: binary(BinaryInst.Operation.REM, frame, block); break; case Opcodes.ISHL: case Opcodes.LSHL: binary(BinaryInst.Operation.SHL, frame, block); break; case Opcodes.ISHR: case Opcodes.LSHR: binary(BinaryInst.Operation.SHR, frame, block); break; case Opcodes.IUSHR: case Opcodes.LUSHR: binary(BinaryInst.Operation.USHR, frame, block); break; case Opcodes.IAND: case Opcodes.LAND: binary(BinaryInst.Operation.AND, frame, block); break; case Opcodes.IOR: case Opcodes.LOR: binary(BinaryInst.Operation.OR, frame, block); break; case Opcodes.IXOR: case Opcodes.LXOR: binary(BinaryInst.Operation.XOR, frame, block); break; case Opcodes.LCMP: case Opcodes.FCMPL: case Opcodes.DCMPL: binary(BinaryInst.Operation.CMP, frame, block); break; case Opcodes.FCMPG: case Opcodes.DCMPG: binary(BinaryInst.Operation.CMPG, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Primitive casts"> case Opcodes.I2L: cast(int.class, long.class, frame, block); break; case Opcodes.I2F: cast(int.class, float.class, frame, block); break; case Opcodes.I2D: cast(int.class, double.class, frame, block); break; case Opcodes.L2I: cast(long.class, int.class, frame, block); break; case Opcodes.L2F: cast(long.class, float.class, frame, block); break; case Opcodes.L2D: cast(long.class, double.class, frame, block); break; case Opcodes.F2I: cast(float.class, int.class, frame, block); break; case Opcodes.F2L: cast(float.class, long.class, frame, block); break; case Opcodes.F2D: cast(float.class, double.class, frame, block); break; case Opcodes.D2I: cast(double.class, int.class, frame, block); break; case Opcodes.D2L: cast(double.class, long.class, frame, block); break; case Opcodes.D2F: cast(double.class, float.class, frame, block); break; case Opcodes.I2B: cast(int.class, byte.class, frame, block); break; case Opcodes.I2C: cast(int.class, char.class, frame, block); break; case Opcodes.I2S: cast(int.class, short.class, frame, block); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Array store opcodes"> case Opcodes.IASTORE: case Opcodes.LASTORE: case Opcodes.FASTORE: case Opcodes.DASTORE: case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.SASTORE: Value data = frame.stack.pop(); Value index = frame.stack.pop(); Value array = frame.stack.pop(); ArrayStoreInst asi = new ArrayStoreInst(array, index, data); block.block.instructions().add(asi); break; //</editor-fold> //<editor-fold defaultstate="collapsed" desc="Array load opcodes"> case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: Value index2 = frame.stack.pop(); Value array2 = frame.stack.pop(); ArrayLoadInst ali = new ArrayLoadInst(array2, index2); block.block.instructions().add(ali); frame.stack.push(ali); break; //</editor-fold> case Opcodes.ARRAYLENGTH: ArrayLengthInst lengthInst = new ArrayLengthInst(frame.stack.pop()); block.block.instructions().add(lengthInst); frame.stack.push(lengthInst); break; case Opcodes.ATHROW: block.block.instructions().add(new ThrowInst(frame.stack.pop())); break; default: throw new UnsupportedOperationException("" + insn.getOpcode()); } }
From source file:edu.mit.streamjit.util.bytecode.MethodUnresolver.java
License:Open Source License
private void emit(BinaryInst i, InsnList insns) { load(i.getOperand(0), insns);//w w w . jav a 2s.c om load(i.getOperand(1), insns); int opcode = 0; if (i.getOperand(0).getType().isSubtypeOf(intType)) { switch (i.getOperation()) { case ADD: opcode = Opcodes.IADD; break; case SUB: opcode = Opcodes.ISUB; break; case MUL: opcode = Opcodes.IMUL; break; case DIV: opcode = Opcodes.IDIV; break; case REM: opcode = Opcodes.IREM; break; case SHL: opcode = Opcodes.ISHL; break; case SHR: opcode = Opcodes.ISHR; break; case USHR: opcode = Opcodes.ISHR; break; case AND: opcode = Opcodes.IAND; break; case OR: opcode = Opcodes.IOR; break; case XOR: opcode = Opcodes.IXOR; break; default: throw new AssertionError(i); } } else if (i.getOperand(0).getType().equals(longType)) { switch (i.getOperation()) { case ADD: opcode = Opcodes.LADD; break; case SUB: opcode = Opcodes.LSUB; break; case MUL: opcode = Opcodes.LMUL; break; case DIV: opcode = Opcodes.LDIV; break; case REM: opcode = Opcodes.LREM; break; case SHL: opcode = Opcodes.LSHL; break; case SHR: opcode = Opcodes.LSHR; break; case USHR: opcode = Opcodes.LSHR; break; case AND: opcode = Opcodes.LAND; break; case OR: opcode = Opcodes.LOR; break; case XOR: opcode = Opcodes.LXOR; break; case CMP: opcode = Opcodes.LCMP; break; default: throw new AssertionError(i); } } else if (i.getOperand(0).getType().equals(floatType)) { switch (i.getOperation()) { case ADD: opcode = Opcodes.FADD; break; case SUB: opcode = Opcodes.FSUB; break; case MUL: opcode = Opcodes.FMUL; break; case DIV: opcode = Opcodes.FDIV; break; case REM: opcode = Opcodes.FREM; break; case CMP: opcode = Opcodes.FCMPL; break; case CMPG: opcode = Opcodes.FCMPG; break; default: throw new AssertionError(i); } } else if (i.getOperand(0).getType().equals(doubleType)) { switch (i.getOperation()) { case ADD: opcode = Opcodes.DADD; break; case SUB: opcode = Opcodes.DSUB; break; case MUL: opcode = Opcodes.DMUL; break; case DIV: opcode = Opcodes.DDIV; break; case REM: opcode = Opcodes.DREM; break; case CMP: opcode = Opcodes.DCMPL; break; case CMPG: opcode = Opcodes.DCMPG; break; default: throw new AssertionError(i); } } else throw new AssertionError(i); insns.add(new InsnNode(opcode)); store(i, insns); }
From source file:org.adjective.stout.tools.StackVisualiserMethodVisitor.java
License:Apache License
public void visitInsn(int opcode) { switch (opcode) { case Opcodes.NOP: break;/* w ww .j av a 2s.c om*/ 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.apache.lucene.expressions.js.JavascriptCompiler.java
License:Apache License
/** * Sends the bytecode of class file to {@link ClassWriter}. *//* w ww . j a v a 2 s .co m*/ private void generateClass(final ParseTree parseTree, final ClassWriter classWriter, final Map<String, Integer> externalsMap) throws ParseException { classWriter.visit(CLASSFILE_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_FINAL, COMPILED_EXPRESSION_INTERNAL, null, EXPRESSION_TYPE.getInternalName(), null); final String clippedSourceText = (sourceText.length() <= MAX_SOURCE_LENGTH) ? sourceText : (sourceText.substring(0, MAX_SOURCE_LENGTH - 3) + "..."); classWriter.visitSource(clippedSourceText, null); final GeneratorAdapter constructor = new GeneratorAdapter(Opcodes.ACC_PUBLIC, EXPRESSION_CTOR, null, null, classWriter); constructor.loadThis(); constructor.loadArgs(); constructor.invokeConstructor(EXPRESSION_TYPE, EXPRESSION_CTOR); constructor.returnValue(); constructor.endMethod(); final GeneratorAdapter gen = new GeneratorAdapter(Opcodes.ACC_PUBLIC, EVALUATE_METHOD, null, null, classWriter); // to completely hide the ANTLR visitor we use an anonymous impl: new JavascriptBaseVisitor<Void>() { private final Deque<Type> typeStack = new ArrayDeque<>(); @Override public Void visitCompile(JavascriptParser.CompileContext ctx) { typeStack.push(Type.DOUBLE_TYPE); visit(ctx.expression()); typeStack.pop(); return null; } @Override public Void visitPrecedence(JavascriptParser.PrecedenceContext ctx) { visit(ctx.expression()); return null; } @Override public Void visitNumeric(JavascriptParser.NumericContext ctx) { if (ctx.HEX() != null) { pushLong(Long.parseLong(ctx.HEX().getText().substring(2), 16)); } else if (ctx.OCTAL() != null) { pushLong(Long.parseLong(ctx.OCTAL().getText().substring(1), 8)); } else if (ctx.DECIMAL() != null) { gen.push(Double.parseDouble(ctx.DECIMAL().getText())); gen.cast(Type.DOUBLE_TYPE, typeStack.peek()); } else { throw new IllegalStateException("Unknown operation specified: " + ctx.getText()); } return null; } @Override public Void visitExternal(JavascriptParser.ExternalContext ctx) { String text = ctx.VARIABLE().getText(); int arguments = ctx.expression().size(); boolean parens = ctx.LP() != null && ctx.RP() != null; Method method = parens ? functions.get(text) : null; try { if (method != null) { int arity = method.getParameterTypes().length; if (arguments != arity) { throw new ParseException("Invalid expression '" + sourceText + "': Expected (" + arity + ") arguments for function call (" + text + "), but found (" + arguments + ").", ctx.start.getStartIndex()); } typeStack.push(Type.DOUBLE_TYPE); for (int argument = 0; argument < arguments; ++argument) { visit(ctx.expression(argument)); } typeStack.pop(); gen.invokeStatic(Type.getType(method.getDeclaringClass()), org.objectweb.asm.commons.Method.getMethod(method)); gen.cast(Type.DOUBLE_TYPE, typeStack.peek()); } else if (!parens || arguments == 0 && text.contains(".")) { int index; text = normalizeQuotes(ctx.getText()); if (externalsMap.containsKey(text)) { index = externalsMap.get(text); } else { index = externalsMap.size(); externalsMap.put(text, index); } gen.loadArg(0); gen.push(index); gen.arrayLoad(FUNCTION_VALUES_TYPE); gen.invokeVirtual(FUNCTION_VALUES_TYPE, DOUBLE_VAL_METHOD); gen.cast(Type.DOUBLE_TYPE, typeStack.peek()); } else { throw new ParseException("Invalid expression '" + sourceText + "': Unrecognized function call (" + text + ").", ctx.start.getStartIndex()); } return null; } catch (ParseException e) { // The API doesn't allow checked exceptions here, so propagate up the stack. This is unwrapped // in getAntlrParseTree. throw new RuntimeException(e); } } @Override public Void visitUnary(JavascriptParser.UnaryContext ctx) { if (ctx.BOOLNOT() != null) { Label labelNotTrue = new Label(); Label labelNotReturn = new Label(); typeStack.push(Type.INT_TYPE); visit(ctx.expression()); typeStack.pop(); gen.visitJumpInsn(Opcodes.IFEQ, labelNotTrue); pushBoolean(false); gen.goTo(labelNotReturn); gen.visitLabel(labelNotTrue); pushBoolean(true); gen.visitLabel(labelNotReturn); } else if (ctx.BWNOT() != null) { typeStack.push(Type.LONG_TYPE); visit(ctx.expression()); typeStack.pop(); gen.push(-1L); gen.visitInsn(Opcodes.LXOR); gen.cast(Type.LONG_TYPE, typeStack.peek()); } else if (ctx.ADD() != null) { visit(ctx.expression()); } else if (ctx.SUB() != null) { typeStack.push(Type.DOUBLE_TYPE); visit(ctx.expression()); typeStack.pop(); gen.visitInsn(Opcodes.DNEG); gen.cast(Type.DOUBLE_TYPE, typeStack.peek()); } else { throw new IllegalStateException("Unknown operation specified: " + ctx.getText()); } return null; } @Override public Void visitMuldiv(JavascriptParser.MuldivContext ctx) { int opcode; if (ctx.MUL() != null) { opcode = Opcodes.DMUL; } else if (ctx.DIV() != null) { opcode = Opcodes.DDIV; } else if (ctx.REM() != null) { opcode = Opcodes.DREM; } else { throw new IllegalStateException("Unknown operation specified: " + ctx.getText()); } pushArith(opcode, ctx.expression(0), ctx.expression(1)); return null; } @Override public Void visitAddsub(JavascriptParser.AddsubContext ctx) { int opcode; if (ctx.ADD() != null) { opcode = Opcodes.DADD; } else if (ctx.SUB() != null) { opcode = Opcodes.DSUB; } else { throw new IllegalStateException("Unknown operation specified: " + ctx.getText()); } pushArith(opcode, ctx.expression(0), ctx.expression(1)); return null; } @Override public Void visitBwshift(JavascriptParser.BwshiftContext ctx) { int opcode; if (ctx.LSH() != null) { opcode = Opcodes.LSHL; } else if (ctx.RSH() != null) { opcode = Opcodes.LSHR; } else if (ctx.USH() != null) { opcode = Opcodes.LUSHR; } else { throw new IllegalStateException("Unknown operation specified: " + ctx.getText()); } pushShift(opcode, ctx.expression(0), ctx.expression(1)); return null; } @Override public Void visitBoolcomp(JavascriptParser.BoolcompContext ctx) { int opcode; if (ctx.LT() != null) { opcode = GeneratorAdapter.LT; } else if (ctx.LTE() != null) { opcode = GeneratorAdapter.LE; } else if (ctx.GT() != null) { opcode = GeneratorAdapter.GT; } else if (ctx.GTE() != null) { opcode = GeneratorAdapter.GE; } else { throw new IllegalStateException("Unknown operation specified: " + ctx.getText()); } pushCond(opcode, ctx.expression(0), ctx.expression(1)); return null; } @Override public Void visitBooleqne(JavascriptParser.BooleqneContext ctx) { int opcode; if (ctx.EQ() != null) { opcode = GeneratorAdapter.EQ; } else if (ctx.NE() != null) { opcode = GeneratorAdapter.NE; } else { throw new IllegalStateException("Unknown operation specified: " + ctx.getText()); } pushCond(opcode, ctx.expression(0), ctx.expression(1)); return null; } @Override public Void visitBwand(JavascriptParser.BwandContext ctx) { pushBitwise(Opcodes.LAND, ctx.expression(0), ctx.expression(1)); return null; } @Override public Void visitBwxor(JavascriptParser.BwxorContext ctx) { pushBitwise(Opcodes.LXOR, ctx.expression(0), ctx.expression(1)); return null; } @Override public Void visitBwor(JavascriptParser.BworContext ctx) { pushBitwise(Opcodes.LOR, ctx.expression(0), ctx.expression(1)); return null; } @Override public Void visitBooland(JavascriptParser.BoolandContext ctx) { Label andFalse = new Label(); Label andEnd = new Label(); typeStack.push(Type.INT_TYPE); visit(ctx.expression(0)); gen.visitJumpInsn(Opcodes.IFEQ, andFalse); visit(ctx.expression(1)); gen.visitJumpInsn(Opcodes.IFEQ, andFalse); typeStack.pop(); pushBoolean(true); gen.goTo(andEnd); gen.visitLabel(andFalse); pushBoolean(false); gen.visitLabel(andEnd); return null; } @Override public Void visitBoolor(JavascriptParser.BoolorContext ctx) { Label orTrue = new Label(); Label orEnd = new Label(); typeStack.push(Type.INT_TYPE); visit(ctx.expression(0)); gen.visitJumpInsn(Opcodes.IFNE, orTrue); visit(ctx.expression(1)); gen.visitJumpInsn(Opcodes.IFNE, orTrue); typeStack.pop(); pushBoolean(false); gen.goTo(orEnd); gen.visitLabel(orTrue); pushBoolean(true); gen.visitLabel(orEnd); return null; } @Override public Void visitConditional(JavascriptParser.ConditionalContext ctx) { Label condFalse = new Label(); Label condEnd = new Label(); typeStack.push(Type.INT_TYPE); visit(ctx.expression(0)); typeStack.pop(); gen.visitJumpInsn(Opcodes.IFEQ, condFalse); visit(ctx.expression(1)); gen.goTo(condEnd); gen.visitLabel(condFalse); visit(ctx.expression(2)); gen.visitLabel(condEnd); return null; } private void pushArith(int operator, ExpressionContext left, ExpressionContext right) { pushBinaryOp(operator, left, right, Type.DOUBLE_TYPE, Type.DOUBLE_TYPE, Type.DOUBLE_TYPE); } private void pushShift(int operator, ExpressionContext left, ExpressionContext right) { pushBinaryOp(operator, left, right, Type.LONG_TYPE, Type.INT_TYPE, Type.LONG_TYPE); } private void pushBitwise(int operator, ExpressionContext left, ExpressionContext right) { pushBinaryOp(operator, left, right, Type.LONG_TYPE, Type.LONG_TYPE, Type.LONG_TYPE); } private void pushBinaryOp(int operator, ExpressionContext left, ExpressionContext right, Type leftType, Type rightType, Type returnType) { typeStack.push(leftType); visit(left); typeStack.pop(); typeStack.push(rightType); visit(right); typeStack.pop(); gen.visitInsn(operator); gen.cast(returnType, typeStack.peek()); } private void pushCond(int operator, ExpressionContext left, ExpressionContext right) { Label labelTrue = new Label(); Label labelReturn = new Label(); typeStack.push(Type.DOUBLE_TYPE); visit(left); visit(right); typeStack.pop(); gen.ifCmp(Type.DOUBLE_TYPE, operator, labelTrue); pushBoolean(false); gen.goTo(labelReturn); gen.visitLabel(labelTrue); pushBoolean(true); gen.visitLabel(labelReturn); } private void pushBoolean(boolean truth) { switch (typeStack.peek().getSort()) { case Type.INT: gen.push(truth); break; case Type.LONG: gen.push(truth ? 1L : 0L); break; case Type.DOUBLE: gen.push(truth ? 1. : 0.); break; default: throw new IllegalStateException("Invalid expected type: " + typeStack.peek()); } } private void pushLong(long i) { switch (typeStack.peek().getSort()) { case Type.INT: gen.push((int) i); break; case Type.LONG: gen.push(i); break; case Type.DOUBLE: gen.push((double) i); break; default: throw new IllegalStateException("Invalid expected type: " + typeStack.peek()); } } }.visit(parseTree); gen.returnValue(); gen.endMethod(); classWriter.visitEnd(); }
From source file:org.apache.lucene.expressions.js.XJavascriptCompiler.java
License:Apache License
private void recursiveCompile(Tree current, Type expected) { int type = current.getType(); String text = current.getText(); switch (type) { case XJavascriptParser.AT_CALL: Tree identifier = current.getChild(0); String call = identifier.getText(); int arguments = current.getChildCount() - 1; Method method = functions.get(call); if (method == null) { throw new IllegalArgumentException("Unrecognized method call (" + call + ")."); }// w w w . j av a2s .co m int arity = method.getParameterTypes().length; if (arguments != arity) { throw new IllegalArgumentException("Expected (" + arity + ") arguments for method call (" + call + "), but found (" + arguments + ")."); } for (int argument = 1; argument <= arguments; ++argument) { recursiveCompile(current.getChild(argument), Type.DOUBLE_TYPE); } gen.invokeStatic(Type.getType(method.getDeclaringClass()), org.objectweb.asm.commons.Method.getMethod(method)); gen.cast(Type.DOUBLE_TYPE, expected); break; case XJavascriptParser.VARIABLE: int index; // normalize quotes text = normalizeQuotes(text); if (externalsMap.containsKey(text)) { index = externalsMap.get(text); } else { index = externalsMap.size(); externalsMap.put(text, index); } gen.loadArg(1); gen.push(index); gen.arrayLoad(FUNCTION_VALUES_TYPE); gen.loadArg(0); gen.invokeVirtual(FUNCTION_VALUES_TYPE, DOUBLE_VAL_METHOD); gen.cast(Type.DOUBLE_TYPE, expected); break; case XJavascriptParser.HEX: pushLong(expected, Long.parseLong(text.substring(2), 16)); break; case XJavascriptParser.OCTAL: pushLong(expected, Long.parseLong(text.substring(1), 8)); break; case XJavascriptParser.DECIMAL: gen.push(Double.parseDouble(text)); gen.cast(Type.DOUBLE_TYPE, expected); break; case XJavascriptParser.AT_NEGATE: recursiveCompile(current.getChild(0), Type.DOUBLE_TYPE); gen.visitInsn(Opcodes.DNEG); gen.cast(Type.DOUBLE_TYPE, expected); break; case XJavascriptParser.AT_ADD: pushArith(Opcodes.DADD, current, expected); break; case XJavascriptParser.AT_SUBTRACT: pushArith(Opcodes.DSUB, current, expected); break; case XJavascriptParser.AT_MULTIPLY: pushArith(Opcodes.DMUL, current, expected); break; case XJavascriptParser.AT_DIVIDE: pushArith(Opcodes.DDIV, current, expected); break; case XJavascriptParser.AT_MODULO: pushArith(Opcodes.DREM, current, expected); break; case XJavascriptParser.AT_BIT_SHL: pushShift(Opcodes.LSHL, current, expected); break; case XJavascriptParser.AT_BIT_SHR: pushShift(Opcodes.LSHR, current, expected); break; case XJavascriptParser.AT_BIT_SHU: pushShift(Opcodes.LUSHR, current, expected); break; case XJavascriptParser.AT_BIT_AND: pushBitwise(Opcodes.LAND, current, expected); break; case XJavascriptParser.AT_BIT_OR: pushBitwise(Opcodes.LOR, current, expected); break; case XJavascriptParser.AT_BIT_XOR: pushBitwise(Opcodes.LXOR, current, expected); break; case XJavascriptParser.AT_BIT_NOT: recursiveCompile(current.getChild(0), Type.LONG_TYPE); gen.push(-1L); gen.visitInsn(Opcodes.LXOR); gen.cast(Type.LONG_TYPE, expected); break; case XJavascriptParser.AT_COMP_EQ: pushCond(GeneratorAdapter.EQ, current, expected); break; case XJavascriptParser.AT_COMP_NEQ: pushCond(GeneratorAdapter.NE, current, expected); break; case XJavascriptParser.AT_COMP_LT: pushCond(GeneratorAdapter.LT, current, expected); break; case XJavascriptParser.AT_COMP_GT: pushCond(GeneratorAdapter.GT, current, expected); break; case XJavascriptParser.AT_COMP_LTE: pushCond(GeneratorAdapter.LE, current, expected); break; case XJavascriptParser.AT_COMP_GTE: pushCond(GeneratorAdapter.GE, current, expected); break; case XJavascriptParser.AT_BOOL_NOT: Label labelNotTrue = new Label(); Label labelNotReturn = new Label(); recursiveCompile(current.getChild(0), Type.INT_TYPE); gen.visitJumpInsn(Opcodes.IFEQ, labelNotTrue); pushBoolean(expected, false); gen.goTo(labelNotReturn); gen.visitLabel(labelNotTrue); pushBoolean(expected, true); gen.visitLabel(labelNotReturn); break; case XJavascriptParser.AT_BOOL_AND: Label andFalse = new Label(); Label andEnd = new Label(); recursiveCompile(current.getChild(0), Type.INT_TYPE); gen.visitJumpInsn(Opcodes.IFEQ, andFalse); recursiveCompile(current.getChild(1), Type.INT_TYPE); gen.visitJumpInsn(Opcodes.IFEQ, andFalse); pushBoolean(expected, true); gen.goTo(andEnd); gen.visitLabel(andFalse); pushBoolean(expected, false); gen.visitLabel(andEnd); break; case XJavascriptParser.AT_BOOL_OR: Label orTrue = new Label(); Label orEnd = new Label(); recursiveCompile(current.getChild(0), Type.INT_TYPE); gen.visitJumpInsn(Opcodes.IFNE, orTrue); recursiveCompile(current.getChild(1), Type.INT_TYPE); gen.visitJumpInsn(Opcodes.IFNE, orTrue); pushBoolean(expected, false); gen.goTo(orEnd); gen.visitLabel(orTrue); pushBoolean(expected, true); gen.visitLabel(orEnd); break; case XJavascriptParser.AT_COND_QUE: Label condFalse = new Label(); Label condEnd = new Label(); recursiveCompile(current.getChild(0), Type.INT_TYPE); gen.visitJumpInsn(Opcodes.IFEQ, condFalse); recursiveCompile(current.getChild(1), expected); gen.goTo(condEnd); gen.visitLabel(condFalse); recursiveCompile(current.getChild(2), expected); gen.visitLabel(condEnd); break; default: throw new IllegalStateException("Unknown operation specified: (" + current.getText() + ")."); } }
From source file:org.decojer.cavaj.readers.asm.ReadMethodVisitor.java
License:Open Source License
@Override public void visitInsn(final int opcode) { T t = null;// w w w . j ava 2 s . c o 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.mutation.ReplaceBitwiseOperator.java
License:Open Source License
private String getOp(int opcode) { switch (opcode) { case Opcodes.IAND: case Opcodes.LAND: return "&"; case Opcodes.IOR: case Opcodes.LOR: return "|"; case Opcodes.IXOR: case Opcodes.LXOR: return "^"; case Opcodes.ISHR: return ">> I"; case Opcodes.LSHR: return ">> L"; case Opcodes.ISHL: return "<< I"; case Opcodes.LSHL: return "<< L"; case Opcodes.IUSHR: return ">>> I"; case Opcodes.LUSHR: return ">>> L"; }/*from w w w .ja v a2s.co m*/ throw new RuntimeException("Unknown opcode: " + opcode); }
From source file:org.evosuite.instrumentation.mutation.ReplaceBitwiseOperator.java
License:Open Source License
/** * <p>calculate</p>/*from ww w. j a v a 2 s . co m*/ * * @param x a long. * @param y a long. * @param opcode a int. * @return a long. */ public static long calculate(long x, long y, int opcode) { switch (opcode) { case Opcodes.LAND: return x & y; case Opcodes.LOR: return x | y; case Opcodes.LXOR: return x ^ y; case Opcodes.LSHL: return x << y; case Opcodes.LSHR: return x >> y; case Opcodes.LUSHR: return x >>> y; } throw new RuntimeException("Unknown long opcode: " + opcode); }
From source file:org.jacoco.core.internal.instr.FrameTracker.java
License:Open Source License
@Override public void visitInsn(final int opcode) { final Object t1, t2, t3, t4; switch (opcode) { case Opcodes.NOP: case Opcodes.RETURN: break;//w w w.ja v a2 s. co m case Opcodes.ARETURN: case Opcodes.ATHROW: case Opcodes.FRETURN: case Opcodes.IRETURN: case Opcodes.MONITORENTER: case Opcodes.MONITOREXIT: case Opcodes.POP: pop(1); break; case Opcodes.DRETURN: case Opcodes.LRETURN: case Opcodes.POP2: pop(2); break; case Opcodes.AASTORE: case Opcodes.BASTORE: case Opcodes.CASTORE: case Opcodes.FASTORE: case Opcodes.IASTORE: case Opcodes.SASTORE: pop(3); break; case Opcodes.LASTORE: case Opcodes.DASTORE: pop(4); 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(Opcodes.INTEGER); break; case Opcodes.ARRAYLENGTH: case Opcodes.F2I: case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: case Opcodes.INEG: pop(1); push(Opcodes.INTEGER); break; case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.D2I: case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.IADD: case Opcodes.IALOAD: case Opcodes.IAND: case Opcodes.IDIV: case Opcodes.IMUL: case Opcodes.IOR: case Opcodes.IREM: case Opcodes.ISHL: case Opcodes.ISHR: case Opcodes.ISUB: case Opcodes.IUSHR: case Opcodes.IXOR: case Opcodes.L2I: case Opcodes.SALOAD: pop(2); push(Opcodes.INTEGER); break; case Opcodes.DCMPG: case Opcodes.DCMPL: case Opcodes.LCMP: pop(4); push(Opcodes.INTEGER); break; case Opcodes.FCONST_0: case Opcodes.FCONST_1: case Opcodes.FCONST_2: push(Opcodes.FLOAT); break; case Opcodes.FNEG: case Opcodes.I2F: pop(1); push(Opcodes.FLOAT); break; case Opcodes.D2F: case Opcodes.FADD: case Opcodes.FALOAD: case Opcodes.FDIV: case Opcodes.FMUL: case Opcodes.FREM: case Opcodes.FSUB: case Opcodes.L2F: pop(2); push(Opcodes.FLOAT); break; case Opcodes.LCONST_0: case Opcodes.LCONST_1: push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.F2L: case Opcodes.I2L: pop(1); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.D2L: case Opcodes.LALOAD: case Opcodes.LNEG: pop(2); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.LSHL: case Opcodes.LSHR: case Opcodes.LUSHR: pop(3); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.LADD: case Opcodes.LAND: case Opcodes.LDIV: case Opcodes.LMUL: case Opcodes.LOR: case Opcodes.LREM: case Opcodes.LSUB: case Opcodes.LXOR: pop(4); push(Opcodes.LONG); push(Opcodes.TOP); break; case Opcodes.DCONST_0: case Opcodes.DCONST_1: push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.F2D: case Opcodes.I2D: pop(1); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.DALOAD: case Opcodes.DNEG: case Opcodes.L2D: pop(2); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.DADD: case Opcodes.DDIV: case Opcodes.DMUL: case Opcodes.DREM: case Opcodes.DSUB: pop(4); push(Opcodes.DOUBLE); push(Opcodes.TOP); break; case Opcodes.ACONST_NULL: push(Opcodes.NULL); break; case Opcodes.AALOAD: pop(1); t1 = pop(); push(Type.getType(((String) t1).substring(1))); break; case Opcodes.DUP: t1 = pop(); push(t1); push(t1); break; case Opcodes.DUP_X1: t1 = pop(); t2 = pop(); push(t1); push(t2); push(t1); break; case Opcodes.DUP_X2: t1 = pop(); t2 = pop(); t3 = pop(); push(t1); push(t3); push(t2); push(t1); break; case Opcodes.DUP2: t1 = pop(); t2 = pop(); push(t2); push(t1); push(t2); push(t1); break; case Opcodes.DUP2_X1: t1 = pop(); t2 = pop(); t3 = pop(); push(t2); push(t1); push(t3); push(t2); push(t1); break; case Opcodes.DUP2_X2: t1 = pop(); t2 = pop(); t3 = pop(); t4 = pop(); push(t2); push(t1); push(t4); push(t3); push(t2); push(t1); break; case Opcodes.SWAP: t1 = pop(); t2 = pop(); push(t1); push(t2); break; default: throw new IllegalArgumentException(); } mv.visitInsn(opcode); }
From source file:org.jboss.byteman.rule.expression.BitExpression.java
License:Open Source License
public void compile(MethodVisitor mv, CompileContext compileContext) throws CompileException { // make sure we are at the right source line compileContext.notifySourceLine(line); int currentStack = compileContext.getStackCount(); int expected = 0; Expression oper0 = getOperand(0); Expression oper1 = getOperand(1); // compile the operands and make sure the result is our target type oper0.compile(mv, compileContext);/*from w ww . java2 s . c o m*/ compileTypeConversion(oper0.getType(), type, mv, compileContext); oper1.compile(mv, compileContext); compileTypeConversion(oper1.getType(), type, mv, compileContext); if (type == Type.B || type == Type.S || type == Type.I) { switch (oper) { case BOR: mv.visitInsn(Opcodes.IOR); break; case BAND: mv.visitInsn(Opcodes.IAND); break; case BXOR: mv.visitInsn(Opcodes.IXOR); break; } if (type == Type.B) { mv.visitInsn(Opcodes.I2B); } else if (type == Type.S) { mv.visitInsn(Opcodes.I2S); } else if (type == Type.C) { mv.visitInsn(Opcodes.I2C); } // ok, we popped two words but added one compileContext.addStackCount(-2); expected = 1; } else if (type == Type.J) { switch (oper) { case BOR: mv.visitInsn(Opcodes.LOR); break; case BAND: mv.visitInsn(Opcodes.LAND); break; case BXOR: mv.visitInsn(Opcodes.LXOR); break; } // ok, we popped four words but added two compileContext.addStackCount(-2); expected = 2; } // we have either a 1 words or a 2 words result // check that the stack height is what we expect compileContext.addStackCount(expected); if (compileContext.getStackCount() != currentStack + expected) { throw new CompileException("BitExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + currentStack + expected); } }