List of usage examples for org.objectweb.asm.tree InsnList add
public void add(final InsnList insnList)
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
private InsnList saveState(int state) { InsnList il = new InsnList(); il.add(ASMUtils.loadInt(state)); il.add(new VarInsnNode(ISTORE, runMethod.LV_RESUME)); return il;/*from w ww. j av a 2 s. com*/ }
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
private InsnList _return() { InsnList il = new InsnList(); if (!isSub()) { il.add(new InsnNode(RETURN)); } else {//from w w w. j a v a2 s .c o m il.add(new InsnNode(ACONST_NULL)); il.add(new InsnNode(ARETURN)); } return il; }
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
private InsnList _nonLocalGoto(Label label) { InsnList il = new InsnList(); int st = resolver.labelStateIndex(label); il.add(saveState(st)); il.add(runMethod.createSnapshot());/*from w w w . jav a 2 s .c o m*/ il.add(new InsnNode(ARETURN)); return il; }
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
private InsnList _goto(Label label) { InsnList il = new InsnList(); if (!isSub() || resolver.isLocalLabel(label)) { il.add(new JumpInsnNode(GOTO, l(label))); } else {//from ww w . jav a 2 s . com il.add(_nonLocalGoto(label)); } return il; }
From source file:net.sandius.rembulan.compiler.gen.asm.BytecodeEmitVisitor.java
License:Apache License
private InsnList _next(Label label) { InsnList il = new InsnList(); if (!isSub() || resolver.isLocalLabel(label)) { // no-op// ww w .j a v a2 s. c o m } else { il.add(_nonLocalGoto(label)); } return il; }
From source file:net.sandius.rembulan.compiler.gen.asm.ConstructorMethod.java
License:Apache License
public MethodNode methodNode() { MethodNode node = new MethodNode(ACC_PUBLIC, "<init>", methodType().getDescriptor(), null, null); InsnList il = node.instructions; LabelNode begin = new LabelNode(); LabelNode end = new LabelNode(); node.localVariables//from ww w.ja va 2 s . com .add(new LocalVariableNode("this", context.thisClassType().getDescriptor(), null, begin, end, 0)); il.add(begin); // superclass constructor il.add(new VarInsnNode(ALOAD, 0)); il.add(new MethodInsnNode(INVOKESPECIAL, context.superClassType().getInternalName(), "<init>", Type.getMethodType(Type.VOID_TYPE).getDescriptor(), false)); // initialise upvalue fields int idx = 0; for (UpVar uv : context.fn.upvals()) { String name = context.getUpvalueFieldName(uv); il.add(new VarInsnNode(ALOAD, 0)); // this il.add(new VarInsnNode(ALOAD, 1 + idx)); // upvalue #i il.add(new FieldInsnNode(PUTFIELD, context.thisClassType().getInternalName(), name, Type.getDescriptor(Variable.class))); node.localVariables .add(new LocalVariableNode(name, Type.getDescriptor(Variable.class), null, begin, end, idx)); idx++; } // instantiate fields for closures that have no open upvalues for (RunMethod.ClosureFieldInstance cfi : runMethod.closureFields()) { context.fields().add(cfi.fieldNode()); il.add(cfi.instantiateInsns()); } il.add(new InsnNode(RETURN)); il.add(end); node.maxStack = 2; node.maxLocals = context.fn.upvals().size() + 1; return node; }
From source file:net.sandius.rembulan.compiler.gen.asm.helpers.BoxedPrimitivesMethods.java
License:Apache License
public static InsnList loadBoxedConstant(Object k, Class<?> castTo) { InsnList il = new InsnList(); if (k == null) { il.add(loadNull()); } else if (k instanceof Boolean) { il.add(BoxedPrimitivesMethods.loadBoxedBoolean((Boolean) k)); } else if (k instanceof Double || k instanceof Float) { il.add(ASMUtils.loadDouble(((Number) k).doubleValue())); il.add(BoxedPrimitivesMethods.box(Type.DOUBLE_TYPE, Type.getType(Double.class))); } else if (k instanceof Number) { il.add(ASMUtils.loadLong(((Number) k).longValue())); il.add(BoxedPrimitivesMethods.box(Type.LONG_TYPE, Type.getType(Long.class))); } else if (k instanceof String) { il.add(new LdcInsnNode(k)); } else {/*from w w w . j a v a2 s . c o m*/ throw new UnsupportedOperationException("Illegal constant type: " + k.getClass()); } if (castTo != null) { Objects.requireNonNull(k); if (!castTo.isAssignableFrom(k.getClass())) { il.add(new TypeInsnNode(CHECKCAST, Type.getInternalName(castTo))); } } return il; }
From source file:net.sandius.rembulan.compiler.gen.asm.helpers.ConversionMethods.java
License:Apache License
public static InsnList toNumericalValue(String what) { Objects.requireNonNull(what); InsnList il = new InsnList(); il.add(new LdcInsnNode(what)); il.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(Conversions.class), "toNumericalValue", Type.getMethodDescriptor(Type.getType(Number.class), Type.getType(Object.class), Type.getType(String.class)), false));/*from w w w . j a va 2 s . c o m*/ return il; }
From source file:net.sandius.rembulan.compiler.gen.asm.helpers.ExecutionContextMethods.java
License:Apache License
public static InsnList newTable(int array, int hash) { InsnList il = new InsnList(); il.add(ASMUtils.loadInt(array)); il.add(ASMUtils.loadInt(hash));/*from w w w. j a v a 2 s.co m*/ il.add(new MethodInsnNode(INVOKEINTERFACE, selfTpe().getInternalName(), "newTable", Type.getMethodType(Type.getType(Table.class), Type.INT_TYPE, Type.INT_TYPE).getDescriptor(), true)); return il; }
From source file:net.sandius.rembulan.compiler.gen.asm.helpers.ReturnBufferMethods.java
License:Apache License
public static InsnList get(int index) { Check.nonNegative(index);/* w w w . j a v a2s.com*/ InsnList il = new InsnList(); if (index <= 4) { String methodName = "get" + index; il.add(new MethodInsnNode(INVOKEINTERFACE, selfTpe().getInternalName(), methodName, Type.getMethodType(Type.getType(Object.class)).getDescriptor(), true)); } else { il.add(ASMUtils.loadInt(index)); il.add(get()); } return il; }