diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/eliminator/asm-eliminator-test-output.js | 15 | ||||
-rw-r--r-- | tools/eliminator/asm-eliminator-test.js | 15 | ||||
-rw-r--r-- | tools/js-optimizer.js | 13 | ||||
-rw-r--r-- | tools/shared.py | 4 |
4 files changed, 39 insertions, 8 deletions
diff --git a/tools/eliminator/asm-eliminator-test-output.js b/tools/eliminator/asm-eliminator-test-output.js index 4cf15c62..e477c320 100644 --- a/tools/eliminator/asm-eliminator-test-output.js +++ b/tools/eliminator/asm-eliminator-test-output.js @@ -108,4 +108,19 @@ function label() { i(); } } +function switchy() { + var no = 0, yes = 0; + while (1) switch (label | 0) { + case x: + no = 100; + break; + case y: + yes = 111; + yes = yes * 2; + print(yes); + yes--; + print(yes / 2); + continue; + } +} diff --git a/tools/eliminator/asm-eliminator-test.js b/tools/eliminator/asm-eliminator-test.js index d2c0507c..acc07edb 100644 --- a/tools/eliminator/asm-eliminator-test.js +++ b/tools/eliminator/asm-eliminator-test.js @@ -141,5 +141,20 @@ function label() { i(); } } +function switchy() { + var no = 0, yes = 0; + while (1) switch (label | 0) { + case x: + no = 100; // eliminatable in theory, but eliminator does not look into switch. must leave def above as well. + break; + case y: + yes = 111; + yes = yes*2; + print(yes); + yes--; + print(yes/2); + continue; + } +} // EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "__Z11printResultPiS_j", "_segment_holding", "__ZN5identC2EiPKcPci", "_vec2Length", "exc", "label"] diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 5ede0ce8..598287db 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -1765,6 +1765,7 @@ function eliminate(ast, memSafe) { var values = {}; var locals = {}; var varsToRemove = {}; // variables being removed, that we can eliminate all 'var x;' of (this refers to 'var' nodes we should remove) + // 1 means we should remove it, 2 means we successfully removed it var varsToTryToRemove = {}; // variables that have 0 uses, but have side effects - when we scan we can try to remove them // add arguments as locals if (func[2]) { @@ -1822,7 +1823,7 @@ function eliminate(ast, memSafe) { }); } if (!hasSideEffects) { - varsToRemove[name] = 1; // remove it normally + varsToRemove[name] = !definitions[name] ? 2 : 1; // remove it normally sideEffectFree[name] = true; } else { varsToTryToRemove[name] = 1; // try to remove it later during scanning @@ -1979,7 +1980,7 @@ function eliminate(ast, memSafe) { for (var i = 0; i < value.length; i++) { node[i] = value[i]; } - varsToRemove[name] = 1; + varsToRemove[name] = 2; } } else { if (allowTracking) track(name, node[3], node); @@ -2019,7 +2020,7 @@ function eliminate(ast, memSafe) { for (var i = 0; i < value.length; i++) { node[i] = value[i]; } - varsToRemove[name] = 1; + varsToRemove[name] = 2; } } } @@ -2123,7 +2124,7 @@ function eliminate(ast, memSafe) { function doEliminate(name, node) { //printErr('elim!!!!! ' + name); // yes, eliminate! - varsToRemove[name] = 1; // both assign and var definitions can have other vars we must clean up + varsToRemove[name] = 2; // both assign and var definitions can have other vars we must clean up var info = tracked[name]; delete tracked[name]; var defNode = info.defNode; @@ -2181,7 +2182,7 @@ function eliminate(ast, memSafe) { //printErr('cleaning up ' + JSON.stringify(varsToRemove)); traverse(func, function(node, type) { if (type === 'var') { - node[1] = node[1].filter(function(pair) { return !(pair[0] in varsToRemove) }); + node[1] = node[1].filter(function(pair) { return !varsToRemove[pair[0]] }); if (node[1].length == 0) { // wipe out an empty |var;| node[0] = 'toplevel'; @@ -2192,7 +2193,7 @@ function eliminate(ast, memSafe) { if (asm) { for (var v in varsToRemove) { - delete asmData.vars[v]; + if (varsToRemove[v] == 2) delete asmData.vars[v]; } denormalizeAsm(func, asmData); } diff --git a/tools/shared.py b/tools/shared.py index a53c0a7b..eedb2e8b 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -729,13 +729,13 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e basename = os.path.basename(f) cache[cache_name].append((basename, open(f, 'rb').read())) break - except: + except Exception, e: if i > 0: # Due to the ugly hack above our best guess is to output the first run with open_make_err(0) as ferr: for line in ferr: sys.stderr.write(line) - raise Exception('could not build library ' + name) + raise Exception('could not build library ' + name + ' due to exception ' + str(e)) if old_dir: os.chdir(old_dir) return generated_libs |