aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2011-11-29 15:00:23 -0800
committerAlon Zakai <alonzakai@gmail.com>2011-11-29 15:00:23 -0800
commit497065b580828e050087896ac05d0e1f1fdd8627 (patch)
tree2e763bdd70a7444a0591c6ffe020a6c3f2720aee
parent6c4725c1ff57d02794c19d64e16ac6757e91fd04 (diff)
discard almost all .tokens when intertyper ends, to save memory (all except for inside Globals)
-rw-r--r--src/analyzer.js4
-rw-r--r--src/framework.js5
-rw-r--r--src/intertyper.js16
3 files changed, 15 insertions, 10 deletions
diff --git a/src/analyzer.js b/src/analyzer.js
index db0c3593..2dce7579 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -279,14 +279,12 @@ function analyzer(data) {
// Normal variables
func.lines.forEach(function(item) {
if (item.intertype === 'assign') {
- if (!item.value.tokens.slice(-1)[0].item) throw 'Did you run llvm-dis with -show-annotations?';
- var commaIndex = getTokenIndexByText(item.value.tokens, ';');
var variable = func.variables[item.ident] = {
ident: item.ident,
type: item.value.type,
origin: item.value.intertype,
lineNum: item.lineNum,
- uses: parseInt(item.value.tokens[commaIndex+1].item.tokens[0].text.split('=')[1])
+ uses: item.uses
};
assert(isNumber(variable.uses), 'Failed to find the # of uses of var: ' + item.ident);
if (variable.origin === 'alloca') {
diff --git a/src/framework.js b/src/framework.js
index 0f9e70d0..6e2bbe81 100644
--- a/src/framework.js
+++ b/src/framework.js
@@ -192,8 +192,9 @@ Substrate.prototype = {
if (!hadProcessing) {
if (DEBUG) print("Solving complete: no remaining items");
finalComment();
- this.results.forEach(function(output) {
- delete output.__uid__; // Might recycle these
+ this.results.forEach(function(result) {
+ delete result.__uid__; // Might recycle these
+ if (that.onResult) that.onResult(result);
});
ret = this.results;
break;
diff --git a/src/intertyper.js b/src/intertyper.js
index bc9ef05a..60b560b3 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -526,16 +526,18 @@ function intertyper(data, parseFunctions, baseLineNum) {
substrate.addActor('Assign', {
processItem: function(item) {
var opIndex = findTokenText(item, '=');
+ if (!item.tokens.slice(-1)[0].item) throw 'Did you run llvm-dis with -show-annotations?';
+ var commentIndex = getTokenIndexByText(item.tokens, ';');
var pair = splitItem({
intertype: 'assign',
ident: toNiceIdent(combineTokens(item.tokens.slice(0, opIndex)).text),
- lineNum: item.lineNum
+ lineNum: item.lineNum,
+ uses: parseInt(item.tokens[commentIndex+1].item.tokens[0].text.split('=')[1])
}, 'value');
this.forwardItem(pair.parent, 'Reintegrator');
- this.forwardItem(mergeInto(pair.child, { // Additional token, to be triaged and later re-integrated
- indent: -1,
- tokens: item.tokens.slice(opIndex+1)
- }), 'Triager');
+ pair.child.indent = -1;
+ pair.child.tokens = item.tokens.slice(opIndex+1);
+ this.forwardItem(pair.child, 'Triager');
}
});
@@ -936,6 +938,10 @@ function intertyper(data, parseFunctions, baseLineNum) {
llvmLines: data
}, 'LineSplitter');
+ substrate.onResult = function(result) {
+ if (result.tokens) result.tokens = null; // We do not need tokens, past the intertyper. Clean them up as soon as possible here.
+ };
+
return substrate.solve();
}