aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-08-28 18:12:53 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-09-03 14:41:29 -0700
commitc76946b2f3cebf00a5e24c9582eb9b59f1039a6d (patch)
tree26754c6f7429e6a502e222f5d44be31980a87503 /src
parentaa1c42a298a568f2910cb0a184824763016ce64f (diff)
support function pointer calls across asm modules by passing them all through invoke (for now), and have a global function table in the Runtime, which modules register their functions to
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js1
-rw-r--r--src/library.js11
-rw-r--r--src/runtime.js28
-rw-r--r--src/shell_sharedlib.js3
4 files changed, 40 insertions, 3 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 3a87df45..c3ba6e74 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1406,6 +1406,7 @@ function JSify(data, functionsOnly, givenFunctions) {
assert(ident != 'asm', 'Inline assembly cannot be compiled to JavaScript!');
if (ASM_JS && funcData.setjmpTable) forceByPointer = true; // in asm.js mode, we must do an invoke for each call
+ if (ASM_JS && DLOPEN_SUPPORT) invoke = true; // go through invoke so we can access other modules TODO: optimize
ident = Variables.resolveAliasToIdent(ident);
var shortident = ident.slice(1);
diff --git a/src/library.js b/src/library.js
index c160c785..25251299 100644
--- a/src/library.js
+++ b/src/library.js
@@ -5050,11 +5050,11 @@ LibraryManager.library = {
try {
var lib_module = eval(lib_data)(
#if ASM_JS
- asm.maxFunctionIndex,
- Module
+ Runtime.functionTable.length,
#else
- {{{ Functions.getTable('x') }}}.length
+ {{{ Functions.getTable('x') }}}.length,
#endif
+ Module
);
} catch (e) {
#if ASSERTIONS
@@ -5132,7 +5132,12 @@ LibraryManager.library = {
} else {
var result = lib.module[symbol];
if (typeof result == 'function') {
+#if ASM_JS
+ result = lib.module.SYMBOL_TABLE[symbol];
+ assert(result);
+#else
result = Runtime.addFunction(result);
+#endif
lib.cached_functions = result;
}
return result;
diff --git a/src/runtime.js b/src/runtime.js
index 33088ad9..e42f90e3 100644
--- a/src/runtime.js
+++ b/src/runtime.js
@@ -384,6 +384,34 @@ var Runtime = {
return Runtime.funcWrappers[func];
},
+#if DLOPEN_SUPPORT
+ functionTable: [], // will contain objects mapping sigs to js functions that call into the right asm module with the right index
+
+ registerFunctions: function(asm, num, sigs, jsModule) {
+ // use asm module dynCall_* from functionTable
+ if (num % 2 == 1) num++; // keep pointers even
+ var table = Runtime.functionTable;
+ var from = table.length;
+ assert(from % 2 == 0);
+ for (var i = 0; i < num; i++) {
+ table[from + i] = {};
+ sigs.forEach(function(sig) { // TODO: new Function etc.
+ var full = 'dynCall_' + sig;
+ table[from + i][sig] = function() {
+ arguments[i] -= from;
+ return asm[full].apply(null, arguments);
+ }
+ });
+ }
+ // patch js module dynCall_* to use functionTable
+ sigs.forEach(function(sig) {
+ jsModule['dynCall_' + sig] = function() {
+ return table[arguments[0]][sig].apply(null, arguments);
+ };
+ });
+ },
+#endif
+
// Returns a processor of UTF.
// processCChar() receives characters from a C-like UTF representation and returns JS string fragments.
// See RFC3629 for details, the bytes are assumed to be valid UTF-8
diff --git a/src/shell_sharedlib.js b/src/shell_sharedlib.js
index 505c3d7b..a2956c24 100644
--- a/src/shell_sharedlib.js
+++ b/src/shell_sharedlib.js
@@ -3,6 +3,8 @@
var Module = {};
var args = [];
Module.arguments = [];
+ Module.print = parentModule.print;
+ Module.printErr = parentModule.printErr;
{{BODY}}
@@ -10,3 +12,4 @@
return Module;
});
+