diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-12-31 11:56:53 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-31 11:56:53 -0800 |
commit | 2325baf34e144586d71251f31c01c7f2abfdb8b7 (patch) | |
tree | 6dec7e37e75040034d443786d4701e62b38a4d6d /src/compiler.js | |
parent | 8aa6919b7acf0b4034735ac7ee597e946fefaf4d (diff) | |
parent | a55c2a24a50a93fcf9035eb2a809d13d3a8d3555 (diff) |
Merge branch 'incoming' into asm_js
Conflicts:
src/library_browser.js
Diffstat (limited to 'src/compiler.js')
-rw-r--r-- | src/compiler.js | 84 |
1 files changed, 55 insertions, 29 deletions
diff --git a/src/compiler.js b/src/compiler.js index ecfd506e..118ca83a 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -76,10 +76,12 @@ if (ENVIRONMENT_IS_NODE) { } } else if (ENVIRONMENT_IS_WEB) { - this['print'] = printErr = function(x) { + printErr = function(x) { console.log(x); }; + if (!this['print']) this['print'] = printErr; + this['read'] = function(url) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, false); @@ -220,42 +222,66 @@ NECESSARY_BLOCKADDRS = temp; // Read llvm -var raw = read(ll_file); -if (FAKE_X86_FP80) { - raw = raw.replace(/x86_fp80/g, 'double'); -} -if (raw.search('\r\n') >= 0) { - raw = raw.replace(/\r\n/g, '\n'); // fix windows line endings -} -var lines = raw.split('\n'); -raw = null; +function compile(raw) { + if (FAKE_X86_FP80) { + raw = raw.replace(/x86_fp80/g, 'double'); + } + if (raw.search('\r\n') >= 0) { + raw = raw.replace(/\r\n/g, '\n'); // fix windows line endings + } + var lines = raw.split('\n'); + raw = null; + + // Pre-process the LLVM assembly + + Debugging.handleMetadata(lines); + + 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)); -// Pre-process the LLVM assembly + if (phase == 'funcs') { + PreProcessor.eliminateUnneededIntrinsics(lines); + } + } -//printErr('JS compiler in action, phase ' + phase); + // Do it -Debugging.handleMetadata(lines); + var intertyped = intertyper(lines); + if (singlePhase) lines = null; + var analyzed = analyzer(intertyped); + intertyped = null; + JSify(analyzed); -if (phase != 'pre') { - PassManager.load(read(forwardedDataFile)); + phase = null; - if (phase == 'funcs') { - PreProcessor.eliminateUnneededIntrinsics(lines); + if (DEBUG_MEMORY) { + print('zzz. last gc: ' + gc()); + MemoryDebugger.dump(); + print('zzz. hanging now!'); + while(1){}; + } } -} -// Do it + // 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; -var intertyped = intertyper(lines); -lines = null; -var analyzed = analyzer(intertyped); -intertyped = null; -JSify(analyzed); + if (singlePhase) { + runPhase(phase); + } else { + runPhase('pre'); + runPhase('funcs'); + runPhase('post'); + } +} -if (DEBUG_MEMORY) { - print('zzz. last gc: ' + gc()); - MemoryDebugger.dump(); - print('zzz. hanging now!'); - while(1){}; +if (ll_file) { + if (ll_file.indexOf(String.fromCharCode(10)) == -1) { + compile(read(ll_file)); + } else { + compile(ll_file); // we are given raw .ll + } } |