aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-07-17 13:38:12 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-17 13:38:12 -0700
commitf02de71371a80e00275845a9a9b3f5f92d22a100 (patch)
tree8ea56f0248a353801b9d5ba612de42fdcfcef30d /tools/js-optimizer.js
parent3eba3acd59c9700feeea136c30e0e21bb3e28814 (diff)
refactor stack bump node search
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js25
1 files changed, 16 insertions, 9 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 7d1f3c16..ad98a3f2 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -1685,6 +1685,20 @@ function getFirstIndexInNormalized(func, data) {
return i+1;
}
+function getStackBumpNode(ast) {
+ var found = null;
+ traverse(ast, function(node, type) {
+ if (type === 'assign' && node[2][0] === 'name' && node[2][1] === 'STACKTOP') {
+ var value = node[3];
+ if (value[0] === 'name') return true;
+ assert(value[0] == 'binary' && value[1] == '|' && value[2][0] == 'binary' && value[2][1] == '+' && value[2][2][0] == 'name' && value[2][2][1] == 'STACKTOP' && value[2][3][0] == 'num');
+ found = node;
+ return true;
+ }
+ });
+ return found;
+}
+
// Very simple 'registerization', coalescing of variables into a smaller number,
// as part of minification. Globals-level minification began in a previous pass,
// we receive extraInfo which tells us how to rename globals. (Only in asm.js.)
@@ -3319,15 +3333,8 @@ function outline(ast) {
var extraSpace = asmData.extraStackSize;
if ('sp' in asmData.vars) {
// find stack bump (STACKTOP = STACKTOP + X | 0) and add the extra space
- traverse(stats, function(node, type) {
- if (type === 'assign' && node[2][0] === 'name' && node[2][1] === 'STACKTOP') {
- var value = node[3];
- if (value[0] === 'name') return true;
- assert(value[0] == 'binary' && value[1] == '|' && value[2][0] == 'binary' && value[2][1] == '+' && value[2][2][0] == 'name' && value[2][2][1] == 'STACKTOP' && value[2][3][0] == 'num');
- value[2][3][1] += extraSpace;
- return true;
- }
- });
+ var stackBumpNode = getStackBumpNode(stats);
+ if (stackBumpNode) stackBumpNode[3][2][3][1] += extraSpace;
} else if (!('sp' in asmData.params)) { // if sp is a param, then we are an outlined function, no need to add stack support for us
// add sp variable and stack bump
var index = getFirstIndexInNormalized(func, asmData);