diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-12-05 14:09:46 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-12-05 14:09:46 -0800 |
commit | d2f91efe1fcf98f59a8d142880e1910ddd2ff726 (patch) | |
tree | e4ba34462a7aba9e8073188cc1ac02e93cf8eae7 /src/jsifier.js | |
parent | 60a4cbdba470cb5e7500d9155fbbff9167c5094a (diff) |
partial support for runtime linking of separately-compiled modules (only functions)
Diffstat (limited to 'src/jsifier.js')
-rw-r--r-- | src/jsifier.js | 15 |
1 files changed, 15 insertions, 0 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'); |