aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-12-27 15:25:31 -0500
committerAlon Zakai <alonzakai@gmail.com>2012-12-27 15:25:31 -0500
commit275adcf5ce7729295d0fa706cbb2f45ac0a875ef (patch)
tree2d0067ee1f647a132448aac0469f07a874ffd196
parent66021ae3aba2f532610efda849f8dbabc8f94783 (diff)
allow (unoptimal) single-phase compiler.js invocation
-rw-r--r--src/compiler.js49
-rw-r--r--src/intertyper.js2
-rw-r--r--src/jsifier.js6
-rw-r--r--src/modules.js2
4 files changed, 37 insertions, 22 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 3ce53b1e..e87ff760 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -225,30 +225,43 @@ raw = null;
// Pre-process the LLVM assembly
-//printErr('JS compiler in action, phase ' + phase);
-
Debugging.handleMetadata(lines);
-if (phase != 'pre') {
- PassManager.load(read(forwardedDataFile));
+function runPhase(currPhase) {
+ //printErr('// JS compiler in action, phase ' + currPhase + typeof lines + (lines === null));
+ phase = currPhase;
+ if (phase != 'pre') {
+ if (singlePhase) PassManager.load(read(forwardedDataFile));
- if (phase == 'funcs') {
- PreProcessor.eliminateUnneededIntrinsics(lines);
+ if (phase == 'funcs') {
+ PreProcessor.eliminateUnneededIntrinsics(lines);
+ }
}
-}
-// Do it
+ // Do it
+
+ var intertyped = intertyper(lines);
+ if (singlePhase) lines = null;
+ var analyzed = analyzer(intertyped);
+ intertyped = null;
+ JSify(analyzed);
-var intertyped = intertyper(lines);
-lines = null;
-var analyzed = analyzer(intertyped);
-intertyped = null;
-JSify(analyzed);
+ if (DEBUG_MEMORY) {
+ print('zzz. last gc: ' + gc());
+ MemoryDebugger.dump();
+ print('zzz. hanging now!');
+ while(1){};
+ }
+}
-if (DEBUG_MEMORY) {
- print('zzz. last gc: ' + gc());
- MemoryDebugger.dump();
- print('zzz. hanging now!');
- while(1){};
+// Normal operation is for each execution of compiler.js to run a single phase. The calling script sends us exactly the information we need, and it is easy to parallelize operation that way. However, it is also possible to run in an unoptimal multiphase mode, where a single invocation goes from ll to js directly. This is not recommended and will likely do a lot of duplicate processing.
+singlePhase = !!phase;
+
+if (singlePhase) {
+ runPhase(phase);
+} else {
+ runPhase('pre');
+ runPhase('funcs');
+ runPhase('post');
}
diff --git a/src/intertyper.js b/src/intertyper.js
index 1d18c3cf..5af291c7 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -61,7 +61,7 @@ function intertyper(data, sidePass, baseLineNums) {
var baseLineNumPosition = 0;
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
- lines[i] = null; // lines may be very very large. Allow GCing to occur in the loop by releasing refs here
+ if (singlePhase) lines[i] = null; // lines may be very very large. Allow GCing to occur in the loop by releasing refs here
while (baseLineNumPosition < baseLineNums.length-1 && i >= baseLineNums[baseLineNumPosition+1][0]) {
baseLineNumPosition++;
diff --git a/src/jsifier.js b/src/jsifier.js
index c7279168..25e79be7 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1333,8 +1333,10 @@ function JSify(data, functionsOnly, givenFunctions) {
var generated = itemsDict.functionStub.concat(itemsDict.GlobalVariablePostSet);
generated.forEach(function(item) { print(indentify(item.JS || '', 2)); });
} else {
- assert(data.unparsedGlobalss[0].lines.length == 0, dump([phase, data.unparsedGlobalss]));
- assert(itemsDict.functionStub.length == 0, dump([phase, itemsDict.functionStub]));
+ if (singlePhase) {
+ assert(data.unparsedGlobalss[0].lines.length == 0, dump([phase, data.unparsedGlobalss]));
+ assert(itemsDict.functionStub.length == 0, dump([phase, itemsDict.functionStub]));
+ }
}
if (phase == 'pre' || phase == 'funcs') {
diff --git a/src/modules.js b/src/modules.js
index fd0ec35e..64638be1 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -269,7 +269,7 @@ var LibraryManager = {
loaded: false,
load: function() {
- assert(!this.library);
+ if (this.library) return;
var libraries = ['library.js', 'library_browser.js', 'library_sdl.js', 'library_gl.js', 'library_glut.js', 'library_xlib.js', 'library_egl.js', 'library_gc.js', 'library_jansson.js'].concat(additionalLibraries);
for (var i = 0; i < libraries.length; i++) {