aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-02-23 14:21:09 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-02-23 14:21:09 -0800
commita18bd727401a8495275c78149dbaae5a0adae0d2 (patch)
tree3ec148291266342eb01708a840734451d9c56fdf
parentfd554f90a78d03af31fcc19c22e2ac5f80998fab (diff)
add stack bump if only sp is defined but no bump is present, when outlining
-rw-r--r--tools/js-optimizer.js22
-rw-r--r--tools/test-js-optimizer-asm-outline2-output.js1
2 files changed, 22 insertions, 1 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 21fce2c2..d393b159 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -4935,7 +4935,27 @@ function outline(ast) {
if ('sp' in asmData.vars) {
// find stack bump (STACKTOP = STACKTOP + X | 0) and add the extra space
var stackBumpNode = getStackBumpNode(stats);
- if (stackBumpNode) stackBumpNode[3][2][3][1] = asmData.totalStackSize;
+ if (stackBumpNode) {
+ stackBumpNode[3][2][3][1] = asmData.totalStackSize;
+ } else {
+ // sp exists, but no stack bump, so we need to add it
+ var found = false;
+ for (var i = 0; i < stats.length; i++) {
+ var stat = stats[i];
+ if (stat[0] === 'stat') stat = stat[1];
+ if (stat[0] === 'assign' && stat[2][0] === 'name' && stat[2][1] === 'sp') {
+ var newNode = ['stat', makeAssign(['name', 'STACKTOP'], ['binary', '|', ['binary', '+', ['name', 'STACKTOP'], ['num', asmData.totalStackSize]], ['num', 0]])];
+ if (i+1 < stats.length) {
+ stats.splice(i+1, 0, newNode);
+ } else {
+ stats.push(newNode);
+ }
+ found = true;
+ break;
+ }
+ }
+ assert(found);
+ }
} 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);
diff --git a/tools/test-js-optimizer-asm-outline2-output.js b/tools/test-js-optimizer-asm-outline2-output.js
index 2658fda0..923cd7df 100644
--- a/tools/test-js-optimizer-asm-outline2-output.js
+++ b/tools/test-js-optimizer-asm-outline2-output.js
@@ -25,6 +25,7 @@ function _free($mem) {
$mem = $mem | 0;
var $5 = 0, $10 = 0, $16 = 0, $21 = 0, $25 = 0, $26 = 0, $psize_0 = 0, $p_0 = 0, $189 = 0, $194 = 0, sp = 0, helper$0 = 0;
sp = STACKTOP;
+ STACKTOP = STACKTOP + 864 | 0;
if (($mem | 0) == 0) {
STACKTOP = sp;
return;