aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-23 11:32:14 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-11-23 11:32:14 -0800
commitd29567b09b3b50f8be74d32e7ccbd99002bccc39 (patch)
tree88ed25e11733dacbee4b98adbd12206b5b859501
parent753437a56d63666d0761b66ead1b0d491c4bcb2b (diff)
improve eliminator
-rw-r--r--tools/eliminator/eliminator-test-output.js10
-rw-r--r--tools/eliminator/eliminator-test.js8
-rw-r--r--tools/eliminator/eliminator.coffee5
3 files changed, 20 insertions, 3 deletions
diff --git a/tools/eliminator/eliminator-test-output.js b/tools/eliminator/eliminator-test-output.js
index ccbd5e5f..594508d0 100644
--- a/tools/eliminator/eliminator-test-output.js
+++ b/tools/eliminator/eliminator-test-output.js
@@ -97,4 +97,12 @@ var anon = (function(x) {
function r($0) {
HEAP[$0 + 7] = 107;
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["f", "g", "h", "py", "r"]
+function t() {
+ if ($10 < $11) {
+ __label__ = 3;
+ }
+ if (!($12 < $13)) {
+ __label__ = 4;
+ }
+}
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["f", "g", "h", "py", "r", "t"]
diff --git a/tools/eliminator/eliminator-test.js b/tools/eliminator/eliminator-test.js
index 2443d707..02ac0c08 100644
--- a/tools/eliminator/eliminator-test.js
+++ b/tools/eliminator/eliminator-test.js
@@ -108,5 +108,11 @@ var anon = function(x) {
function r($0) {
HEAP[$0 + 5 + 2] = 99+5+2+1;
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["f", "g", "h", "py", "r"]
+function t() {
+ var $cmp2=($10) < ($11);
+ if ($cmp2) { __label__ = 3; }
+ var $cmp3=($12) < ($13);
+ if (!($cmp3)) { __label__ = 4; }
+}
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["f", "g", "h", "py", "r", "t"]
diff --git a/tools/eliminator/eliminator.coffee b/tools/eliminator/eliminator.coffee
index 62e7ef82..8b99338a 100644
--- a/tools/eliminator/eliminator.coffee
+++ b/tools/eliminator/eliminator.coffee
@@ -42,6 +42,7 @@ NODES_WITHOUT_SIDE_EFFECTS =
string: true
binary: true
sub: true
+ 'unary-prefix': true # ++x can have side effects, but we never have that in generated code
# Nodes which may break control flow. Moving a variable beyond them may have
# side effects.
@@ -148,7 +149,7 @@ class Eliminator
varName = node[1]
if @useCount.hasOwnProperty varName then @useCount[varName]++
else @isSingleDef[varName] = false
- else if type in ['assign', 'unary-prefix', 'unary-postfix']
+ else if type in ['assign']
varName = node[2][1]
if @isSingleDef[varName] then @isSingleDef[varName] = false
return undefined
@@ -374,6 +375,8 @@ main = ->
ast = uglify.parser.parse src
+ #process.stderr.write(JSON.stringify(ast) + '\n')
+
# Run on all functions.
traverse ast, (node, type) ->
if type in ['defun', 'function'] and isGenerated node[1]