Java Code Examples for org.objectweb.asm.tree.InsnNode#getOpcode()

The following examples show how to use org.objectweb.asm.tree.InsnNode#getOpcode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private void convertArrayLoadInsn(InsnNode insn) {
	StackFrame frame = getFrame(insn);
	Operand[] out = frame.out();
	Operand opr;
	if (out == null) {
		Operand indx = popImmediate();
		Operand base = popImmediate();
		ArrayRef ar = Jimple.v().newArrayRef(
				base.stackOrValue(), indx.stackOrValue());
		indx.addBox(ar.getIndexBox());
		base.addBox(ar.getBaseBox());
		opr = new Operand(insn, ar);
		frame.in(indx, base);
		frame.boxes(ar.getIndexBox(), ar.getBaseBox());
		frame.out(opr);
	} else {
		opr = out[0];
		frame.mergeIn(pop(), pop());
	}
	int op = insn.getOpcode();
	if (op == DALOAD || op == LALOAD)
		pushDual(opr);
	else
		push(opr);
}
 
Example 2
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
private void convertArrayStoreInsn(InsnNode insn) {
	int op = insn.getOpcode();
	boolean dword = op == LASTORE || op == DASTORE;
	StackFrame frame = getFrame(insn);
	if (!units.containsKey(insn)) {
		Operand valu = dword ? popImmediateDual() : popImmediate();
		Operand indx = popImmediate();
		Operand base = popLocal();
		ArrayRef ar = Jimple.v().newArrayRef(
				base.stackOrValue(), indx.stackOrValue());
		indx.addBox(ar.getIndexBox());
		base.addBox(ar.getBaseBox());
		AssignStmt as = Jimple.v().newAssignStmt(ar, valu.stackOrValue());
		valu.addBox(as.getRightOpBox());
		frame.in(valu, indx, base);
		frame.boxes(as.getRightOpBox(),
				ar.getIndexBox(), ar.getBaseBox());
		setUnit(insn, as);
	} else {
		frame.mergeIn(dword ? popDual() : pop(), pop(), pop());
	}
}
 
Example 3
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void convertConstInsn(InsnNode insn) {
	int op = insn.getOpcode();
	StackFrame frame = getFrame(insn);
	Operand[] out = frame.out();
	Operand opr;
	if (out == null) {
		Value v;
		if (op == ACONST_NULL)
			v = NullConstant.v();
		else if (op >= ICONST_M1 && op <= ICONST_5)
			v = IntConstant.v(op - ICONST_0);
		else if (op == LCONST_0 || op == LCONST_1)
			v = LongConstant.v(op - LCONST_0);
		else if (op >= FCONST_0 && op <= FCONST_2)
			v = FloatConstant.v(op - FCONST_0);
		else if (op == DCONST_0 || op == DCONST_1)
			v = DoubleConstant.v(op - DCONST_0);
		else
			throw new AssertionError("Unknown constant opcode: " + op);
		opr = new Operand(insn, v);
		frame.out(opr);
	} else {
		opr = out[0];
	}
	if (op == LCONST_0 || op == LCONST_1 ||
			op == DCONST_0 || op == DCONST_1) {
		pushDual(opr);
	} else {
		push(opr);
	}
}
 
Example 4
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void convertUnopInsn(InsnNode insn) {
	int op = insn.getOpcode();
	boolean dword = op == LNEG || op == DNEG;
	StackFrame frame = getFrame(insn);
	Operand[] out = frame.out();
	Operand opr;
	if (out == null) {
		Operand op1 = dword ? popImmediateDual() : popImmediate();
		Value v1 = op1.stackOrValue();
		UnopExpr unop;
		if (op >= INEG && op <= DNEG)
			unop = Jimple.v().newNegExpr(v1);
		else if (op == ARRAYLENGTH)
			unop = Jimple.v().newLengthExpr(v1);
		else
			throw new AssertionError("Unknown unop: " + op);
		op1.addBox(unop.getOpBox());
		opr = new Operand(insn, unop);
		frame.in(op1);
		frame.boxes(unop.getOpBox());
		frame.out(opr);
	} else {
		opr = out[0];
		frame.mergeIn(dword ? popDual() : pop());
	}
	if (dword)
		pushDual(opr);
	else
		push(opr);
}
 
Example 5
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private void convertReturnInsn(InsnNode insn) {
	int op = insn.getOpcode();
	boolean dword = op == LRETURN || op == DRETURN;
	StackFrame frame = getFrame(insn);
	if (!units.containsKey(insn)) {
		Operand val = dword ? popImmediateDual() : popImmediate();
		ReturnStmt ret = Jimple.v().newReturnStmt(val.stackOrValue());
		val.addBox(ret.getOpBox());
		frame.in(val);
		frame.boxes(ret.getOpBox());
		setUnit(insn, ret);
	} else {
		frame.mergeIn(dword ? popDual() : pop());
	}
}
 
