Skip to content

Commit

Permalink
Remove final WASM_BACKEND usage in src/. See #11860
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken committed Aug 12, 2020
1 parent c6212ef commit 7919643
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 136 deletions.
26 changes: 0 additions & 26 deletions src/runtime_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
* SPDX-License-Identifier: MIT
*/

#if !WASM_BACKEND
var jsCallStartIndex = 1;
var functionPointers = new Array({{{ RESERVED_FUNCTION_POINTERS }}});
#endif // !WASM_BACKEND

#if WASM
// Wraps a JS function as a wasm function with a given signature.
function convertJsFunctionToWasm(func, sig) {
Expand Down Expand Up @@ -147,11 +142,7 @@ function addFunctionWasm(func, sig) {
if (!(err instanceof RangeError)) {
throw err;
}
#if WASM_BACKEND
throw 'Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.';
#else
throw 'Unable to grow wasm table. Use a higher value for RESERVED_FUNCTION_POINTERS or set ALLOW_TABLE_GROWTH.';
#endif
}
}

Expand Down Expand Up @@ -193,26 +184,9 @@ function addFunction(func, sig) {
#endif // ASSERTIONS == 2
#endif // ASSERTIONS

#if WASM_BACKEND
return addFunctionWasm(func, sig);
#else

var base = 0;
for (var i = base; i < base + {{{ RESERVED_FUNCTION_POINTERS }}}; i++) {
if (!functionPointers[i]) {
functionPointers[i] = func;
return jsCallStartIndex + i;
}
}
throw 'Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS.';

#endif // WASM_BACKEND
}

function removeFunction(index) {
#if WASM_BACKEND
removeFunctionWasm(index);
#else
functionPointers[index-jsCallStartIndex] = null;
#endif // WASM_BACKEND
}
4 changes: 0 additions & 4 deletions src/runtime_init_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
var wasmTable = new WebAssembly.Table({
'initial': {{{ getQuoted('WASM_TABLE_SIZE') }}},
#if !ALLOW_TABLE_GROWTH
#if WASM_BACKEND
'maximum': {{{ getQuoted('WASM_TABLE_SIZE') }}} + {{{ RESERVED_FUNCTION_POINTERS }}},
#else
'maximum': {{{ getQuoted('WASM_TABLE_SIZE') }}},
#endif
#endif // WASM_BACKEND
'element': 'anyfunc'
});
#endif
10 changes: 0 additions & 10 deletions src/runtime_stack_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ function writeStackCookie() {
#if ASSERTIONS
assert((STACK_MAX & 3) == 0);
#endif
#if WASM_BACKEND
// The stack grows downwards
HEAPU32[(STACK_MAX >> 2)+1] = 0x2135467;
HEAPU32[(STACK_MAX >> 2)+2] = 0x89BACDFE;
#else
HEAPU32[(STACK_MAX >> 2)-1] = 0x2135467;
HEAPU32[(STACK_MAX >> 2)-2] = 0x89BACDFE;
#endif
#if !USE_ASAN
// Also test the global address 0 for integrity.
// We don't do this with ASan because ASan does its own checks for this.
Expand All @@ -26,13 +21,8 @@ function writeStackCookie() {
}

function checkStackCookie() {
#if WASM_BACKEND
var cookie1 = HEAPU32[(STACK_MAX >> 2)+1];
var cookie2 = HEAPU32[(STACK_MAX >> 2)+2];
#else
var cookie1 = HEAPU32[(STACK_MAX >> 2)-1];
var cookie2 = HEAPU32[(STACK_MAX >> 2)-2];
#endif
if (cookie1 != 0x2135467 || cookie2 != 0x89BACDFE) {
abort('Stack overflow! Stack cookie has been overwritten, expected hex dwords 0x89BACDFE and 0x2135467, but received 0x' + cookie2.toString(16) + ' ' + cookie1.toString(16));
}
Expand Down
23 changes: 0 additions & 23 deletions src/shell_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,6 @@ if (ENVIRONMENT_IS_SHELL) {
}
#endif

#if !WASM && !WASM_BACKEND
// asm.js loading in fastcomp backend:

#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_IS_NODE) {
var fs = require('fs');
#if MEM_INIT_METHOD == 1 && !MEM_INIT_IN_WASM
Module['mem'] = fs.readFileSync(__dirname + '/{{{ TARGET_BASENAME }}}.mem');
#endif
}
#endif

#if ENVIRONMENT_MAY_BE_SHELL
if (ENVIRONMENT_IS_SHELL) {
eval(read('{{{ TARGET_BASENAME }}}.asm.js')+'');
#if MEM_INIT_METHOD == 1 && !MEM_INIT_IN_WASM
Module['mem'] = read('{{{ TARGET_BASENAME }}}.mem', 'binary');
#endif
}
#endif

#endif

#endif // !SINGLE_FILE

// Redefine these in a --pre-js to override behavior. If you would like to
Expand Down
56 changes: 1 addition & 55 deletions src/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,6 @@ function warnOnce(text) {
}
}

