aboutsummaryrefslogtreecommitdiff
path: root/tools/js-optimizer.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-07-16 17:38:13 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-07-16 17:38:13 -0700
commit4260723fdf4c436a7999c9b3eefb8cd0e8b1208a (patch)
treebfaa34bfc37f593c2533f0124d098012e86dbd16 /tools/js-optimizer.js
parente747992077a1889a92330d7677cb1324c5fb499b (diff)
fix switch generation for break/continue routing in outliner
Diffstat (limited to 'tools/js-optimizer.js')
-rw-r--r--tools/js-optimizer.js31
1 files changed, 22 insertions, 9 deletions
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 2c11d683..7989f1f4 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -3075,6 +3075,9 @@ function outline(ast) {
function makeComparison(left, comp, right) {
return ['binary', comp, left, right];
}
+ function makeSwitch(value, cases) {
+ return ['switch', value, cases];
+ }
var CONTROL_BREAK = 1, CONTROL_BREAK_LABEL = 2, CONTROL_CONTINUE = 3, CONTROL_CONTINUE_LABEL = 4, CONTROL_RETURN_VOID = 5, CONTROL_RETURN_INT = 6, CONTROL_RETURN_DOUBLE = 7;
@@ -3175,20 +3178,30 @@ function outline(ast) {
makeComparison(makeStackAccess(ASM_INT, asmData.controlStackPos), '==', ['num', CONTROL_BREAK]),
[['stat', ['break']]]
));
- reps.push(makeIf(
- makeComparison(makeStackAccess(ASM_INT, asmData.controlStackPos), '==', ['num', CONTROL_BREAK_LABEL]),
- [['stat', ['break', makeStackAccess(ASM_INT, asmData.controlDataStackPos)]]] // XXX here and below, need a switch overall possible labels
- ));
+ if (keys(codeInfo.labels).length > 0) {
+ reps.push(makeIf(
+ makeComparison(makeStackAccess(ASM_INT, asmData.controlStackPos), '==', ['num', CONTROL_BREAK_LABEL]),
+ [makeSwitch(makeStackAccess(ASM_INT, asmData.controlDataStackPos), keys(codeInfo.labels).map(function(key) {
+ var id = codeInfo.labels[key];
+ return [['num', id], [['stat', ['break', key]]]];
+ }))]
+ ));
+ }
}
if (codeInfo.hasContinue) {
reps.push(makeIf(
makeComparison(makeStackAccess(ASM_INT, asmData.controlStackPos), '==', ['num', CONTROL_CONTINUE]),
- [['stat', ['break']]]
- ));
- reps.push(makeIf(
- makeComparison(makeStackAccess(ASM_INT, asmData.controlStackPos), '==', ['num', CONTROL_CONTINUE_LABEL]),
- [['stat', ['continue', makeStackAccess(ASM_INT, asmData.controlDataStackPos)]]] // XXX
+ [['stat', ['continue']]]
));
+ if (keys(codeInfo.labels).length > 0) {
+ reps.push(makeIf(
+ makeComparison(makeStackAccess(ASM_INT, asmData.controlStackPos), '==', ['num', CONTROL_CONTINUE_LABEL]),
+ [makeSwitch(makeStackAccess(ASM_INT, asmData.controlDataStackPos), keys(codeInfo.labels).map(function(key) {
+ var id = codeInfo.labels[key];
+ return [['num', id], [['stat', ['continue', key]]]];
+ }))]
+ ));
+ }
}
}
var newFunc = ['defun', newIdent, ['sp'], code];