Example 6
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private void convertBinopInsn(InsnNode insn) {
	int op = insn.getOpcode();
	boolean dword = op == DADD || op == LADD ||
			op == DSUB || op == LSUB ||
			op == DMUL || op == LMUL ||
			op == DDIV || op == LDIV ||
			op == DREM || op == LREM ||
			op == LSHL || op == LSHR ||
			op == LUSHR || op == LAND ||
			op == LOR || op == LXOR ||
			op == LCMP || op == DCMPL ||
			op == DCMPG;
	StackFrame frame = getFrame(insn);
	Operand[] out = frame.out();
	Operand opr;
	if (out == null) {
		Operand op2 = (dword && op != LSHL && op != LSHR && op != LUSHR) ?
				popImmediateDual() : popImmediate();
		Operand op1 = dword ? popImmediateDual() : popImmediate();
		Value v1 = op1.stackOrValue();
		Value v2 = op2.stackOrValue();
		BinopExpr binop;
		if (op >= IADD && op <= DADD)
			binop = Jimple.v().newAddExpr(v1, v2);
		else if (op >= ISUB && op <= DSUB)
			binop = Jimple.v().newSubExpr(v1, v2);
		else if (op >= IMUL && op <= DMUL)
			binop = Jimple.v().newMulExpr(v1, v2);
		else if (op >= IDIV && op <= DDIV)
			binop = Jimple.v().newDivExpr(v1, v2);
		else if (op >= IREM && op <= DREM)
			binop = Jimple.v().newRemExpr(v1, v2);
		else if (op >= ISHL && op <= LSHL)
			binop = Jimple.v().newShlExpr(v1, v2);
		else if (op >= ISHR && op <= LSHR)
			binop = Jimple.v().newShrExpr(v1, v2);
		else if (op >= IUSHR && op <= LUSHR)
			binop = Jimple.v().newUshrExpr(v1, v2);
		else if (op >= IAND && op <= LAND)
			binop = Jimple.v().newAndExpr(v1, v2);
		else if (op >= IOR && op <= LOR)
			binop = Jimple.v().newOrExpr(v1, v2);
		else if (op >= IXOR && op <= LXOR)
			binop = Jimple.v().newXorExpr(v1, v2);
		else if (op == LCMP)
			binop = Jimple.v().newCmpExpr(v1, v2);
		else if (op == FCMPL || op == DCMPL)
			binop = Jimple.v().newCmplExpr(v1, v2);
		else if (op == FCMPG || op == DCMPG)
			binop = Jimple.v().newCmpgExpr(v1, v2);
		else
			throw new AssertionError("Unknown binop: " + op);
		op1.addBox(binop.getOp1Box());
		op2.addBox(binop.getOp2Box());
		opr = new Operand(insn, binop);
		frame.in(op2, op1);
		frame.boxes(binop.getOp2Box(), binop.getOp1Box());
		frame.out(opr);
	} else {
		opr = out[0];
		if (dword) {
			if (op != LSHL && op != LSHR && op != LUSHR)
				frame.mergeIn(popDual(), popDual());
			else
				frame.mergeIn(pop(), popDual());
		} else {
			frame.mergeIn(pop(), pop());
		}
	}
	if (dword && (op < LCMP || op > DCMPG))
		pushDual(opr);
	else
		push(opr);
}
 
Example 7
Source File: AsmMethodSource.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
private void convertPrimCastInsn(InsnNode insn) {
	int op = insn.getOpcode();
	boolean tod = op == I2L || op == I2D ||
			op == F2L || op == F2D ||
			op == D2L || op == L2D;
	boolean fromd = op == D2L || op == L2D ||
			op == D2I || op == L2I ||
			op == D2F || op == L2F;
	StackFrame frame = getFrame(insn);
	Operand[] out = frame.out();
	Operand opr;
	if (out == null) {
		Type totype;
		if (op == I2L || op == F2L || op == D2L)
			totype = LongType.v();
		else if (op == L2I || op == F2I || op == D2I)
			totype = IntType.v();
		else if (op == I2F || op == L2F || op == D2F)
			totype = FloatType.v();
		else if (op == I2D || op == L2D || op == F2D)
			totype = DoubleType.v();
		else if (op == I2B)
			totype = ByteType.v();
		else if (op == I2S)
			totype = ShortType.v();
		else if (op == I2C)
			totype = CharType.v();
		else
			throw new AssertionError("Unknonw prim cast op: " + op);
		Operand val = fromd ? popImmediateDual() : popImmediate();
		CastExpr cast = Jimple.v().newCastExpr(val.stackOrValue(), totype);
		opr = new Operand(insn, cast);
		val.addBox(cast.getOpBox());
		frame.in(val);
		frame.boxes(cast.getOpBox());
		frame.out(opr);
	} else {
		opr = out[0];
		frame.mergeIn(fromd ? popDual() : pop());
	}
	if (tod)
		pushDual(opr);
	else
		push(opr);
}