fix jasmin support and j2ir

--HG--
branch : 2.x
This commit is contained in:
Bob Pan 2015-02-21 01:11:09 +08:00
parent b13f6f284f
commit db2eb2d775
3 changed files with 28 additions and 19 deletions

View File

@ -863,7 +863,7 @@ OP0 : 'nop'|'monitorenter'|'monitorexit'|'pop2'|'pop'
|'aconst_null'
|('a'|'d'|'f'|'i'|'l')? 'return'
|('a'|'d'|'f'|'i'|'l') ('store'|'load') '_' ('0'..'3')
|('a'|'d'|'f'|'i'|'l') ('astore'|'aload')
|('a'|'b'|'d'|'f'|'i'|'l') ('astore'|'aload')
|'dcmpg'|'dcmpl' | 'lcmp' |'fcmpg'|'fcmpl'
|'athrow'
|('i'|'f'|'d'|'l')('add'|'div'|'sub'|'mul'|'rem'|'shl'|'shr'|'ushr'|'and'|'or'|'xor'|'neg')
@ -1110,6 +1110,9 @@ sMethod @init{
if(mn.exceptions==null){
mn.exceptions=new ArrayList<>();
}
if(mn.tryCatchBlocks==null){
mn.tryCatchBlocks=new ArrayList<>();
}
}
: '.method' i=sAccList n=sMemberName t=sMethodDesc {mn.access|=i;mn.name=$n.name;mn.desc=unEscape($t.text);}
(s=sSigAttr{mn.signature=$s.sig;}

View File

@ -358,20 +358,21 @@ public class IR2JConverter implements Opcodes {
asm.visitInsn(ATHROW);
break;
case VOID_INVOKE:
InvokeExpr invokeExpr = (InvokeExpr) st.getOp();
accept(invokeExpr, asm);
String ret = invokeExpr.ret;
if (invokeExpr.vt == VT.INVOKE_NEW) {
Value op = st.getOp();
accept(op, asm);
String ret = op.valueType;
if (op.vt == VT.INVOKE_NEW) {
asm.visitInsn(POP);
} else if (!"V".equals(ret)) {
switch (ret.charAt(0)) {
case 'J':
case 'D':
asm.visitInsn(POP2);
break;
default:
asm.visitInsn(POP);
break;
case 'J':
case 'D':
asm.visitInsn(POP2);
break;
default:
asm.visitInsn(POP);
break;
}
}
break;

View File

@ -392,7 +392,7 @@ public class J2IRConverter {
@Override
public JvmValue unaryOperation(AbstractInsnNode insn, JvmValue value0) throws AnalyzerException {
Local local = getLocal(value0);
Local local = value0 == null ? null : getLocal(value0);
switch (insn.getOpcode()) {
case INEG:
return b(1, Exprs.nNeg(local, "I"));
@ -525,7 +525,8 @@ public class J2IRConverter {
emit(Stmts.nThrow(local));
return null;
case CHECKCAST:
desc = "L" + ((TypeInsnNode) insn).desc + ";";
String orgDesc = ((TypeInsnNode) insn).desc;
desc = orgDesc.startsWith("[") ? orgDesc : ("L" + orgDesc + ";");
return b(1, Exprs.nCheckCast(local, desc));
case INSTANCEOF:
return b(1, Exprs.nInstanceOf(local, "L" + ((TypeInsnNode) insn).desc + ";"));
@ -543,6 +544,9 @@ public class J2IRConverter {
emit(Stmts.nIf(Exprs.nNe(local, Exprs.nNull(), "L"),
getLabel(((JumpInsnNode) insn).label)));
return null;
case GOTO: // special case
emit(Stmts.nGoto(getLabel(((JumpInsnNode) insn).label)));
return null;
default:
throw new Error("Internal error.");
}
@ -811,7 +815,7 @@ public class J2IRConverter {
};
}
private Local getLocal(JvmValue value) {
Local getLocal(JvmValue value) {
Local local = value.local;
if (local == null) {
local = value.local = newLocal();
@ -958,14 +962,15 @@ public class J2IRConverter {
@Override
public void execute(AbstractInsnNode insn, Interpreter<JvmValue> interpreter) throws AnalyzerException {
if (insn.getType() == AbstractInsnNode.FRAME || insn.getType() == AbstractInsnNode.LINE || insn.getType()==AbstractInsnNode.LABEL) {
if (insn.getType() == AbstractInsnNode.FRAME || insn.getType() == AbstractInsnNode.LINE || insn.getType() == AbstractInsnNode.LABEL) {
return;
}
if(insn.getOpcode()==44){
System.out.print("");
}
if (insn.getOpcode() == Opcodes.RETURN) {
interpreter.returnOperation(insn, null, null);
} else if (insn.getOpcode() == Opcodes.GOTO) {
interpreter.unaryOperation(insn, null);
} else if (insn.getOpcode() == RET) {
throw new RuntimeException("not support yet!");
} else {
super.execute(insn, interpreter);
}