aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/analyzer.js13
-rw-r--r--src/jsifier.js10
-rw-r--r--src/settings.js2
3 files changed, 18 insertions, 7 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 50683ec7..ae40896d 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -39,6 +39,7 @@ function analyzer(data, givenTypes) {
});
// Functions & labels
item.functions = [];
+ var currLabelFinished; // Sometimes LLVM puts a branch in the middle of a label. We need to ignore all lines after that.
for (var i = 0; i < item.items.length; i++) {
var subItem = item.items[i];
if (subItem.intertype == 'function') {
@@ -60,10 +61,18 @@ function analyzer(data, givenTypes) {
} else if (subItem.intertype == 'label') {
item.functions.slice(-1)[0].labels.push(subItem);
subItem.lines = [];
+ currLabelFinished = false;
} else if (item.functions.length > 0 && item.functions.slice(-1)[0].endLineNum === null) {
// Internal line
- item.functions.slice(-1)[0].lines.push(subItem);
- item.functions.slice(-1)[0].labels.slice(-1)[0].lines.push(subItem);
+ if (!currLabelFinished) {
+ item.functions.slice(-1)[0].lines.push(subItem);
+ item.functions.slice(-1)[0].labels.slice(-1)[0].lines.push(subItem);
+ if (subItem.intertype === 'branch') {
+ currLabelFinished = true;
+ }
+ } else {
+ print('// WARNING: content after a branch in a label, line: ' + subItem.lineNum);
+ }
} else {
print("ERROR: what is this? " + JSON.stringify(subItem));
}
diff --git a/src/jsifier.js b/src/jsifier.js
index 847b198d..7efc407c 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -442,7 +442,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
if (block.type == 'emulated') {
if (block.labels.length > 1) {
if (block.entries.length == 1) {
- ret += indent + '__label__ = ' + getLabelId(block.entries[0]) + '; /* ' + block.entries[0] + ' */\n';
+ ret += indent + '__label__ = ' + getLabelId(block.entries[0]) + '; ' + (SHOW_LABELS ? '/* ' + block.entries[0] + ' */' : '') + '\n';
} // otherwise, should have been set before!
ret += indent + 'while(1) switch(__label__) {\n';
ret += block.labels.map(function(label) {
@@ -451,11 +451,11 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
}).join('\n');
ret += '\n' + indent + ' default: assert(0, "bad label: " + __label__);\n' + indent + '}';
} else {
- ret += getLabelLines(block.labels[0], indent);
+ ret += (SHOW_LABELS ? indent + '/* ' + block.entries[0] + ' */' : '') + '\n' + getLabelLines(block.labels[0], indent);
}
ret += '\n';
} else if (block.type == 'reloop') {
- ret += indent + block.id + ': while(1) { // ' + block.entries + '\n';
+ ret += indent + block.id + ': while(1) { ' + (SHOW_LABELS ? ' /* ' + block.entries + + ' */' : '') + '\n';
ret += walkBlock(block.inner, indent + ' ');
ret += indent + '}\n';
} else if (block.type == 'multiple') {
@@ -632,7 +632,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
var parts = label.split('|');
var trueLabel = parts[1];
var oldLabel = parts[2];
- var labelSetting = '__label__ = ' + getLabelId(oldLabel) + '; /* ' + cleanLabel(oldLabel) + ' */ '; // TODO: optimize away
+ var labelSetting = '__label__ = ' + getLabelId(oldLabel) + ';' + (SHOW_LABELS ? ' /* to: ' + cleanLabel(oldLabel) + ' */' : ''); // TODO: optimize away
if (label[1] == 'R') {
return pre + labelSetting + 'break ' + trueLabel + ';';
} else if (label[1] == 'C') { // CONT
@@ -645,7 +645,7 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVaria
throw 'Invalid B-op in branch: ' + trueLabel + ',' + oldLabel;
}
} else {
- return pre + '__label__ = ' + getLabelId(label) + '; /* ' + cleanLabel(label) + ' */ break;';
+ return pre + '__label__ = ' + getLabelId(label) + ';' + (SHOW_LABELS ? ' /* to: ' + cleanLabel(label) + ' */' : '') + ' break;';
}
}
diff --git a/src/settings.js b/src/settings.js
index 829d4517..1b0b2bce 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -51,6 +51,8 @@ CORRECT_OVERFLOWS = 1; // Experimental code that tries to prevent unexpected JS
// not rely on overflows in your C/C++ code, as even if this option works,
// it slows things down.
+SHOW_LABELS = 0; // Show labels in the generated code
+
// Compiler debugging options
DEBUG_TAGS_SHOWING = [];
// Some useful items: