diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-06 19:23:34 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-07 14:23:24 -0800 |
commit | f0b6b3d2ad45a81e7d92d7491b38a3cad8a08ef5 (patch) | |
tree | b3f55db088eea10116c76e0ef7530f5f4f2da50a /tools | |
parent | cdaf0e156e7eed0d8d591bddc143df55017dfb4f (diff) |
make normalizeAsm not get confused when a var later has an unneeded 'var' before it
Diffstat (limited to 'tools')
-rw-r--r-- | tools/eliminator/asm-eliminator-test-output.js | 26 | ||||
-rw-r--r-- | tools/eliminator/asm-eliminator-test.js | 33 | ||||
-rw-r--r-- | tools/js-optimizer.js | 14 |
3 files changed, 70 insertions, 3 deletions
diff --git a/tools/eliminator/asm-eliminator-test-output.js b/tools/eliminator/asm-eliminator-test-output.js index 70eca01a..3170bd9c 100644 --- a/tools/eliminator/asm-eliminator-test-output.js +++ b/tools/eliminator/asm-eliminator-test-output.js @@ -74,4 +74,30 @@ function _vec2Length($this) { STACKTOP = __stackBase__; return 0; } +function exc($this) { + $this = $this | 0; + var $1 = 0, $5 = 0; + $1 = (function() { + try { + __THREW__ = false; + return __ZNSt3__16locale8__globalEv(); + } catch (e) { + if (typeof e != "number") throw e; + if (ABORT) throw e; + __THREW__ = true; + Module.print("Exception: " + e + ", currently at: " + (new Error).stack); + return null; + } + })(); + if (!__THREW__) { + $5 = HEAP32[(($1 | 0) & 16777215) >> 2] | 0; + HEAP32[(($this | 0) & 16777215) >> 2] = $5; + __ZNSt3__114__shared_count12__add_sharedEv($5 | 0); + return; + } else { + $8$0 = ___cxa_find_matching_catch(HEAP32[(_llvm_eh_exception.buf & 16777215) >> 2] | 0, HEAP32[(_llvm_eh_exception.buf + 4 & 16777215) >> 2] | 0, []); + $8$1 = tempRet0; + ___cxa_call_unexpected($8$0); + } +} diff --git a/tools/eliminator/asm-eliminator-test.js b/tools/eliminator/asm-eliminator-test.js index 2fcf90d4..ce34a7a6 100644 --- a/tools/eliminator/asm-eliminator-test.js +++ b/tools/eliminator/asm-eliminator-test.js @@ -99,5 +99,36 @@ function _vec2Length($this) { STACKTOP = __stackBase__; return 0; } -// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "__Z11printResultPiS_j", "_segment_holding", "__ZN5identC2EiPKcPci", "_vec2Length"] +function exc($this) { + $this = $this | 0; + var $1 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0, $8 = +0, $9 = 0; + var label = 0; + var $1 = (function() { + try { + __THREW__ = false; + return __ZNSt3__16locale8__globalEv(); + } catch (e) { + if (typeof e != "number") throw e; + if (ABORT) throw e; + __THREW__ = true; + Module.print("Exception: " + e + ", currently at: " + (new Error).stack); + return null; + } + })(); + if (!__THREW__) { + $3 = $this | 0; + $4 = $1 | 0; + $5 = HEAP32[($4 & 16777215) >> 2] | 0; + HEAP32[($3 & 16777215) >> 2] = $5; + $6 = $5 | 0; + __ZNSt3__114__shared_count12__add_sharedEv($6); + return; + } else { + $8$0 = ___cxa_find_matching_catch(HEAP32[(_llvm_eh_exception.buf & 16777215) >> 2] | 0, HEAP32[(_llvm_eh_exception.buf + 4 & 16777215) >> 2] | 0, []); + $8$1 = tempRet0; + $9 = $8$0; + ___cxa_call_unexpected($9); + } +} +// EMSCRIPTEN_GENERATED_FUNCTIONS: ["asm", "__Z11printResultPiS_j", "_segment_holding", "__ZN5identC2EiPKcPci", "_vec2Length", "exc"] diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index daa08fe5..78553771 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -1259,8 +1259,18 @@ function normalizeAsm(func) { var node = stats[i]; if (node[0] != 'var') break; node[1].forEach(function(v) { - data.vars[v[0]] = detectAsmCoercion(v[1]); - v.length = 1; // make an un-assigning var + var name = v[0]; + var value = v[1]; + if (!(name in data.vars)) { + assert(value[0] == 'num' || (value[0] == 'unary-prefix' && value[2][0] == 'num')); // must be valid coercion no-op + data.vars[name] = detectAsmCoercion(value); + v.length = 1; // make an un-assigning var + } else { + // known var, just an unneeded 'var ' that when removed leaves an assign + assert(node[1].length == 1); + node[0] = 'stat'; + node[1] = ['assign', true, ['name', name], value]; + } }); i++; } |