diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 15 | ||||
-rw-r--r-- | src/settings.js | 11 | ||||
-rw-r--r-- | src/shell_sharedlib.js | 2 |
3 files changed, 27 insertions, 1 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index b941032a..feebbe5a 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -321,6 +321,10 @@ function JSify(data, functionsOnly, givenFunctions) { if (item.ident in EXPORTED_GLOBALS) { js += '\nModule["' + item.ident + '"] = ' + item.ident + ';'; } + // TODO: Support exporting BUILD_AS_SHARED_LIB == 2 globals. The problem now is that they override the main file's globals. + //if (BUILD_AS_SHARED_LIB == 2) { + // js += 'if (globalScope) globalScope["' + item.ident + '"] = ' + item.ident + ';'; // XXX: assert not overriding + //} return ret.concat({ intertype: 'GlobalVariable', JS: js, @@ -603,6 +607,10 @@ function JSify(data, functionsOnly, givenFunctions) { func.JS += func.ident + '["X"]=1;'; } + if (BUILD_AS_SHARED_LIB == 2) { + func.JS += 'if (globalScope) { assert(!globalScope["' + func.ident + '"]); globalScope["' + func.ident + '"] = ' + func.ident + ' }'; + } + return func; } }); @@ -1116,7 +1124,14 @@ function JSify(data, functionsOnly, givenFunctions) { data.unparsedGlobalss = null; print(Functions.generateIndexing()); // done last, as it may rely on aliases set in postsets + + // Load runtime-linked libraries + RUNTIME_LINKED_LIBS.forEach(function(lib) { + print('eval(read("' + lib + '"))(FUNCTION_TABLE.length, this);'); + }); + print(postParts[1]); + print(shellParts[1]); // Print out some useful metadata (for additional optimizations later, like the eliminator) print('// EMSCRIPTEN_GENERATED_FUNCTIONS: ' + JSON.stringify(Functions.allIdents) + '\n'); diff --git a/src/settings.js b/src/settings.js index 66762298..9dba6a24 100644 --- a/src/settings.js +++ b/src/settings.js @@ -172,6 +172,17 @@ var SHOW_LABELS = 0; // Show labels in the generated code var BUILD_AS_SHARED_LIB = 0; // Whether to build the code as a shared library, which // must be loaded dynamically using dlopen(). + // 0 here means this is not a shared lib: It is a main file. + // 1 means this is a normal shared lib. + // 2 means this is a shared lib that will be linked at runtime, + // which means it will insert its functions into + // the global namespace. See STATIC_LIBS_TO_LOAD. Note + // that only functions are exported, not globals, since + // in a naive implementation they can easily override main's + // symbols (for example, the global strings, _str1 etc.). +var RUNTIME_LINKED_LIBS = []; // If this is a main file (BUILD_AS_SHARED_LIB == 0), then + // we will link these at runtime. They must have been built with + // BUILD_AS_SHARED_LIB == 2. var RUNTIME_TYPE_INFO = 0; // Whether to expose type info to the script at run time. This // increases the size of the generated script, but allows you diff --git a/src/shell_sharedlib.js b/src/shell_sharedlib.js index 60a78323..1d34c73e 100644 --- a/src/shell_sharedlib.js +++ b/src/shell_sharedlib.js @@ -1,5 +1,5 @@ // Capture the output of this into a variable, if you want -(function(FUNCTION_TABLE_OFFSET) { +(function(FUNCTION_TABLE_OFFSET, globalScope) { var Module = {}; var args = []; Module.arguments = []; |