aboutsummaryrefslogtreecommitdiff
path: root/src/compiler.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler.js')
-rw-r--r--src/compiler.js64
1 files changed, 48 insertions, 16 deletions
diff --git a/src/compiler.js b/src/compiler.js
index 94e77e26..17a8e83c 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -121,6 +121,8 @@ if (typeof print === 'undefined') {
// *** Environment setup code ***
+DEBUG_MEMORY = false;
+
// Basic utilities
load('utility.js');
@@ -132,7 +134,7 @@ load('settings.js');
var settings_file = arguments_[0];
var ll_file = arguments_[1];
phase = arguments_[2];
-if (phase == 'pre') {
+if (phase == 'pre' || phase == 'glue') {
additionalLibraries = Array.prototype.slice.call(arguments_, 3);
} else {
var forwardedDataFile = arguments_[3];
@@ -176,15 +178,12 @@ DEAD_FUNCTIONS = numberedSet(DEAD_FUNCTIONS);
RUNTIME_DEBUG = LIBRARY_DEBUG || GL_DEBUG;
+if (SAFE_HEAP) USE_BSS = 0; // must initialize heap for safe heap
+
// Settings sanity checks
assert(!(USE_TYPED_ARRAYS === 2 && QUANTUM_SIZE !== 4), 'For USE_TYPED_ARRAYS == 2, must have normal QUANTUM_SIZE of 4');
-if (ASM_JS) {
- assert(!ALLOW_MEMORY_GROWTH, 'Cannot grow asm.js heap');
- assert((TOTAL_MEMORY&(TOTAL_MEMORY-1)) == 0, 'asm.js heap must be power of 2');
-}
-assert(!BUILD_AS_SHARED_LIB, 'shared libs are deprecated');
-//assert(!(!NAMED_GLOBALS && BUILD_AS_SHARED_LIB), 'shared libraries must have named globals');
+assert(!(!NAMED_GLOBALS && BUILD_AS_SHARED_LIB), 'shared libraries must have named globals');
// Output some info and warnings based on settings
@@ -201,16 +200,33 @@ if (phase == 'pre') {
}
}
+if (VERBOSE) printErr('VERBOSE is on, this generates a lot of output and can slow down compilation');
+
+// Load struct and define information.
+//try {
+ var temp = JSON.parse(read(STRUCT_INFO));
+//} catch(e) {
+// printErr('cannot load struct info at ' + STRUCT_INFO + ' : ' + e + ', trying in current dir');
+// temp = JSON.parse(read('struct_info.compiled.json'));
+//}
+C_STRUCTS = temp.structs;
+C_DEFINES = temp.defines;
+
// Load compiler code
-load('framework.js');
load('modules.js');
load('parseTools.js');
load('intertyper.js');
load('analyzer.js');
load('jsifier.js');
-if (RELOOP) {
- load(RELOOPER);
+if (phase == 'funcs' && RELOOP) { // XXX handle !singlePhase
+ RelooperModule = { TOTAL_MEMORY: ceilPowerOfTwo(2*RELOOPER_BUFFER_SIZE) };
+ //try {
+ load(RELOOPER);
+ //} catch(e) {
+ // printErr('cannot load relooper at ' + RELOOPER + ' : ' + e + ', trying in current dir');
+ // load('relooper.js');
+ //}
assert(typeof Relooper != 'undefined');
}
globalEval(processMacros(preprocess(read('runtime.js'))));
@@ -248,7 +264,7 @@ function compile(raw) {
function runPhase(currPhase) {
//printErr('// JS compiler in action, phase ' + currPhase + typeof lines + (lines === null));
phase = currPhase;
- if (phase != 'pre') {
+ if (phase != 'pre' && phase != 'glue') {
if (singlePhase) PassManager.load(read(forwardedDataFile));
if (phase == 'funcs') {
@@ -264,6 +280,10 @@ function compile(raw) {
intertyped = null;
JSify(analyzed);
+ //dumpInterProf();
+ //printErr(phase + ' paths (fast, slow): ' + [fastPaths, slowPaths]);
+ B.print(phase);
+
phase = null;
if (DEBUG_MEMORY) {
@@ -286,11 +306,23 @@ function compile(raw) {
}
}
-if (ll_file) {
- if (ll_file.indexOf(String.fromCharCode(10)) == -1) {
- compile(read(ll_file));
- } else {
- compile(ll_file); // we are given raw .ll
+B = new Benchmarker();
+
+try {
+ if (ll_file) {
+ if (phase === 'glue') {
+ compile(';');
+ } else if (ll_file.indexOf(String.fromCharCode(10)) == -1) {
+ compile(read(ll_file));
+ } else {
+ compile(ll_file); // we are given raw .ll
+ }
}
+} catch(err) {
+ printErr('aborting from js compiler due to exception: ' + err + ' | ' + err.stack);
}
+//var M = keys(tokenCacheMisses).map(function(m) { return [m, misses[m]] }).sort(function(a, b) { return a[1] - b[1] });
+//printErr(dump(M.slice(M.length-10)));
+//printErr('hits: ' + hits);
+