#if !WASM_BACKEND
var asm2wasmImports = { // special asm2wasm imports
"f64-rem": function(x, y) {
return x % y;
},
"debugger": function() {
#if ASSERTIONS // Disable debugger; statement from being present in release builds to avoid Firefox deoptimizations, see https://bugzilla.mozilla.org/show_bug.cgi?id=1538375
debugger;
#endif
}
#if NEED_ALL_ASM2WASM_IMPORTS
,
"f64-to-int": function(x) {
return x | 0;
},
"i32s-div": function(x, y) {
return ((x | 0) / (y | 0)) | 0;
},
"i32u-div": function(x, y) {
return ((x >>> 0) / (y >>> 0)) >>> 0;
},
"i32s-rem": function(x, y) {
return ((x | 0) % (y | 0)) | 0;
},
"i32u-rem": function(x, y) {
return ((x >>> 0) % (y >>> 0)) >>> 0;
}
#endif // NEED_ALL_ASM2WASM_IMPORTS
};
#endif

#if RELOCATABLE
// dynamic linker/loader (a-la ld.so on ELF systems)
var LDSO = {
Expand Down Expand Up @@ -104,12 +73,8 @@ function fetchBinary(url) {
}

function asmjsMangle(x) {
#if WASM_BACKEND
var unmangledSymbols = {{{ buildStringArray(WASM_FUNCTIONS_THAT_ARE_NOT_NAME_MANGLED) }}};
return x.indexOf('dynCall_') == 0 || unmangledSymbols.indexOf(x) != -1 ? x : '_' + x;
#else
return x;
#endif
}

// loadDynamicLibrary loads dynamic library @ lib URL / path and returns handle for loaded DSO.
Expand Down Expand Up @@ -260,18 +225,6 @@ function loadDynamicLibrary(lib, flags) {
// We should copy the symbols (which include methods and variables) from SIDE_MODULE to MAIN_MODULE.

var module_sym = asmjsMangle(sym);
#if !WASM_BACKEND
// Module of SIDE_MODULE has not only the symbols (which should be copied)
// but also others (print*, asmGlobal*, FUNCTION_TABLE_**, NAMED_GLOBALS, and so on).
//
// When the symbol (which should be copied) is method, Module.* 's type becomes function.
// When the symbol (which should be copied) is variable, Module.* 's type becomes number.
// Except for the symbol prefix (_), there is no difference in the symbols (which should be copied) and others.
// So this just copies over compiled symbols (which start with _).
if (!sym.startsWith('dynCall_') && sym[0] !== '_') {
continue;
}
#endif

if (!Module.hasOwnProperty(module_sym)) {
Module[module_sym] = libModule[sym];
Expand Down Expand Up @@ -334,11 +287,7 @@ function relocateExports(exports, memoryBase, tableBase, moduleLocal) {
}
relocated[e] = value;
if (moduleLocal) {
#if WASM_BACKEND
moduleLocal['_' + e] = value;
#else
moduleLocal[e] = value;
#endif
}
}
return relocated;
Expand Down Expand Up @@ -549,9 +498,6 @@ function loadWebAssemblyModule(binary, flags) {
'global.Math': Math,
env: proxy,
{{{ WASI_MODULE_NAME }}}: proxy,
#if !WASM_BACKEND
'asm2wasm': asm2wasmImports
#endif
};
#if ASSERTIONS
var oldTable = [];
Expand Down Expand Up @@ -711,7 +657,7 @@ var GLOBAL_BASE = {{{ GLOBAL_BASE }}};
GLOBAL_BASE = alignMemory(GLOBAL_BASE, {{{ MAX_GLOBAL_ALIGN || 1 }}});
#endif

#if WASM_BACKEND && USE_PTHREADS
#if USE_PTHREADS
// JS library code refers to Atomics in the manner used from asm.js, provide
// the same API here.
var Atomics_load = Atomics.load;
Expand Down
18 changes: 0 additions & 18 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ this.onmessage = function(e) {
var imports = {};
#endif

#if !WASM_BACKEND
// Initialize the thread-local field(s):
#if MINIMAL_RUNTIME
var imports = {};
#endif
#endif

// Initialize the global "process"-wide fields:
#if !MINIMAL_RUNTIME
Module['DYNAMIC_BASE'] = e.data.DYNAMIC_BASE;
Expand Down Expand Up @@ -178,31 +171,20 @@ this.onmessage = function(e) {
selfThreadId = e.data.selfThreadId;
parentThreadId = e.data.parentThreadId;
// Establish the stack frame for this thread in global scope
#if WASM_BACKEND
// The stack grows downwards
var max = e.data.stackBase;
var top = e.data.stackBase + e.data.stackSize;
#else
var max = e.data.stackBase + e.data.stackSize;
var top = e.data.stackBase;
#endif
#if ASSERTIONS
assert(threadInfoStruct);
assert(selfThreadId);
assert(parentThreadId);
assert(top != 0);
assert(max != 0);
#if WASM_BACKEND
assert(top > max);
#else
assert(max > top);
#endif
#endif
// Also call inside JS module to set up the stack frame for this pthread in JS module scope
Module['establishStackSpace'](top, max);
#if WASM_BACKEND
Module['_emscripten_tls_init']();
#endif
#if STACK_OVERFLOW_CHECK
Module['writeStackCookie']();
#endif
Expand Down

0 comments on commit 7919643

Please sign in to comment.