diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-06-29 19:16:08 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-06-29 19:16:08 -0700 |
commit | 0e9344a42800afd65b3c74c86e79ed78c15161f0 (patch) | |
tree | 44dfad042648a02fed1fe76c002f677f5b70e497 /src | |
parent | 8fc2acdc4ec487130a98f26e3e8e2a70bd54de96 (diff) |
indexize external functions (for shared libraries, primarily), +some code cleanup around that. fixed issues 38
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 26 | ||||
-rw-r--r-- | src/library.js | 15 | ||||
-rw-r--r-- | src/modules.js | 2 | ||||
-rw-r--r-- | src/parseTools.js | 2 |
4 files changed, 35 insertions, 10 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 62acf8d7..5a92ba52 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -3,8 +3,10 @@ // Main function function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { + var mainPass = !functionsOnly; + // Add additional necessary items for the main pass - if (!functionsOnly) { + if (mainPass) { var libFuncsToInclude; if (INCLUDE_FULL_LIBRARY) { assert(!BUILD_AS_SHARED_LIB, 'Cannot have both INCLUDE_FULL_LIBRARY and BUILD_AS_SHARED_LIB set.') @@ -31,11 +33,15 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { substrate = new Substrate('JSifyer'); - var GLOBAL_VARIABLES = functionsOnly ? givenGlobalVariables : data.globalVariables; + var GLOBAL_VARIABLES = !mainPass ? givenGlobalVariables : data.globalVariables; + + Functions.currFunctions = !mainPass ? givenFunctions : {}; + if (mainPass) { + Functions.currExternalFunctions = set(data.functionStubs.map(function(item) { return item.ident })); + } - Functions.currFunctions = functionsOnly ? givenFunctions : {}; - // Now that analysis has completed, we can get around to handling unparsedFunctions - (functionsOnly ? data.functions : data.unparsedFunctions.concat(data.functions)).forEach(function(func) { + // Now that first-pass analysis has completed (so we have basic types, etc.), we can get around to handling unparsedFunctions + (!mainPass ? data.functions : data.unparsedFunctions.concat(data.functions)).forEach(function(func) { // Save just what we need, to save memory Functions.currFunctions[func.ident] = { hasVarArgs: func.hasVarArgs, @@ -57,7 +63,11 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { if (data.unparsedFunctions.length > 0) { // We are now doing the final JS generation dprint('unparsedFunctions', '== Completed unparsedFunctions ==\n'); - //Debugging.clear(); // Save some memory, before the final heavy lifting + + // Save some memory, before the final heavy lifting + //Functions.currFunctions = null; + //Functions.currExternalFunctions = null; + //Debugging.clear(); } // Actors @@ -771,12 +781,12 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) { items = null; var generated = []; - if (!functionsOnly) { + if (mainPass) { generated = generated.concat(itemsDict.type).concat(itemsDict.GlobalVariableStub).concat(itemsDict.functionStub); } generated = generated.concat(itemsDict.function).concat(data.unparsedFunctions); - if (functionsOnly) return generated.map(function(item) { return item.JS }).join('\n'); + if (!mainPass) return generated.map(function(item) { return item.JS }).join('\n'); // We are ready to print out the data, but must do so carefully - we are // dealing with potentially *huge* strings. Convenient replacements and diff --git a/src/library.js b/src/library.js index 284f093d..685f839a 100644 --- a/src/library.js +++ b/src/library.js @@ -1476,7 +1476,17 @@ var Library = { // ========================================================================== - // dlfcn.h + // dlfcn.h - Dynamic library loading + // + // Some limitations: + // + // * Minification on each file separately may not work, as they will + // have different shortened names. You can in theory combine them, then + // minify, then split... perhaps. + // + // * LLVM optimizations may fail. If the child wants to access a function + // in the parent, LLVM opts may remove it from the parent when it is + // being compiled. Not sure how to tell LLVM to not do so. // ========================================================================== // Data for dlfcn.h. @@ -1510,6 +1520,9 @@ var Library = { try { var lib_module = eval(lib_data)(FUNCTION_TABLE.length); } catch (e) { +#if ASSERTIONS + print('Error in loading dynamic library: ' + e); +#endif DLFCN_DATA.isError = true; return 0; } diff --git a/src/modules.js b/src/modules.js index 91758609..f9185725 100644 --- a/src/modules.js +++ b/src/modules.js @@ -124,6 +124,8 @@ var Types = { var Functions = { // The list of function datas which are being processed in the jsifier, currently currFunctions: [], + // The list of functions that are external'ly defined + currExternalFunctions: [], indexedFunctions: [0, 0], // Start at a non-0 (even, see below) value diff --git a/src/parseTools.js b/src/parseTools.js index 4f0cda35..fe71ff3b 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -695,7 +695,7 @@ function makeGetValue(ptr, pos, type, noNeedFirst, unsigned) { } function indexizeFunctions(value) { - if (value in Functions.currFunctions) { + if (value in Functions.currFunctions || value in Functions.currExternalFunctions) { if (BUILD_AS_SHARED_LIB) { return '(FUNCTION_TABLE_OFFSET + ' + Functions.getIndex(value) + ')'; } else { |