aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/analyzer.js22
-rw-r--r--src/jsifier.js49
2 files changed, 14 insertions, 57 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index d0c3cb71..407ae4b9 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -1146,15 +1146,6 @@ function analyzer(data) {
exploreBlockEndings(block.inner, singular(block.inner));
} else if (block.type == 'multiple') {
block.entryLabels.forEach(function(entryLabel) { exploreBlockEndings(entryLabel.block, singular(block.next)) });
- } else if (block.type === 'emulated' && block.next && block.next.type === 'multiple') {
- assert(block.labels.length == 1);
- var lastLine = block.labels[0].lines.slice(-1)[0];
- if (lastLine.intertype == 'branch' && lastLine.ident) { // TODO: handle switch, and other non-branch2 things
- // 'Steal' the condition
- block.next.stolenCondition = lastLine;
- dprint('relooping', 'steal condition: ' + block.next.stolenCondition.ident);
- lastLine.stolen = true;
- }
}
exploreBlockEndings(block.next, endOfTheWorld);
@@ -1182,19 +1173,6 @@ function analyzer(data) {
replaceLabelLabels(block.labels, set('BCONT|' + block.willGetTo + '|' + block.willGetTo), 'BNOPP');
replaceLabelLabels(block.labels, set('BREAK|*|' + block.willGetTo), 'BNOPP');
} else if (block.type === 'multiple') {
- // Stolen conditions can be optimized further than the same branches in their original position
- var stolen = block.stolenCondition;
- if (stolen) {
- [stolen.labelTrue, stolen.labelFalse].forEach(function(entry) {
- entryLabel = block.entryLabels.filter(function(possible) { return possible.ident === getActualLabelId(entry) })[0];
- if (entryLabel) {
- replaceLabelLabels([{ lines: [stolen] }], set(entry), 'BNOPP');
- } else {
- replaceLabelLabels([{ lines: [stolen] }], set('BJSET|' + block.willGetTo + '|' + block.willGetTo), 'BNOPP');
- }
- });
- }
-
// Check if the one-time loop (that allows breaking out) is actually needed
if (replaceLabelLabels(block.labels, set('BREAK|' + block.id + '|*')).length === 0) {
block.loopless = true;
diff --git a/src/jsifier.js b/src/jsifier.js
index fb086e29..49bac511 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -505,43 +505,23 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
ret += indent + (block.needBlockId ? block.id + ': ' : '') + 'do { \n';
multipleIdent = ' ';
}
- var stolen = block.stolenCondition;
- if (stolen) {
- var intendedTrueLabel = stolen.labelTrue;
- assert(block.entryLabels.length <= 2);
- [stolen.labelTrue, stolen.labelFalse].forEach(function(entry) {
- var branch = makeBranch(entry, stolen.currLabelId || null);
- entryLabel = block.entryLabels.filter(function(possible) { return possible.ident === getActualLabelId(entry) })[0];
- if (branch.length < 5 && !entryLabel) return;
- //ret += indent + multipleIdent + (first ? '' : 'else ') +
- // 'if (' + (entry == intendedTrueLabel ? '' : '!') + stolen.ident + ')' + ' {\n';
- ret += indent + multipleIdent + (first ? 'if (' + (entry == intendedTrueLabel ? '' : '!') + stolen.ident + ')' : 'else') + ' {\n';
- ret += indent + multipleIdent + ' ' + branch + '\n';
- if (entryLabel) {
- ret += walkBlock(entryLabel.block, indent + ' ' + multipleIdent);
- }
- ret += indent + multipleIdent + '}\n';
- first = false;
+ // TODO: Find out cases where the final if/case is not needed - where we know we must be in a specific label at that point
+ var SWITCH_IN_MULTIPLE = 0; // This appears to never be worth it, for no amount of labels
+ if (SWITCH_IN_MULTIPLE && block.entryLabels.length >= 2) {
+ ret += indent + multipleIdent + 'switch(__label__) {\n';
+ block.entryLabels.forEach(function(entryLabel) {
+ ret += indent + multipleIdent + ' case ' + getLabelId(entryLabel.ident) + ': {\n';
+ ret += walkBlock(entryLabel.block, indent + ' ' + multipleIdent);
+ ret += indent + multipleIdent + ' } break;\n';
});
+ ret += indent + multipleIdent + '}\n';
} else {
- // TODO: Find out cases where the final if/case is not needed - where we know we must be in a specific label at that point
- var SWITCH_IN_MULTIPLE = 0; // This appears to never be worth it, for no amount of labels
- if (SWITCH_IN_MULTIPLE && block.entryLabels.length >= 2) {
- ret += indent + multipleIdent + 'switch(__label__) {\n';
- block.entryLabels.forEach(function(entryLabel) {
- ret += indent + multipleIdent + ' case ' + getLabelId(entryLabel.ident) + ': {\n';
- ret += walkBlock(entryLabel.block, indent + ' ' + multipleIdent);
- ret += indent + multipleIdent + ' } break;\n';
- });
+ block.entryLabels.forEach(function(entryLabel) {
+ ret += indent + multipleIdent + (first ? '' : 'else ') + 'if (__label__ == ' + getLabelId(entryLabel.ident) + ') {\n';
+ ret += walkBlock(entryLabel.block, indent + ' ' + multipleIdent);
ret += indent + multipleIdent + '}\n';
- } else {
- block.entryLabels.forEach(function(entryLabel) {
- ret += indent + multipleIdent + (first ? '' : 'else ') + 'if (__label__ == ' + getLabelId(entryLabel.ident) + ') {\n';
- ret += walkBlock(entryLabel.block, indent + ' ' + multipleIdent);
- ret += indent + multipleIdent + '}\n';
- first = false;
- });
- }
+ first = false;
+ });
}
if (!block.loopless) {
ret += indent + '} while(0);\n';
@@ -783,7 +763,6 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
makeFuncLineActor('branch', function(item) {
var phiSets = calcPhiSets(item);
- if (item.stolen) return getPhiSetsForLabel(phiSets, item.label) || ';'; // We will appear where we were stolen to
if (!item.value) {
return getPhiSetsForLabel(phiSets, item.label) + makeBranch(item.label, item.currLabelId);
} else {