aboutsummaryrefslogtreecommitdiff
path: root/src/jsifier.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-18 14:34:54 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-11-18 14:34:54 -0800
commit42b3bb7206356f6543737696d3bbd75ebe2aad4f (patch)
tree6c5b3d2855f13f0084a3f972f029686c726bd1af /src/jsifier.js
parent7d95ee5784c4e1bd475aef46ebcdf4f4cac5cfbe (diff)
phi progress, almost all unoptimized tests pass
Diffstat (limited to 'src/jsifier.js')
-rw-r--r--src/jsifier.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 6d77fe4f..7a267e92 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -702,13 +702,29 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
}
makeFuncLineActor('branch', function(item) {
- if (item.stolen) return ';'; // We will appear where we were stolen to
+ 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
if (!item.value) {
- return makeBranch(item.label, item.currLabelId);
+ return getPhiSets(item.label) + makeBranch(item.label, item.currLabelId);
} else {
var condition = finalizeLLVMParameter(item.value);
- var labelTrue = makeBranch(item.labelTrue, item.currLabelId);
- var labelFalse = makeBranch(item.labelFalse, item.currLabelId);
+ var labelTrue = getPhiSets(item.labelTrue) + makeBranch(item.labelTrue, item.currLabelId);
+ var labelFalse = getPhiSets(item.labelFalse) + makeBranch(item.labelFalse, item.currLabelId);
if (labelTrue == ';' && labelFalse == ';') return ';';
var head = 'if (' + condition + ') { ';
var head2 = 'if (!(' + condition + ')) { ';