List of usage examples for org.objectweb.asm Opcodes DLOAD
int DLOAD
To view the source code for org.objectweb.asm Opcodes DLOAD.
Click Source Link
From source file:com.codename1.tools.translator.bytecodes.VarOp.java
License:Open Source License
@Override public boolean assignTo(String varName, StringBuilder sb) { StringBuilder b = new StringBuilder(); /*/*from w w w.j a v a 2s.co m*/ if (typeVarName != null) { switch (opcode) { case Opcodes.ALOAD: b.append("locals["); b.append(var); b.append("].type = CN1_TYPE_OBJECT; "); break; } }*/ if (varName != null) { b.append(" "); b.append(varName).append(" = "); } switch (opcode) { case Opcodes.ILOAD: b.append("ilocals_"); b.append(var); b.append("_"); break; case Opcodes.LLOAD: b.append("llocals_"); b.append(var); b.append("_"); break; case Opcodes.FLOAD: b.append("flocals_"); b.append(var); b.append("_"); break; case Opcodes.DLOAD: b.append("dlocals_"); b.append(var); b.append("_"); break; case Opcodes.ALOAD: if (getMethod() != null && !getMethod().isStatic() && var == 0) { b.append("__cn1ThisObject"); } else { b.append("locals["); b.append(var); b.append("].data.o"); } break; default: return false; } if (varName != null) { b.append(";\n"); } sb.append(b); return true; }
From source file:com.codename1.tools.translator.bytecodes.VarOp.java
License:Open Source License
@Override public void appendInstruction(StringBuilder b) { b.append(" "); switch (opcode) { case Opcodes.ILOAD: b.append("(*SP).type = CN1_TYPE_INT; /* ILOAD */ \n" + " (*SP).data.i = ilocals_"); b.append(var); b.append("_; \n SP++;\n"); return;/*from ww w . j a va 2 s.c om*/ case Opcodes.LLOAD: b.append("BC_LLOAD("); break; case Opcodes.FLOAD: b.append("BC_FLOAD("); break; case Opcodes.DLOAD: b.append("BC_DLOAD("); break; case Opcodes.ALOAD: b.append("BC_ALOAD("); break; case Opcodes.ISTORE: b.append("BC_ISTORE("); break; case Opcodes.LSTORE: b.append("BC_LSTORE("); break; case Opcodes.FSTORE: b.append("BC_FSTORE("); break; case Opcodes.DSTORE: b.append("BC_DSTORE("); break; case Opcodes.ASTORE: b.append("BC_ASTORE("); break; case Opcodes.RET: b.append("/* RET TODO */"); //b.append("goto label_"); //b.append(var); //b.append("; /* RET */\n"); return; case Opcodes.SIPUSH: case Opcodes.BIPUSH: b.append("PUSH_INT("); break; case Opcodes.NEWARRAY: switch (var) { case 4: // boolean b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_BOOLEAN, sizeof(JAVA_ARRAY_BOOLEAN), 1));\n"); break; case 5: // char b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_CHAR, sizeof(JAVA_ARRAY_CHAR), 1));\n"); break; case 6: // float b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_FLOAT, sizeof(JAVA_ARRAY_FLOAT), 1));\n"); break; case 7: // double b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_DOUBLE, sizeof(JAVA_ARRAY_DOUBLE), 1));\n"); break; case 8: // byte b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_BYTE, sizeof(JAVA_ARRAY_BYTE), 1));\n"); break; case 9: // short b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_SHORT, sizeof(JAVA_ARRAY_SHORT), 1));\n"); break; case 10: // int b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_INT, sizeof(JAVA_ARRAY_INT), 1));\n"); break; case 11: // long b.append( "PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_LONG, sizeof(JAVA_ARRAY_LONG), 1));\n"); break; } return; default: throw new RuntimeException("Missing opcode: " + opcode); } b.append(var); b.append(");\n"); }
From source file:com.geeksaga.light.profiler.util.ASMUtil.java
License:Apache License
public static VarInsnNode createDLOAD(int index) { return new VarInsnNode(Opcodes.DLOAD, index); }
From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java
License:Open Source License
private void load(int var, Type type) { assert var >= 0 && variables.isActive(var) : "variable is not initialized"; switch (type.getOpcode(Opcodes.ILOAD)) { case Opcodes.ILOAD: iload(var); return;/* w ww. ja va 2 s. c o m*/ case Opcodes.LLOAD: lload(var); return; case Opcodes.FLOAD: fload(var); return; case Opcodes.DLOAD: dload(var); return; case Opcodes.ALOAD: aload(var); return; default: throw new IllegalArgumentException(); } }
From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java
License:Open Source License
private void dload(int var) { methodVisitor.visitVarInsn(Opcodes.DLOAD, var); stack.dload(var); }
From source file:com.github.rgcjonas.kuemmelgtr.core.Compiler.java
License:Open Source License
private static void compileCommon(TokenSource<RPNToken> source, MethodVisitor method, String variable) throws ParsingError { method.visitCode();//from w w w. j a v a 2s . c o m // we now can compile our token stream int currentStackSize = 0; // we keep track of the current stack size to throw errors if we encounter an invalid instruction RPNToken t; while ((t = source.nextToken()) != null) { if (t instanceof RPNToken.Operand) { // we push it onto the stack method.visitLdcInsn(((RPNToken.Operand) t).getValue()); currentStackSize++; } else if (t instanceof RPNToken.Operator) { RPNToken.Operator op = (RPNToken.Operator) t; if (currentStackSize < op.getNumOperands()) throw new ParsingError(t.getSrcLine(), t.getSrcColumn(), "Missing operand(s)"); switch (op.getName()) { case "_add": method.visitInsn(Opcodes.DADD); currentStackSize--; break; case "_mult": method.visitInsn(Opcodes.DMUL); currentStackSize--; break; case "_sub": method.visitInsn(Opcodes.DSUB); currentStackSize--; break; case "_div": method.visitInsn(Opcodes.DDIV); currentStackSize--; break; case "_pow": method.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", "pow", "(DD)D"); currentStackSize--; break; default: //HACK: support every function in java/lang/Math. Will be way more performant than any lookup-and-evaluate //TODO: implement more functions inline if (currentStackSize < 1) throw new ParsingError(t.getSrcLine(), t.getSrcColumn(), "Missing operand"); try { Method meth = Math.class.getDeclaredMethod(op.getName(), double.class); // just check if it's available and hope it returns a double if (meth.getReturnType() != double.class) throw new NoSuchMethodException(); // we don't want to blow up at runtime, do we? method.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Math", op.getName(), "(D)D"); } catch (NoSuchMethodException e) { // we do not give up. The method may be available at runtime. method.visitVarInsn(Opcodes.ALOAD, 0); method.visitInsn(Opcodes.DUP_X2); // swap the this pointer and double method.visitInsn(Opcodes.POP); method.visitLdcInsn(op.getName()); method.visitLdcInsn((int) op.getSrcLine()); method.visitLdcInsn((int) op.getSrcColumn()); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CompiledClassBase.class.getName().replace('.', '/'), "resolveAndEvaluateFunction", "(DLjava/lang/String;II)D"); } } } else if (t instanceof RPNToken.VariableRecall) { // maybe, maybe the variable is an argument we can load if (variable != null && ((RPNToken.VariableRecall) t).getName().equalsIgnoreCase(variable)) { method.visitVarInsn(Opcodes.DLOAD, 1); } else { // we let our parent class do the hard work method.visitVarInsn(Opcodes.ALOAD, 0); method.visitLdcInsn(((RPNToken.VariableRecall) t).getName()); method.visitLdcInsn(t.getSrcLine()); method.visitLdcInsn(t.getSrcColumn()); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CompiledClassBase.class.getName().replace('.', '/'), "getVariable", "(Ljava/lang/String;II)D"); } currentStackSize++; } else if (t instanceof RPNToken.VariableAssignment) { // also defer to our parent class // we do not give up. The method may be available at runtime. method.visitVarInsn(Opcodes.ALOAD, 0); method.visitInsn(Opcodes.DUP_X2); // swap the this pointer and double method.visitInsn(Opcodes.POP); method.visitLdcInsn(((RPNToken.VariableAssignment) t).getVariableName()); method.visitLdcInsn(t.getSrcLine()); method.visitLdcInsn(t.getSrcColumn()); method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, CompiledClassBase.class.getName().replace('.', '/'), "setVariable", "(DLjava/lang/String;II)D"); } else { throw new ParsingError(t.getSrcLine(), t.getSrcColumn(), "Unknown instruction: " + t); } } if (currentStackSize != 1) throw new ParsingError(0, 0, "Expected stack to be one value, found " + currentStackSize); method.visitInsn(Opcodes.DRETURN); method.visitMaxs(0, 0); method.visitEnd(); }
From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java
License:Open Source License
@Override public void visitVarInsn(int opcode, int var) { switch (opcode) { case Opcodes.ILOAD: push(InferredType.INT);/*from w ww .j a v a 2 s . c o m*/ break; case Opcodes.LLOAD: push(InferredType.LONG); push(InferredType.TOP); break; case Opcodes.FLOAD: push(InferredType.FLOAT); break; case Opcodes.DLOAD: push(InferredType.DOUBLE); push(InferredType.TOP); break; case Opcodes.ALOAD: push(getLocalVariableType(var)); break; case Opcodes.ISTORE: case Opcodes.FSTORE: case Opcodes.ASTORE: { InferredType type = pop(); setLocalVariableTypes(var, type); break; } case Opcodes.LSTORE: case Opcodes.DSTORE: { InferredType type = pop(2); setLocalVariableTypes(var, type); setLocalVariableTypes(var + 1, InferredType.TOP); break; } case Opcodes.RET: throw new RuntimeException("The instruction RET is not supported"); default: throw new RuntimeException("Unhandled opcode " + opcode); } super.visitVarInsn(opcode, var); }
From source file:com.google.devtools.build.wireless.testing.java.injector.TypeDescriptorTest.java
License:Apache License
/** * Test method for {@link TypeDescriptor#getLoadOpcode()}. *///ww w. j a v a 2 s. c o m public void testGetLoadOpcode() { try { TypeDescriptor.VOID.getLoadOpcode(); fail("Void should have thrown an exception!"); } catch (IllegalStateException e) { // OK! } assertEquals("Wrong LOAD instruction", Opcodes.ILOAD, TypeDescriptor.BOOLEAN.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ILOAD, TypeDescriptor.BYTE.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ILOAD, TypeDescriptor.CHAR.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ILOAD, TypeDescriptor.SHORT.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ILOAD, TypeDescriptor.INTEGER.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.LLOAD, TypeDescriptor.LONG.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.FLOAD, TypeDescriptor.FLOAT.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.DLOAD, TypeDescriptor.DOUBLE.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ALOAD, TypeDescriptor.CLASS.getLoadOpcode()); assertEquals("Wrong STORE instruction", Opcodes.ALOAD, TypeDescriptor.ARRAY.getLoadOpcode()); }
From source file:com.google.gwt.jvm.asm.NativeMethodDelegatingVisitor.java
License:Apache License
private int nativeDelegate_addArgument(String parameter, int index) { int size = 1; delegate.visitInsn(Opcodes.DUP);/*from w ww.ja va2s. co m*/ switch (parameter.charAt(0)) { case 'L': case '[': parameter = "Ljava/lang/Object;"; delegate.visitVarInsn(Opcodes.ALOAD, index); break; case 'Z': case 'B': case 'C': case 'S': case 'I': delegate.visitVarInsn(Opcodes.ILOAD, index); break; case 'J': delegate.visitVarInsn(Opcodes.LLOAD, index); size = 2; break; case 'F': delegate.visitVarInsn(Opcodes.FLOAD, index); break; case 'D': delegate.visitVarInsn(Opcodes.DLOAD, index); size = 2; break; default: throw new IllegalStateException(parameter); } delegate.visitMethodInsn(Opcodes.INVOKEVIRTUAL, InvocationDelegate, "addArg", "(" + parameter + ")V"); return size; }
From source file:com.google.test.metric.asm.MethodVisitorBuilder.java
License:Apache License
public void visitVarInsn(final int opcode, final int var) { switch (opcode) { case Opcodes.ILOAD: load(var, JavaType.INT); break;/*from w ww . j a v a 2 s . c om*/ case Opcodes.LLOAD: load(var, JavaType.LONG); break; case Opcodes.FLOAD: load(var, JavaType.FLOAT); break; case Opcodes.DLOAD: load(var, JavaType.DOUBLE); break; case Opcodes.ALOAD: load(var, JavaType.OBJECT); break; case Opcodes.ISTORE: store(var, JavaType.INT); break; case Opcodes.LSTORE: store(var, JavaType.LONG); break; case Opcodes.FSTORE: store(var, JavaType.FLOAT); break; case Opcodes.DSTORE: store(var, JavaType.DOUBLE); break; case Opcodes.ASTORE: store(var, JavaType.OBJECT); break; case Opcodes.RET: recorder.add(new Runnable() { public void run() { block.addOp(new RetSub(lineNumber)); } }); break; default: throw new UnsupportedOperationException("opcode: " + opcode); } }