diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-04-19 20:30:03 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-04-19 20:36:02 -0700 |
commit | 31872fbd01ca23962d954ca40232c7b8bfde58fe (patch) | |
tree | cf05b59fb1451f137e0ff96ef56bc9c184329099 /src | |
parent | 9089dc78a6c7fd21be5fc115451996018779dd40 (diff) |
support for Runtime.addFunction in asm.js
Diffstat (limited to 'src')
-rw-r--r-- | src/modules.js | 2 | ||||
-rw-r--r-- | src/preamble.js | 9 | ||||
-rw-r--r-- | src/runtime.js | 25 | ||||
-rw-r--r-- | src/settings.js | 3 |
4 files changed, 34 insertions, 5 deletions
diff --git a/src/modules.js b/src/modules.js index 5b5f7947..7a769846 100644 --- a/src/modules.js +++ b/src/modules.js @@ -234,7 +234,7 @@ var Functions = { unimplementedFunctions: {}, // library etc. functions that we need to index, maps id to signature indexedFunctions: {}, - nextIndex: 2, // Start at a non-0 (even, see below) value + nextIndex: (ASM_JS ? 2*RESERVED_FUNCTION_POINTERS : 0) + 2, // Start at a non-0 (even, see below) value blockAddresses: {}, // maps functions to a map of block labels to label ids diff --git a/src/preamble.js b/src/preamble.js index 17b74cd9..92305ca0 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -6,6 +6,15 @@ {{RUNTIME}} +#if ASM_JS +#if RESERVED_FUNCTION_POINTERS +function jsCall() { + var args = Array.prototype.slice.call(arguments); + return Runtime.functionPointers[args[0]].apply(null, args.slice(1)); +} +#endif +#endif + #if BENCHMARK Module.realPrint = Module.print; Module.print = Module.printErr = function(){}; diff --git a/src/runtime.js b/src/runtime.js index 2a26db28..5b9a8134 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -305,18 +305,35 @@ var Runtime = { } }, - addFunction: function(func, sig) { - //assert(sig); // TODO: support asm - var table = FUNCTION_TABLE; // TODO: support asm +#if ASM_JS + functionPointers: new Array(RESERVED_FUNCTION_POINTERS), +#endif + + addFunction: function(func) { +#if ASM_JS + for (var i = 0; i < Runtime.functionPointers.length; i++) { + if (!Runtime.functionPointers[i]) { + Runtime.functionPointers[i] = func; + return 2 + 2*i; + } + } + throw 'Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS.'; +#else + var table = FUNCTION_TABLE; var ret = table.length; table.push(func); table.push(0); return ret; +#endif }, removeFunction: function(index) { - var table = FUNCTION_TABLE; // TODO: support asm +#if ASM_JS + Runtime.functionPointers[(index-2)/2] = null; +#else + var table = FUNCTION_TABLE; table[index] = null; +#endif }, warnOnce: function(text) { diff --git a/src/settings.js b/src/settings.js index db24cca4..7cd0c02e 100644 --- a/src/settings.js +++ b/src/settings.js @@ -131,6 +131,9 @@ var CHECK_HEAP_ALIGN = 0; // Check heap accesses for alignment, but don't do as var SAFE_DYNCALLS = 0; // Show stack traces on missing function pointer/virtual method calls +var RESERVED_FUNCTION_POINTERS = 0; // In asm.js mode, we cannot simply add function pointers to + // function tables, so we reserve some slots for them. + var ASM_HEAP_LOG = 0; // Simple heap logging, like SAFE_HEAP_LOG but cheaper, and in asm.js var CORRUPTION_CHECK = 0; // When enabled, will emit a buffer area at the beginning and |