diff options
-rw-r--r-- | src/analyzer.js | 4 | ||||
-rw-r--r-- | src/compiler.js | 31 | ||||
-rw-r--r-- | src/intertyper.js | 3 | ||||
-rw-r--r-- | src/jsifier.js | 3 | ||||
-rw-r--r-- | src/library.js | 14 | ||||
-rw-r--r-- | src/parseTools.js | 3 | ||||
-rw-r--r-- | src/runtime.js | 14 |
7 files changed, 45 insertions, 27 deletions
diff --git a/src/analyzer.js b/src/analyzer.js index 0cb89eda..50683ec7 100644 --- a/src/analyzer.js +++ b/src/analyzer.js @@ -1,4 +1,6 @@ -// Analyze intertype data +// Analyze intertype data. Calculates things that are necessary in order +// to do the final conversion into JavaScript later, for example, +// properties of variables, loop structures of functions, etc. VAR_NATIVE = 'native'; VAR_NATIVIZED = 'nativized'; diff --git a/src/compiler.js b/src/compiler.js index 1cdc0002..92c9a4d9 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -8,20 +8,9 @@ if (!this['read']) { read = function(f) { snarf(f) }; } -load('settings.js'); +// Load settings, can be overridden by commandline -load('utility.js'); -load('framework.js'); -load('parseTools.js'); -load('intertyper.js'); -load('analyzer.js'); -load('jsifier.js'); - -//=============================== -// Main -//=============================== - -// Override settings.js +load('settings.js'); var settings = JSON.parse(readline()); for (setting in settings) { @@ -29,12 +18,25 @@ for (setting in settings) { } var CONSTANTS = { 'QUANTUM_SIZE': QUANTUM_SIZE }; +// Load compiler code + +load('utility.js'); +load('framework.js'); +load('parseTools.js'); +load('intertyper.js'); +load('analyzer.js'); +load('jsifier.js'); load('runtime.js'); +eval(preprocess(read('library.js'), CONSTANTS)); -// Sanity of settings +// Sanity checks assert(!(USE_TYPED_ARRAYS && SAFE_HEAP)); +//=============================== +// Main +//=============================== + // Read llvm var lines = []; @@ -47,6 +49,5 @@ do { // Do it -eval(preprocess(read('library.js'), CONSTANTS)); print(JSify(analyzer(intertyper(lines)))); diff --git a/src/intertyper.js b/src/intertyper.js index 9897884b..a8636555 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -1,4 +1,5 @@ -// llvm => internal intermediate representation +// LLVM assembly => internal intermediate representation, which is ready +// to be processed by the later stages. var LLVM_STYLE = null; diff --git a/src/jsifier.js b/src/jsifier.js index e3fbf3e4..80d8b41f 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1,4 +1,5 @@ -// Convert analyzed data to javascript +// Convert analyzed data to javascript. Everything has already been calculated +// before this stage, which just does the final conversion to JavaScript. function JSify(data, functionsOnly, givenTypes, givenFunctions, givenGlobalVariables) { substrate = new Substrate('JSifyer'); diff --git a/src/library.js b/src/library.js index 0d5f2c22..2675b38b 100644 --- a/src/library.js +++ b/src/library.js @@ -1,3 +1,17 @@ +// An implementation of a libc for the web. Basically, implementations of +// the various standard C libraries, that can be called from compiled code, +// and work using the actual JavaScript environment. +// +// We search the Library object when there is an external function. If the +// entry in the Library is a function, we insert it. If it is a string, we +// do another lookup in the library (a simple way to write a function once, +// if it can be called by different names). We also allow dependencies, +// using __deps. +// +// Note that the full function name will be '_' + the name in the Library +// object. For convenience, the short name appears here. Note that if you add a +// new function with an '_', it will not be found. + var Library = { // stdio.h diff --git a/src/parseTools.js b/src/parseTools.js index ac212248..05c8fc10 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1,4 +1,5 @@ -// Various tools for parsing llvm +// Various tools for parsing LLVM. Utilities of various sorts, that are +// specific to Emscripten (and hence not in utility.js). // Simple #if/else/endif preprocessing for a file. Checks if the // ident checked is true in our global. Also replaces some constants diff --git a/src/runtime.js b/src/runtime.js index 3784c236..7131bf9c 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -1,7 +1,9 @@ -////////////QUANTUM_SIZE = GUARD_STACK = 1; -// Generates code that can be placed inline in generated code. -// This is not the cleanest way to write this kind of code - it is -// optimized for generating fast inline code. +// Implementation details for the 'runtime environment' we generate in +// JavaScript. The Runtime object itself is used both during compilation, +// and is available at runtime (dynamic compilation). The RuntimeGenerator +// helps to create the Runtime object (written so that the Runtime object +// itself is as optimized as possible - no unneeded runtime checks). + RuntimeGenerator = { alloc: function(size, type) { var ret = type + 'TOP'; @@ -76,10 +78,6 @@ function unInline(name_, params) { return eval(src); } -// Uses the RuntimeGenerator during compilation, in order to -// 1. Let the compiler access and run those functions during compilation -// 2. We expose the entire Runtime object to generated code, so it can -// use that functionality in a non-inline manner. Runtime = { stackAlloc: unInline('stackAlloc', ['size']), staticAlloc: unInline('staticAlloc', ['size']), |