diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-08 18:18:50 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-08 18:18:50 -0700 |
commit | 5d3ff92c55b8830c5f1c670a252107d3e8cded60 (patch) | |
tree | 8f92d19ea6a6af346bf55f0990d42546d5cefe23 | |
parent | 28898039d201593e77c721e75b534e4b32273e92 (diff) |
add one-time loop when we need to handle control flow in outlined functions
-rw-r--r-- | tools/js-optimizer.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js index 1bf7e0e1..06d82752 100644 --- a/tools/js-optimizer.js +++ b/tools/js-optimizer.js @@ -2982,7 +2982,7 @@ function outline(ast) { function analyzeCode(func, asmData, ast) { var writes = {}; var appearances = {}; - var hasReturn = false; + var hasReturn = false, hasBreak = false, hasContinue = false; var breaks = {}; // set of labels we break or continue var continues = {}; // to. '0' is an unlabeled one @@ -3002,8 +3002,10 @@ function outline(ast) { hasReturn = true; } else if (type == 'break') { breaks[node[1] || 0] = 0; + hasBreak = true; } else if (type == 'continue') { continues[node[1] || 0] = 0; + hasContinue = true; } }); @@ -3039,6 +3041,10 @@ function outline(ast) { } stats.splice.apply(stats, [start, end-start+1].concat(reps)); // Generate new function + if (codeInfo.hasReturn || codeInfo.hasBreak || codeInfo.hasContinue) { + // we need to capture all control flow using a top-level labeled one-time loop in the outlined function + code = [['label', 'OL', ['do', ['num', 0], ['block', code]]]]; + } var newFunc = ['defun', newIdent, ['sp'], code]; var newAsmInfo = { params: { sp: ASM_INT }, vars: {} }; for (var v in codeInfo.reads) { |