aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-09-20 20:14:56 -0700
committeralon@honor <none@none>2010-09-20 20:14:56 -0700
commitab582256db454b3ccab074058941311845746f8b (patch)
treed4cf0ed511bc3e4d1a635fcfa132b523f2d733e2
parentfea809cb090c648f58f11561f7f25ce813d9944f (diff)
optimize __lastLabel__/phi
-rw-r--r--src/analyzer.js21
-rw-r--r--src/jsifier.js14
2 files changed, 29 insertions, 6 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index c9ccf82a..6daf9191 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -12,7 +12,6 @@ function cleanFunc(func) {
}
function analyzer(data) {
-//print('zz analaz')
substrate = new Substrate('Analyzer');
// Sorter
@@ -261,6 +260,26 @@ function analyzer(data) {
dprint('vars', '// var ' + vname + ': ' + JSON.stringify(variable));
}
});
+ this.forwardItem(item, 'LabelAnalyzer');
+ },
+ });
+
+ // Label analyzer
+ substrate.addZyme('LabelAnalyzer', {
+ processItem: function(item) {
+ item.functions.forEach(function(func) {
+ func.hasPhi = false;
+ func.remarkableLabels = [];
+ func.labels.forEach(function(label) {
+ label.lines.forEach(function(line) {
+ if (line.value && line.value.intertype == 'phi') {
+ func.remarkableLabels.push(toNiceIdent(line.value.label1));
+ func.remarkableLabels.push(toNiceIdent(line.value.label2));
+ func.hasPhi = true;
+ }
+ });
+ });
+ });
this.forwardItem(item, 'Relooper');
},
});
diff --git a/src/jsifier.js b/src/jsifier.js
index e99917e7..c4235b3f 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -197,9 +197,8 @@ function JSify(data) {
// We have this function all reconstructed, go and finalize it's JS!
- var hasVarArgs = false, hasPhi = false;
+ var hasVarArgs = false;
var params = parseParamTokens(func.params.item[0].tokens).map(function(param) {
- hasPhi = hasPhi || param.intertype == 'phi';
if (param.intertype == 'varargs') {
hasVarArgs = true;
return null;
@@ -213,6 +212,9 @@ function JSify(data) {
if (hasVarArgs) {
func.JS += ' __numArgs__ = ' + params.length + ';\n';
}
+ if (func.hasPhi) {
+ func.JS += ' __lastLabel__ = null;\n';
+ }
// Walk function blocks and generate JS
function walkBlock(block, indent) {
@@ -222,6 +224,10 @@ function JSify(data) {
if (LABEL_DEBUG) {
ret += indent + " print(INDENT + '" + func.ident + ":" + label.ident + "');\n";
}
+ // for special labels we care about (for phi), mark that we visited them
+ if (func.remarkableLabels.indexOf(label.ident) >= 0) {
+ ret += ' __lastLabel__ = ' + getLabelId(label.ident) + ';\n';
+ }
return ret + label.lines.map(function(line) { return indent + line.JS + (line.comment ? ' // ' + line.comment : '') }).join('\n');
}
var ret = '';
@@ -387,9 +393,7 @@ function JSify(data) {
return ';'; // Returning no text might confuse this parser
}
} else {
- // FIXME: We should use __lastLabel__ only if we actually need
- // it, which is in the case of phi being used on the label.
- return '__lastLabel__ = __label__; __label__ = ' + getLabelId(label) + '; break;';
+ return '__label__ = ' + getLabelId(label) + '; break;';
}
}