clean up relooper label storage

This commit is contained in:
alon@honor 2010-10-11 21:34:41 -07:00
Родитель cb9319ec92
Коммит ce832e42fd
2 изменённых файлов: 16 добавлений и 18 удалений

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

@ -365,10 +365,8 @@ function analyzer(data) {
operateOnLabels(line, function process(item, id) {
if (item[id] in labelIds) {
ret.push(item[id]);
assert(!item['old_' + id]);
item['old_' + id] = item[id]; // Save it; we need this later for labels before breaks, when we have multiple entries later
dprint('relooping', 'zz ' + id + ' replace ' + item[id] + ' with ' + toLabelId + '; old: ' + item['old_' + id]);
item[id] = toLabelId;
item[id] = toLabelId + '|' + item[id];
}
});
return ret;
@ -520,11 +518,11 @@ function analyzer(data) {
var nextEntries = keys(entryLabel.outLabels);
dprint('relooping', ' Creating simple emulated, outlabels: ' + nextEntries);
//if (nextEntries.length == 1) {
// replaceLabelLabels([entryLabel], set(nextEntries), 'BNOPP'); // remove unneeded branch XXX - this is dangerous, as we may
// replaceLabelLabels([entryLabel], set(nextEntries), 'BNOPP|XXX'); // remove unneeded branch XXX - this is dangerous, as we may
// // have 1 next entry, but 1 or more B-labels...
//} else {
nextEntries.forEach(function(nextEntry) {
replaceLabelLabels([entryLabel], set(nextEntry), 'BJSET' + nextEntry); // Just SET __label__ - no break or continue or whatnot
replaceLabelLabels([entryLabel], set(nextEntry), 'BJSET|' + nextEntry); // Just SET __label__ - no break or continue or whatnot
});
//}
return {
@ -565,7 +563,7 @@ function analyzer(data) {
// We will be in a loop, |continue| gets us back to the entry
entries.forEach(function(entry) {
replaceLabelLabels(internals, searchable(entries), 'BCONT' + entries[0]); // entries[0] is the name of the loop, see walkBlock
replaceLabelLabels(internals, searchable(entries), 'BCONT|' + entries[0]); // entries[0] is the name of the loop, see walkBlock
});
// To get to any of our (not our parents') exit labels, we will break.
@ -573,7 +571,7 @@ function analyzer(data) {
var enteredExitLabels = {};
if (externals.length > 0) {
entries.forEach(function(entry) {
mergeInto(enteredExitLabels, set(replaceLabelLabels(internals, currExitLabels, 'BREAK' + entries[0]))); // see comment on entries[0] above
mergeInto(enteredExitLabels, set(replaceLabelLabels(internals, currExitLabels, 'BREAK|' + entries[0]))); // see comment on entries[0] above
});
enteredExitLabels = keys(enteredExitLabels).map(cleanLabel);
dprint('relooping', 'enteredExitLabels: ' + dump(enteredExitLabels));
@ -660,7 +658,7 @@ function analyzer(data) {
// TODO: Move this into BJSET
keys(postEntryLabels).forEach(function(post) {
replaceLabelLabels(actualEntryLabel.blockChildren, set(post), 'BREAK' + actualEntries[0]);
replaceLabelLabels(actualEntryLabel.blockChildren, set(post), 'BREAK|' + actualEntries[0]);
});
// Create child block
actualEntryLabel.block = makeBlock(actualEntryLabel.blockChildren, [actualEntryLabel.blockChildren[0].ident], labelsDict);

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

@ -492,12 +492,12 @@ function JSify(data) {
return LABEL_IDs[label] = LABEL_ID_COUNTER ++;
}
// TODO: remove 'oldLabel', store that inside the label: BXXX|Labeltobreak|Labeltogetto
function makeBranch(label, oldLabel) {
function makeBranch(label) {
if (label[0] == 'B') {
var parts = label.split('|');
var trueLabel = parts[1];
var oldLabel = parts[2];
var labelSetting = '__label__ = ' + getLabelId(oldLabel) + '; /* ' + cleanLabel(oldLabel) + ' */ '; // TODO: optimize away
var trueLabel = label.substr(5);
assert(oldLabel);
if (label[1] == 'R') {
return labelSetting + 'break ' + trueLabel + ';';
} else if (label[1] == 'C') { // CONT
@ -517,10 +517,10 @@ function JSify(data) {
makeFuncLineZyme('branch', function(item) {
//print('branch: ' + dump(item));
if (!item.ident) {
return makeBranch(item.label, item.old_label);
return makeBranch(item.label);
} else {
var labelTrue = makeBranch(item.labelTrue, item.old_labelTrue);
var labelFalse = makeBranch(item.labelFalse, item.old_labelFalse);
var labelTrue = makeBranch(item.labelTrue);
var labelFalse = makeBranch(item.labelFalse);
if (labelTrue == ';' && labelFalse == ';') return ';';
var head = 'if (' + item.ident + ') { ';
var head2 = 'if (!(' + item.ident + ')) { ';
@ -545,11 +545,11 @@ function JSify(data) {
first = false;
}
ret += 'if (' + item.ident + ' == ' + switchLabel.value + ') {\n';
ret += ' ' + makeBranch(switchLabel.label, switchLabel.old_label) + '\n';
ret += ' ' + makeBranch(switchLabel.label) + '\n';
ret += '}\n';
});
ret += 'else {\n';
ret += makeBranch(item.defaultLabel, item.old_defaultLabel) + '\n';
ret += makeBranch(item.defaultLabel) + '\n';
ret += '}\n';
if (item.value) {
ret += ' ' + toNiceIdent(item.value);
@ -573,7 +573,7 @@ function JSify(data) {
+ '__THREW__ = false } catch(e) { '
+ '__THREW__ = true; '
+ (EXCEPTION_DEBUG ? 'print("Exception: " + e + " : " + (new Error().stack)); ' : '')
+ '} })(); if (!__THREW__) { ' + makeBranch(item.toLabel, item.old_toLabel) + ' } else { ' + makeBranch(item.unwindLabel, item.old_unwindLabel) + ' }';
+ '} })(); if (!__THREW__) { ' + makeBranch(item.toLabel) + ' } else { ' + makeBranch(item.unwindLabel) + ' }';
return ret;
});
makeFuncLineZyme('load', function(item) {