aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-10-17 23:15:33 -0700
committeralon@honor <none@none>2010-10-17 23:15:33 -0700
commit7439185557cae67f03a44a3070cceb4c45f4e1a7 (patch)
treea8de622ec6be09e0a06c1d77620cf14b56e8a99d
parent04dff51782dd5e8bb1a209e93d39499c59b190fa (diff)
optimize reintegrator
-rw-r--r--src/analyzer.js1
-rw-r--r--src/intertyper.js13
-rw-r--r--src/parseTools.js41
3 files changed, 30 insertions, 25 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index 54acbc54..4a692826 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -181,6 +181,7 @@ function analyzer(data) {
} else if (isStructType(field)) {
size = item.types[field].flatSize;
} else {
+ dprint('Unclear type in struct: ' + field + ', in ' + type.name_);
assert(0);
}
var curr = Runtime.alignMemory(type.flatSize, Math.min(QUANTUM_SIZE, size)); // if necessary, place this on aligned memory
diff --git a/src/intertyper.js b/src/intertyper.js
index c0462738..e4814daf 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -267,10 +267,12 @@ function intertyper(data) {
};
if (ident == '@llvm.global_ctors') {
ret.ctors = [];
- var subTokens = item.tokens[3].item[0].tokens;
- splitTokenList(subTokens).forEach(function(segment) {
- ret.ctors.push(segment[1].tokens.slice(-1)[0].text);
- });
+ if (item.tokens[3].item) {
+ var subTokens = item.tokens[3].item[0].tokens;
+ splitTokenList(subTokens).forEach(function(segment) {
+ ret.ctors.push(segment[1].tokens.slice(-1)[0].text);
+ });
+ }
} else {
if (item.tokens[3].type == '<') { // type <{ i8 }> XXX - check spec
item.tokens[3] = item.tokens[3].item[0].tokens;
@@ -331,8 +333,7 @@ function intertyper(data) {
}), 'Triager');
},
});
- // reintegration - find intermediate representation-parsed items and
- // place back in parents TODO: Optimize this code to optimal O(..)
+
substrate.addZyme('Reintegrator', makeReintegrator(function(parent, child) {
// Special re-integration behaviors
if (child.intertype == 'fastgetelementptrload') {
diff --git a/src/parseTools.js b/src/parseTools.js
index 3ee56ece..fe8d1159 100644
--- a/src/parseTools.js
+++ b/src/parseTools.js
@@ -203,29 +203,32 @@ function splitItem(parent, childSlot, copySlots) {
}
function makeReintegrator(afterFunc) {
- // reintegration - find intermediate representation-parsed items and
- // place back in parents TODO: Optimize this code to optimal O(..)
+ // Reintegration - find intermediate representation-parsed items and
+ // place back in parents
return {
process: function(items) {
var ret = [];
+ var lineDict = {};
for (var i = 0; i < items.length; i++) {
- var found = false;
- if (items[i] && items[i].parentSlot) {
- var child = items[i];
- for (var j = 0; j < items.length; j++) {
- if (items[j] && items[j].lineNum == items[i].parentLineNum) {
- var parent = items[j];
- // process the pair
- parent[child.parentSlot] = child;
- delete child.parentLineNum;
- afterFunc.call(this, parent, child);
-
- items[i] = null;
- items[j] = null;
- found = true;
- break;
- }
- }
+ var item = items[i];
+ if (!item.parentSlot) {
+ assert(!lineDict[item.lineNum]);
+ lineDict[item.lineNum] = i;
+ }
+ }
+ for (var i = 0; i < items.length; i++) {
+ var child = items[i];
+ var j = lineDict[child.parentLineNum];
+ if (typeof j === 'number') {
+ var parent = items[j];
+ // process the pair
+ parent[child.parentSlot] = child;
+ delete child.parentLineNum;
+ afterFunc.call(this, parent, child);
+
+ items[i] = null;
+ items[j] = null;
+ lineDict[child.parentLineNum] = null;
}
}
this.forwardItems(items.filter(function(item) { return !!item }), this.name_); // next time hopefully