# HG changeset patch # User Jaroslav Tulach # Date 1426155375 -3600 # Node ID ea9fd59c8b62e766bfc6fd7989ed6af2c469f0dd # Parent 5c30fa1c8c5b208d01306072596a516a6a25cfc0 Need to propagate flow to the goto generating methods diff -r 5c30fa1c8c5b -r ea9fd59c8b62 rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Mar 12 10:32:13 2015 +0100 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu Mar 12 11:16:15 2015 +0100 @@ -480,7 +480,7 @@ boolean changeInCatch = trap.advanceTo(i); if (changeInCatch || lastStackFrame != stackMapIterator.getFrameIndex()) { if (previousTrap != null) { - generateCatch(previousTrap, i, topMostLabel); + generateCatch(previousTrap, flow, i, topMostLabel); previousTrap = null; } } @@ -1002,106 +1002,106 @@ smapper.popD(), smapper.popD(), smapper.pushI()); break; case opc_if_acmpeq: - i = generateIf(smapper, byteCodes, i, smapper.popA(), smapper.popA(), + i = generateIf(smapper, flow, byteCodes, i, smapper.popA(), smapper.popA(), "===", topMostLabel); break; case opc_if_acmpne: - i = generateIf(smapper, byteCodes, i, smapper.popA(), smapper.popA(), + i = generateIf(smapper, flow, byteCodes, i, smapper.popA(), smapper.popA(), "!==", topMostLabel); break; case opc_if_icmpeq: - i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(), + i = generateIf(smapper, flow, byteCodes, i, smapper.popI(), smapper.popI(), "==", topMostLabel); break; case opc_ifeq: { int indx = i + readShortArg(byteCodes, i); - emitIf(smapper, this, "if ((@1) == 0) ", + emitIf(smapper, flow, this, "if ((@1) == 0) ", smapper.popI(), i, indx, topMostLabel); i += 2; break; } case opc_ifne: { int indx = i + readShortArg(byteCodes, i); - emitIf(smapper, this, "if ((@1) != 0) ", + emitIf(smapper, flow, this, "if ((@1) != 0) ", smapper.popI(), i, indx, topMostLabel); i += 2; break; } case opc_iflt: { int indx = i + readShortArg(byteCodes, i); - emitIf(smapper, this, "if ((@1) < 0) ", + emitIf(smapper, flow, this, "if ((@1) < 0) ", smapper.popI(), i, indx, topMostLabel); i += 2; break; } case opc_ifle: { int indx = i + readShortArg(byteCodes, i); - emitIf(smapper, this, "if ((@1) <= 0) ", + emitIf(smapper, flow, this, "if ((@1) <= 0) ", smapper.popI(), i, indx, topMostLabel); i += 2; break; } case opc_ifgt: { int indx = i + readShortArg(byteCodes, i); - emitIf(smapper, this, "if ((@1) > 0) ", + emitIf(smapper, flow, this, "if ((@1) > 0) ", smapper.popI(), i, indx, topMostLabel); i += 2; break; } case opc_ifge: { int indx = i + readShortArg(byteCodes, i); - emitIf(smapper, this, "if ((@1) >= 0) ", + emitIf(smapper, flow, this, "if ((@1) >= 0) ", smapper.popI(), i, indx, topMostLabel); i += 2; break; } case opc_ifnonnull: { int indx = i + readShortArg(byteCodes, i); - emitIf(smapper, this, "if ((@1) !== null) ", + emitIf(smapper, flow, this, "if ((@1) !== null) ", smapper.popA(), i, indx, topMostLabel); i += 2; break; } case opc_ifnull: { int indx = i + readShortArg(byteCodes, i); - emitIf(smapper, this, "if ((@1) === null) ", + emitIf(smapper, flow, this, "if ((@1) === null) ", smapper.popA(), i, indx, topMostLabel); i += 2; break; } case opc_if_icmpne: - i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(), + i = generateIf(smapper, flow, byteCodes, i, smapper.popI(), smapper.popI(), "!=", topMostLabel); break; case opc_if_icmplt: - i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(), + i = generateIf(smapper, flow, byteCodes, i, smapper.popI(), smapper.popI(), "<", topMostLabel); break; case opc_if_icmple: - i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(), + i = generateIf(smapper, flow, byteCodes, i, smapper.popI(), smapper.popI(), "<=", topMostLabel); break; case opc_if_icmpgt: - i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(), + i = generateIf(smapper, flow, byteCodes, i, smapper.popI(), smapper.popI(), ">", topMostLabel); break; case opc_if_icmpge: - i = generateIf(smapper, byteCodes, i, smapper.popI(), smapper.popI(), + i = generateIf(smapper, flow, byteCodes, i, smapper.popI(), smapper.popI(), ">=", topMostLabel); break; case opc_goto: { smapper.flush(this); int indx = i + readShortArg(byteCodes, i); - goTo(this, i, indx, topMostLabel); + goTo(this, flow, i, indx, topMostLabel); i += 2; break; } case opc_lookupswitch: { - i = generateLookupSwitch(i, byteCodes, smapper, topMostLabel); + i = generateLookupSwitch(i, byteCodes, smapper, flow, topMostLabel); break; } case opc_tableswitch: { - i = generateTableSwitch(i, byteCodes, smapper, topMostLabel); + i = generateTableSwitch(i, byteCodes, smapper, flow, topMostLabel); break; } case opc_invokeinterface: { @@ -1510,7 +1510,7 @@ } } if (previousTrap != null) { - generateCatch(previousTrap, byteCodes.length, topMostLabel); + generateCatch(previousTrap, flow, byteCodes.length, topMostLabel); } if (didBranches) { append("\n }\n"); @@ -1526,16 +1526,13 @@ return defineProp; } - private int generateIf(StackMapper mapper, byte[] byteCodes, - int i, final CharSequence v2, final CharSequence v1, - final String test, int topMostLabel - ) throws IOException { + private int generateIf(StackMapper mapper, Flow flow, byte[] byteCodes, int i, final CharSequence v2, final CharSequence v1, final String test, int topMostLabel) throws IOException { mapper.flush(this); int indx = i + readShortArg(byteCodes, i); append("if ((").append(v1) .append(") ").append(test).append(" (") .append(v2).append(")) "); - goTo(this, i, indx, topMostLabel); + goTo(this, flow, i, indx, topMostLabel); return i + 2; } @@ -2249,7 +2246,7 @@ out.append(format, processed, length); } - private void generateCatch(TrapData[] traps, int current, int topMostLabel) throws IOException { + private void generateCatch(TrapData[] traps, Flow flow, int current, int topMostLabel) throws IOException { append("} catch (e) {\n"); int finallyPC = -1; for (TrapData e : traps) { @@ -2262,7 +2259,7 @@ append("e = vm.java_lang_Class(false).bck2BrwsrThrwrbl(e);"); append("if (e['$instOf_" + classInternalName.replace('/', '_') + "']) {"); append("var stA0 = e;"); - goTo(this, current, e.handler_pc, topMostLabel); + goTo(this, flow, current, e.handler_pc, topMostLabel); append("}\n"); } else { finallyPC = e.handler_pc; @@ -2272,12 +2269,12 @@ append("throw e;"); } else { append("var stA0 = e;"); - goTo(this, current, finallyPC, topMostLabel); + goTo(this, flow, current, finallyPC, topMostLabel); } append("\n}"); } - private static void goTo(Appendable out, int current, int to, int canBack) throws IOException { + private static void goTo(Appendable out, Flow flow, int current, int to, int canBack) throws IOException { if (to < current) { if (canBack < to) { out.append("{ gt = 0; continue X_" + to + "; }"); @@ -2290,14 +2287,11 @@ } private static void emitIf( - StackMapper sm, - Appendable out, String pattern, - CharSequence param, - int current, int to, int canBack + StackMapper sm, Flow flow, Appendable out, String pattern, CharSequence param, int current, int to, int canBack ) throws IOException { sm.flush(out); emitImpl(out, pattern, param); - goTo(out, current, to, canBack); + goTo(out, flow, current, to, canBack); } private void generateNewArray(int atype, final StackMapper smapper) throws IOException, IllegalStateException { @@ -2355,7 +2349,7 @@ return i; } - private int generateTableSwitch(int i, final byte[] byteCodes, final StackMapper smapper, int topMostLabel) throws IOException { + private int generateTableSwitch(int i, final byte[] byteCodes, final StackMapper smapper, Flow flow, int topMostLabel) throws IOException { int table = i / 4 * 4 + 4; int dflt = i + readInt4(byteCodes, table); table += 4; @@ -2369,17 +2363,17 @@ while (low <= high) { int offset = i + readInt4(byteCodes, table); table += 4; - append(" case " + low).append(":"); goTo(this, i, offset, topMostLabel); append('\n'); + append(" case " + low).append(":"); goTo(this, flow, i, offset, topMostLabel); append('\n'); low++; } append(" default: "); - goTo(this, i, dflt, topMostLabel); + goTo(this, flow, i, dflt, topMostLabel); append("\n}"); i = table - 1; return i; } - private int generateLookupSwitch(int i, final byte[] byteCodes, final StackMapper smapper, int topMostLabel) throws IOException { + private int generateLookupSwitch(int i, final byte[] byteCodes, final StackMapper smapper, Flow flow, int topMostLabel) throws IOException { int table = i / 4 * 4 + 4; int dflt = i + readInt4(byteCodes, table); table += 4; @@ -2393,10 +2387,10 @@ table += 4; int offset = i + readInt4(byteCodes, table); table += 4; - append(" case " + cnstnt).append(": "); goTo(this, i, offset, topMostLabel); append('\n'); + append(" case " + cnstnt).append(": "); goTo(this, flow, i, offset, topMostLabel); append('\n'); } append(" default: "); - goTo(this, i, dflt, topMostLabel); + goTo(this, flow, i, dflt, topMostLabel); append("\n}"); i = table - 1; return i;