use of org.objectweb.asm.tree.TypeInsnNode in project runelite by runelite.
the class InstructionDeserializer method deserialize.
@Override
public AbstractInsnNode deserialize(JsonElement var1, Type var2, JsonDeserializationContext var3) {
JsonObject var4 = (JsonObject) var1;
int var5 = var4.get("opcode").getAsInt();
if (var5 != 21 && var5 != 25 && var5 != 58 && var5 != 54 && var5 != 22 && var5 != 55) {
String var7;
String var8;
String var10;
if (var5 != 184 && var5 != 182 && var5 != 183) {
if (var5 == 18) {
try {
return new LdcInsnNode(Integer.valueOf(var4.get("cst").getAsInt()));
} catch (Exception var9) {
return new LdcInsnNode(var4.get("cst").getAsString());
}
} else if (var5 != 187 && var5 != 189) {
if (var5 != 16 && var5 != 17) {
if (var5 != 179 && var5 != 178 && var5 != 180 && var5 != 181) {
return new InsnNode(var5);
} else {
var10 = var4.get("owner").getAsString();
var7 = var4.get("name").getAsString();
var8 = var4.get("desc").getAsString();
return new FieldInsnNode(var5, var10, var7, var8);
}
} else {
return new IntInsnNode(var5, var4.get("operand").getAsInt());
}
} else {
return new TypeInsnNode(var5, var4.get("desc").getAsString());
}
} else {
var10 = var4.get("owner").getAsString();
var7 = var4.get("name").getAsString();
var8 = var4.get("desc").getAsString();
return new MethodInsnNode(var5, var10, var7, var8);
}
} else {
int var6 = var4.get("var").getAsInt();
return new VarInsnNode(var5, var6);
}
}
use of org.objectweb.asm.tree.TypeInsnNode in project BuildCraft by BuildCraft.
the class EventBusProviderASM method generateGenerator.
private byte[] generateGenerator(Class<? extends IEventHandler<?>> handlerClass, Class<?> parClass, String clsName) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
ClassNode node = new ClassNode();
node.name = clsName.replace('.', '/');
node.version = Opcodes.V1_6;
node.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL;
node.interfaces = Lists.newArrayList(IEventHandlerProvider.class.getName().replace('.', '/'));
node.superName = "java/lang/Object";
// Method:
// public ClassName() {
// super();
// }
{
MethodNode consturctorMethod = new MethodNode();
consturctorMethod.access = Opcodes.ACC_PUBLIC;
consturctorMethod.desc = "()V";
consturctorMethod.name = "<init>";
consturctorMethod.exceptions = Lists.newArrayList();
consturctorMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
consturctorMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false));
consturctorMethod.instructions.add(new InsnNode(Opcodes.RETURN));
node.methods.add(consturctorMethod);
}
// Method:
// public IEventHandler createNewHandler(Object obj) {
// return new ClassHandler(obj);
// }
{
MethodNode generationMethod = new MethodNode();
// public final void handle(Object)
generationMethod.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL;
generationMethod.desc = "(Ljava/lang/Object;)Lbuildcraft/core/lib/event/IEventHandler;";
generationMethod.name = "createNewHandler";
generationMethod.exceptions = Lists.newArrayList();
{
generationMethod.instructions.add(new TypeInsnNode(Opcodes.NEW, Type.getInternalName(handlerClass)));
generationMethod.instructions.add(new InsnNode(Opcodes.DUP));
generationMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
generationMethod.instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(parClass)));
generationMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, Type.getInternalName(handlerClass), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(parClass)), false));
generationMethod.instructions.add(new InsnNode(Opcodes.ARETURN));
}
node.methods.add(generationMethod);
}
node.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.TypeInsnNode in project BuildCraft by BuildCraft.
the class EventBusProviderASM method generateDirectHandler.
private byte[] generateDirectHandler(Method meth, Class<?> parClass, String clsName) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
ClassNode node = new ClassNode();
node.name = clsName.replace('.', '/');
node.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL;
node.interfaces = Lists.newArrayList(IEventHandler.class.getName().replace('.', '/'));
node.version = Opcodes.V1_6;
node.superName = "java/lang/Object";
String fd = Type.getDescriptor(meth.getDeclaringClass());
node.fields.add(new FieldNode(Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL, "listener", fd, null, null));
// This method does:
// public ClassName(ListenerObject obj) {
// super();
// this.listener = obj;
// }
{
MethodNode consturctorMethod = new MethodNode();
consturctorMethod.access = Opcodes.ACC_PUBLIC;
consturctorMethod.desc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(meth.getDeclaringClass()));
consturctorMethod.name = "<init>";
consturctorMethod.exceptions = Lists.newArrayList();
consturctorMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
consturctorMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false));
consturctorMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
consturctorMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
consturctorMethod.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, node.name, "listener", fd));
consturctorMethod.instructions.add(new InsnNode(Opcodes.RETURN));
node.methods.add(consturctorMethod);
}
// This method does:
// public final void handle(Object event) {
// if (!(event instanceof EventClass)) return;
// listener.<method_name>((EventClass) event);
// }
{
MethodNode generationMethod = new MethodNode();
// public final void handle(Object)
generationMethod.access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL;
generationMethod.desc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class));
generationMethod.name = "handle";
generationMethod.exceptions = Lists.newArrayList();
// This block does:
// if (!(event instanceof EventClass)) return;
{
// ADD the first object (given as [this, event])
// -> event
generationMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
// event -> event instanceof PAR_CLASS -> boolean
generationMethod.instructions.add(new TypeInsnNode(Opcodes.INSTANCEOF, Type.getInternalName(parClass)));
LabelNode instanceLabel = new LabelNode();
// boolean -> if (boolean) GOTO instanceLabel ->
generationMethod.instructions.add(new JumpInsnNode(Opcodes.IFNE, instanceLabel));
// return;
generationMethod.instructions.add(new InsnNode(Opcodes.RETURN));
generationMethod.instructions.add(instanceLabel);
}
// This block does:
// listener.<method_name>(event);
{
generationMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
// -> ListenerObject
String desc = Type.getDescriptor(meth.getDeclaringClass());
generationMethod.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, node.name, "listener", desc));
// -> Object
generationMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
// CheckCast
generationMethod.instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(parClass)));
// ListenerObject, EventObject -> <method_name> ->
generationMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, Type.getInternalName(meth.getDeclaringClass()), meth.getName(), Type.getMethodDescriptor(meth), false));
}
// return;
generationMethod.instructions.add(new InsnNode(Opcodes.RETURN));
node.methods.add(generationMethod);
}
node.accept(writer);
byte[] bytecode = writer.toByteArray();
return bytecode;
}
use of org.objectweb.asm.tree.TypeInsnNode in project soot by Sable.
the class AsmMethodSource method convert.
private void convert() {
ArrayDeque<Edge> worklist = new ArrayDeque<Edge>();
for (LabelNode ln : trapHandlers.keySet()) {
if (checkInlineExceptionHandler(ln))
handleInlineExceptionHandler(ln, worklist);
else
worklist.add(new Edge(ln, new ArrayList<Operand>()));
}
worklist.add(new Edge(instructions.getFirst(), new ArrayList<Operand>()));
conversionWorklist = worklist;
edges = HashBasedTable.create(1, 1);
do {
Edge edge = worklist.pollLast();
AbstractInsnNode insn = edge.insn;
stack = edge.stack;
edge.stack = null;
do {
int type = insn.getType();
if (type == FIELD_INSN) {
convertFieldInsn((FieldInsnNode) insn);
} else if (type == IINC_INSN) {
convertIincInsn((IincInsnNode) insn);
} else if (type == INSN) {
convertInsn((InsnNode) insn);
int op = insn.getOpcode();
if ((op >= IRETURN && op <= RETURN) || op == ATHROW) {
break;
}
} else if (type == INT_INSN) {
convertIntInsn((IntInsnNode) insn);
} else if (type == LDC_INSN) {
convertLdcInsn((LdcInsnNode) insn);
} else if (type == JUMP_INSN) {
JumpInsnNode jmp = (JumpInsnNode) insn;
convertJumpInsn(jmp);
int op = jmp.getOpcode();
if (op == JSR)
throw new UnsupportedOperationException("JSR!");
if (op != GOTO) {
/* ifX opcode, i.e. two successors */
AbstractInsnNode next = insn.getNext();
addEdges(insn, next, Collections.singletonList(jmp.label));
} else {
addEdges(insn, jmp.label, null);
}
break;
} else if (type == LOOKUPSWITCH_INSN) {
LookupSwitchInsnNode swtch = (LookupSwitchInsnNode) insn;
convertLookupSwitchInsn(swtch);
LabelNode dflt = swtch.dflt;
addEdges(insn, dflt, swtch.labels);
break;
} else if (type == METHOD_INSN) {
convertMethodInsn((MethodInsnNode) insn);
} else if (type == INVOKE_DYNAMIC_INSN) {
convertInvokeDynamicInsn((InvokeDynamicInsnNode) insn);
} else if (type == MULTIANEWARRAY_INSN) {
convertMultiANewArrayInsn((MultiANewArrayInsnNode) insn);
} else if (type == TABLESWITCH_INSN) {
TableSwitchInsnNode swtch = (TableSwitchInsnNode) insn;
convertTableSwitchInsn(swtch);
LabelNode dflt = swtch.dflt;
addEdges(insn, dflt, swtch.labels);
} else if (type == TYPE_INSN) {
convertTypeInsn((TypeInsnNode) insn);
} else if (type == VAR_INSN) {
if (insn.getOpcode() == RET)
throw new UnsupportedOperationException("RET!");
convertVarInsn((VarInsnNode) insn);
} else if (type == LABEL) {
convertLabel((LabelNode) insn);
} else if (type == LINE) {
convertLine((LineNumberNode) insn);
} else if (type == FRAME) {
// we can ignore it
} else
throw new RuntimeException("Unknown instruction type: " + type);
} while ((insn = insn.getNext()) != null);
} while (!worklist.isEmpty());
conversionWorklist = null;
edges = null;
}
use of org.objectweb.asm.tree.TypeInsnNode in project pinpoint by naver.
the class ASMMethodVariables method loadInterceptorLocalVariables.
public void loadInterceptorLocalVariables(final InsnList instructions, final InterceptorDefinition interceptorDefinition, final boolean after) {
assertInitializedInterceptorLocalVariables();
loadVar(instructions, this.interceptorVarIndex);
instructions.add(new TypeInsnNode(Opcodes.CHECKCAST, Type.getInternalName(interceptorDefinition.getInterceptorBaseClass())));
// target(this) object.
loadThis(instructions);
final InterceptorType interceptorType = interceptorDefinition.getInterceptorType();
if (interceptorType == InterceptorType.ARRAY_ARGS) {
// Object target, Object[] args
loadVar(instructions, this.argsVarIndex);
} else if (interceptorType == InterceptorType.STATIC) {
// Object target, String declaringClassInternalName, String methodName, String parameterDescription, Object[] args
loadVar(instructions, this.classNameVarIndex);
loadVar(instructions, this.methodNameVarIndex);
loadVar(instructions, this.parameterDescriptionVarIndex);
loadVar(instructions, this.argsVarIndex);
} else if (interceptorType == InterceptorType.API_ID_AWARE) {
// Object target, int apiId, Object[] args
loadInt(instructions, this.apiIdVarIndex);
loadVar(instructions, this.argsVarIndex);
} else if (interceptorType == InterceptorType.BASIC) {
int interceptorMethodParameterCount = getInterceptorParameterCount(interceptorDefinition);
int argumentCount = Math.min(this.argumentTypes.length, interceptorMethodParameterCount);
int i = 1;
for (; i <= argumentCount; i++) {
// Object target, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4
if (i == 1)
loadVar(instructions, this.arg0VarIndex);
else if (i == 2)
loadVar(instructions, this.arg1VarIndex);
else if (i == 3)
loadVar(instructions, this.arg2VarIndex);
else if (i == 4)
loadVar(instructions, this.arg3VarIndex);
else if (i == 5)
loadVar(instructions, this.arg4VarIndex);
else
loadNull(instructions);
}
for (; i <= interceptorMethodParameterCount; i++) {
loadNull(instructions);
}
}
if (after) {
loadVar(instructions, this.resultVarIndex);
loadVar(instructions, this.throwableVarIndex);
}
}
Aggregations