aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-06 16:18:15 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-07 14:23:24 -0800
commit69df5a06c4c0e2d0783ea32ad910fa23b14470a1 (patch)
tree4698c7ffe33283b40f0910c190b1d556cd7e8b06 /tools
parent2c95c2f3fd99ca6f96332bd51dcbe24d0e163d54 (diff)
unvarify later vars in asm when js optimizing
Diffstat (limited to 'tools')
-rw-r--r--tools/js-optimizer.js41
1 files changed, 29 insertions, 12 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 0697cdb9..222ebba0 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1201,6 +1201,24 @@ function loopOptimizer(ast) {
vacuum(ast);
}
+function unVarify(vars, ret) { // transform var x=1, y=2 etc. into (x=1, y=2), i.e., the same assigns, but without a var definition
+ ret = ret || [];
+ ret[0] = 'stat';
+ if (vars.length == 1) {
+ ret[1] = ['assign', true, ['name', vars[0][0]], vars[0][1]];
+ } else {
+ ret[1] = [];
+ var curr = ret[1];
+ for (var i = 0; i < vars.length-1; i++) {
+ curr[0] = 'seq';
+ curr[1] = ['assign', true, ['name', vars[i][0]], vars[i][1]];
+ if (i != vars.length-2) curr = curr[2] = [];
+ }
+ curr[2] = ['assign', true, ['name', vars[vars.length-1][0]], vars[vars.length-1][1]];
+ }
+ return ret;
+}
+
// asm.js support code - normalize (convert asm.js code to 'normal' JS, without
// annotations, plus explicit metadata) and denormalize (vice versa)
var ASM_INT = 0;
@@ -1246,6 +1264,15 @@ function normalizeAsm(func) {
});
i++;
}
+ // finally, look for other var definitions and collect them
+ while (i < stats.length) {
+ traverse(stats[i], function(node, type) {
+ if (type == 'var') {
+ unVarify(node[1], node);
+ }
+ });
+ i++;
+ }
//printErr('normalized \n\n' + astToSrc(func) + '\n\n');
return data;
}
@@ -1310,18 +1337,8 @@ function registerize(ast, asm) {
if (type == 'var') {
node[1].forEach(function(defined) { localVars[defined[0]] = 1 });
var vars = node[1].filter(function(varr) { return varr[1] });
- if (vars.length > 1) {
- var ret = ['stat', []];
- var curr = ret[1];
- for (var i = 0; i < vars.length-1; i++) {
- curr[0] = 'seq';
- curr[1] = ['assign', true, ['name', vars[i][0]], vars[i][1]];
- if (i != vars.length-2) curr = curr[2] = [];
- }
- curr[2] = ['assign', true, ['name', vars[vars.length-1][0]], vars[vars.length-1][1]];
- return ret;
- } else if (vars.length == 1) {
- return ['stat', ['assign', true, ['name', vars[0][0]], vars[0][1]]];
+ if (vars.length >= 1) {
+ return unVarify(vars);
} else {
return emptyNode();
}