This commit is contained in:
alon@honor 2010-09-20 20:14:56 -07:00
Родитель fea809cb09
Коммит ab582256db
2 изменённых файлов: 29 добавлений и 6 удалений

Просмотреть файл

@ -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');
},
});

Просмотреть файл

@ -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;';
}
}