diff options
-rw-r--r-- | tools/js-optimizer.js | 3 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-outline1-output.js | 133 | ||||
-rw-r--r-- | tools/test-js-optimizer-asm-outline1.js | 40 |
3 files changed, 176 insertions, 0 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 788a76ed..34fc028b 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -3032,6 +3032,9 @@ function outline(ast) { } var ignore = []; traverse(func, function(node) { + if (node[0] === 'while' && node[2][0] !== 'block') { + node[2] = ['block', [node[2]]]; // so we have a list of statements and can flatten while(1) switch + } var stats = getStatements(node); if (stats) { for (var i = 0; i < stats.length; i++) { diff --git a/tools/test-js-optimizer-asm-outline1-output.js b/tools/test-js-optimizer-asm-outline1-output.js index 612da16a..27f93d8a 100644 --- a/tools/test-js-optimizer-asm-outline1-output.js +++ b/tools/test-js-optimizer-asm-outline1-output.js @@ -372,6 +372,57 @@ function switchh() { } STACKTOP = sp; } +function switchh2() { + var helper$0 = 0, helper$1 = 0, sp = 0; + sp = STACKTOP; + STACKTOP = STACKTOP + 280 | 0; + while (1) { + helper$0 = 1; + helper$1 = x; + if (helper$0) { + helper$0 = 0; + switch (helper$1 | 0) { + case 0: + f(0); + g(); + break; + default: + { + helper$0 = 1; + } + } + } + HEAP32[sp + 8 >> 2] = helper$0; + HEAP32[sp + 16 >> 2] = helper$1; + HEAP32[sp + 40 >> 2] = 0; + HEAP32[sp + 44 >> 2] = 0; + switchh2$2(sp); + helper$0 = HEAP32[sp + 8 >> 2] | 0; + tempValue = HEAP32[sp + 40 >> 2] | 0; + tempInt = HEAP32[sp + 44 >> 2] | 0; + tempDouble = +HEAPF32[sp + 44 >> 2]; + HEAP32[sp + 40 >> 2] = 0; + HEAP32[sp + 44 >> 2] = 0; + if ((tempValue | 0) == 5) { + STACKTOP = sp; + return; + } + HEAP32[sp + 8 >> 2] = helper$0; + HEAP32[sp + 16 >> 2] = helper$1; + HEAP32[sp + 32 >> 2] = 0; + HEAP32[sp + 36 >> 2] = 0; + switchh2$1(sp); + helper$0 = HEAP32[sp + 8 >> 2] | 0; + if (helper$0) { + helper$0 = 0; + HEAP32[sp + 16 >> 2] = helper$1; + HEAP32[sp + 24 >> 2] = 0; + HEAP32[sp + 28 >> 2] = 0; + switchh2$0(sp); + } + } + STACKTOP = sp; +} function lin$0(sp) { sp = sp | 0; c(14); @@ -793,4 +844,86 @@ function switchh$2(sp) { } while (0); HEAP32[sp + 8 >> 2] = helper$0; } +function switchh2$0(sp) { + sp = sp | 0; + var helper$1 = 0; + helper$1 = HEAP32[sp + 16 >> 2] | 0; + switch (helper$1 | 0) { + case 4: + f(4); + g(); + case 5: + f(5); + g(); + case 6: + f(6); + g(); + default: + print(9); + } +} +function switchh2$1(sp) { + sp = sp | 0; + var helper$0 = 0, helper$1 = 0; + helper$0 = HEAP32[sp + 8 >> 2] | 0; + helper$1 = HEAP32[sp + 16 >> 2] | 0; + if (helper$0) { + helper$0 = 0; + switch (helper$1 | 0) { + case 21: + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 28: + case 29: + case 3: + f(3); + g(); + break; + default: + { + helper$0 = 1; + } + } + } + HEAP32[sp + 8 >> 2] = helper$0; +} +function switchh2$2(sp) { + sp = sp | 0; + var helper$0 = 0, helper$1 = 0; + helper$0 = HEAP32[sp + 8 >> 2] | 0; + helper$1 = HEAP32[sp + 16 >> 2] | 0; + OL : do { + if (helper$0) { + helper$0 = 0; + switch (helper$1 | 0) { + case 1: + f(1); + g(); + return; + default: + { + helper$0 = 1; + } + } + } + if (helper$0) { + helper$0 = 0; + switch (helper$1 | 0) { + case 2: + f(2); + g(); + break; + default: + { + helper$0 = 1; + } + } + } + } while (0); + HEAP32[sp + 8 >> 2] = helper$0; +} diff --git a/tools/test-js-optimizer-asm-outline1.js b/tools/test-js-optimizer-asm-outline1.js index 4282ec8e..b7ec9011 100644 --- a/tools/test-js-optimizer-asm-outline1.js +++ b/tools/test-js-optimizer-asm-outline1.js @@ -307,5 +307,45 @@ function switchh() { } } } +function switchh2() { + while (1) switch (x) { + case 0: + f(0); + g(); + break; + case 1: + f(1); + g(); + return; + case 2: + f(2); + g(); + break; + case 21: // gotta keem em unseparated + case 22: + case 23: + case 24: + case 25: + case 26: + case 27: + case 28: + case 29: + case 3: // these too + f(3); + g(); + break; + case 4: + f(4); + g(); + case 5: + f(5); + g(); + case 6: + f(6); + g(); + default: + print(9); + } +} // EMSCRIPTEN_GENERATED_FUNCTIONS // EXTRA_INFO: { "sizeToOutline": 30, "allowCostlyOutlines": 1 } |