aboutsummaryrefslogtreecommitdiff
path: root/src/jsifier.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/jsifier.js')
-rw-r--r--src/jsifier.js47
1 files changed, 26 insertions, 21 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 7a267e92..a4340623 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -701,30 +701,34 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
}
}
+ function calcPhiSets(item) {
+ if (!item.phi) return null;
+ var phiSets = {};
+ // TODO: Do not always rename them all
+ // TODO: eliminate unneeded sets (to undefined etc.)
+ item.params.forEach(function(param) {
+ if (!phiSets[param.targetLabel]) phiSets[param.targetLabel] = [];
+ phiSets[param.targetLabel].unshift('var ' + param.ident + '$phi = ' + finalizeLLVMParameter(param.value) + ';');
+ phiSets[param.targetLabel].push(param.ident + ' = ' + param.ident + '$phi;');
+ });
+ return phiSets;
+ }
+
+ function getPhiSetsForLabel(phiSets, label) {
+ label = getOldLabel(label);
+ if (!phiSets || !phiSets[label]) return '';
+ return sumStringy(phiSets[label]);
+ }
+
makeFuncLineActor('branch', function(item) {
- var phiSets = null;
- if (item.phi) {
- phiSets = {};
- // TODO: Do not always rename them all
- // TODO: eliminate unneeded sets (to undefined etc.)
- item.params.forEach(function(param) {
- if (!phiSets[param.targetLabel]) phiSets[param.targetLabel] = [];
- phiSets[param.targetLabel].unshift('var ' + param.ident + '$phi = ' + finalizeLLVMParameter(param.value) + ';');
- phiSets[param.targetLabel].push(param.ident + ' = ' + param.ident + '$phi;');
- });
- }
- function getPhiSets(label) {
- label = getOldLabel(label);
- if (!phiSets || !phiSets[label]) return '';
- return sumStringy(phiSets[label]);
- }
- if (item.stolen) return getPhiSets(item.label) || ';'; // We will appear where we were stolen to
+ var phiSets = calcPhiSets(item);
+ if (item.stolen) return getPhiSetsForLabel(phiSets, item.label) || ';'; // We will appear where we were stolen to
if (!item.value) {
- return getPhiSets(item.label) + makeBranch(item.label, item.currLabelId);
+ return getPhiSetsForLabel(phiSets, item.label) + makeBranch(item.label, item.currLabelId);
} else {
var condition = finalizeLLVMParameter(item.value);
- var labelTrue = getPhiSets(item.labelTrue) + makeBranch(item.labelTrue, item.currLabelId);
- var labelFalse = getPhiSets(item.labelFalse) + makeBranch(item.labelFalse, item.currLabelId);
+ var labelTrue = getPhiSetsForLabel(phiSets, item.labelTrue) + makeBranch(item.labelTrue, item.currLabelId);
+ var labelFalse = getPhiSetsForLabel(phiSets, item.labelFalse) + makeBranch(item.labelFalse, item.currLabelId);
if (labelTrue == ';' && labelFalse == ';') return ';';
var head = 'if (' + condition + ') { ';
var head2 = 'if (!(' + condition + ')) { ';
@@ -740,6 +744,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
}
});
makeFuncLineActor('switch', function(item) {
+ var phiSets = calcPhiSets(item);
var ret = '';
var first = true;
item.switchLabels.forEach(function(switchLabel) {
@@ -749,7 +754,7 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
first = false;
}
ret += 'if (' + item.ident + ' == ' + switchLabel.value + ') {\n';
- ret += ' ' + makeBranch(switchLabel.label, item.currLabelId || null) + '\n';
+ ret += ' ' + getPhiSetsForLabel(phiSets, switchLabel.label) + makeBranch(switchLabel.label, item.currLabelId || null) + '\n';
ret += '}\n';
});
if (item.switchLabels.length > 0) ret += 'else {\n';