improve global alias processing, including sort by dependency. poppler test passes

This commit is contained in:
Alon Zakai 2011-09-07 15:26:23 -07:00
Родитель af88c4ce71
Коммит 0a89324b72
2 изменённых файлов: 33 добавлений и 7 удалений

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

@ -255,10 +255,13 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
item.intertype = 'GlobalVariableStub';
var ret = [item];
item.JS = 'var ' + item.ident + ';';
// Set the actual value in a postset, since it may be a global variable. TODO: handle alias of alias (needs ordering)
// Set the actual value in a postset, since it may be a global variable. We also order by dependencies there
var value = finalizeLLVMParameter(item.value, true); // do *not* indexize functions here
ret.push({
intertype: 'GlobalVariablePostSet',
JS: item.ident + ' = ' + finalizeLLVMParameter(item.value, true) + ';' // do *not* indexize functions here
ident: item.ident,
dependencies: set([value]),
JS: item.ident + ' = ' + value + ';';
});
return ret;
}
@ -845,11 +848,34 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
var itemsDict = { type: [], GlobalVariableStub: [], functionStub: [], function: [], GlobalVariable: [], GlobalVariablePostSet: [] };
items.forEach(function(item) {
item.lines = null;
var small = { intertype: item.intertype, JS: item.JS }; // Release memory
var small = { intertype: item.intertype, JS: item.JS, ident: item.ident, dependencies: item.dependencies }; // Release memory
itemsDict[small.intertype].push(small);
});
items = null;
var splitPostSets = splitter(itemsDict.GlobalVariablePostSet, function(x) { return x.ident && x.dependencies });
itemsDict.GlobalVariablePostSet = splitPostSets.leftIn;
var orderedPostSets = splitPostSets.splitOut;
var limit = orderedPostSets.length * orderedPostSets.length;
for (var i = 0; i < orderedPostSets.length; i++) {
for (var j = i+1; j < orderedPostSets.length; j++) {
if (orderedPostSets[j].ident in orderedPostSets[i].dependencies) {
var temp = orderedPostSets[i];
orderedPostSets[i] = orderedPostSets[j];
orderedPostSets[j] = temp;
i--;
limit--;
assert(limit > 0, 'Could not sort postsets!');
break;
}
}
}
itemsDict.GlobalVariablePostSet = itemsDict.GlobalVariablePostSet.concat(orderedPostSets);
//
var generated = [];
if (mainPass) {
generated = generated.concat(itemsDict.type).concat(itemsDict.GlobalVariableStub).concat(itemsDict.functionStub);

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

@ -979,14 +979,14 @@ function makeGetSlabs(ptr, type, allowMultiple, unsigned) {
return [];
}
function finalizeLLVMFunctionCall(item) {
function finalizeLLVMFunctionCall(item, noIndexizeFunctions) {
switch(item.intertype) {
case 'getelementptr': // TODO finalizeLLVMParameter on the ident and the indexes?
return makePointer(makeGetSlabs(item.ident, item.type)[0], getGetElementPtrIndexes(item), null, item.type);
case 'bitcast':
case 'inttoptr':
case 'ptrtoint':
return finalizeLLVMParameter(item.params[0]);
return finalizeLLVMParameter(item.params[0], noIndexizeFunctions);
case 'icmp': case 'mul': case 'zext': case 'add': case 'sub': case 'div':
var temp = {
op: item.intertype,
@ -1085,11 +1085,11 @@ function finalizeLLVMParameter(param, noIndexizeFunctions) {
} else if (typeof param === 'string') {
return toNiceIdentCarefully(param);
} else if (param.intertype in PARSABLE_LLVM_FUNCTIONS) {
ret = finalizeLLVMFunctionCall(param);
ret = finalizeLLVMFunctionCall(param, noIndexizeFunctions);
} else if (param.intertype == 'value') {
ret = parseNumerical(param.ident);
} else if (param.intertype == 'structvalue') {
ret = param.values.map(finalizeLLVMParameter);
ret = param.values.map(function(value) { return finalizeLLVMParameter(value, noIndexizeFunctions) });
} else if (param.intertype === 'blockaddress') {
return finalizeBlockAddress(param);
} else if (param.intertype === 'type') {