// Analyze intertype data. Calculates things that are necessary in order
// to do the final conversion into JavaScript later, for example,
// properties of variables, loop structures of functions, etc.
VAR_NATIVE = 'native';
VAR_NATIVIZED = 'nativized';
VAR_EMULATED = 'emulated';
function cleanFunc(func) {
func.lines = func.lines.filter(function(line) { return line.intertype !== null });
func.labels.forEach(function(label) {
label.lines = label.lines.filter(function(line) { return line.intertype !== null });
});
}
function analyzer(data) {
// Substrate
substrate = new Substrate('Analyzer');
// Sorter
substrate.addActor('Sorter', {
processItem: function(item) {
item.items.sort(function (a, b) { return a.lineNum - b.lineNum });
this.forwardItem(item, 'Gatherer');
}
});
// Gatherer
substrate.addActor('Gatherer', {
processItem: function(item) {
// Single-liners
['globalVariable', 'functionStub', 'unparsedFunction', 'alias'].forEach(function(intertype) {
var temp = splitter(item.items, function(item) { return item.intertype == intertype });
item.items = temp.leftIn;
item[intertype + 's'] = temp.splitOut;
});
var temp = splitter(item.items, function(item) { return item.intertype == 'type' });
item.items = temp.leftIn;
temp.splitOut.forEach(function(type) {
Types.types[type.name_] = type;
if (QUANTUM_SIZE === 1) {
Types.fatTypes[type.name_] = copy(type);
}
});
// 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.
item.items.sort(function(a, b) { return a.lineNum - b.lineNum });
for (var i = 0; i < item.items.length; i++) {
var subItem = item.items[i];
assert(subItem.lineNum);
if (subItem.intertype == 'function') {
item.functions.push(subItem);
subItem.endLineNum = null;
subItem.lines = [];
subItem.labels = [];
// no explicit 'entry' label in clang on LLVM 2.8 - most of the time, but not all the time! - so we add one if necessary
if (LLVM_STYLE == 'new' && item.items[i+1].intertype !== 'label') {
item.items.splice(i+1, 0, {
intertype: 'label',
ident: toNiceIdent('%0'),
lineNum: subItem.lineNum + '.5'
});
}
} else