#if MAIN_MODULE
{{{ makeModuleReceiveWithVar('dynamicLibraries', undefined, '[]') }}}
#endif
{{{ makeModuleReceiveWithVar('wasmBinary') }}}
#if WASM2JS
#if WASM != 2
#include "wasm2js.js"
#endif
if (WebAssembly.isWasm2js) {
wasmBinary = [];
}
#endif
#if ASSERTIONS && WASM == 1
if (!globalThis.WebAssembly) {
err('no native wasm support detected');
}
#endif
#if SHARED_MEMORY
var wasmModule;
#endif
var ABORT = false;
var EXITSTATUS;
#if ASSERTIONS || !STRICT
function assert(condition, text) {
if (!condition) {
#if ASSERTIONS
abort('Assertion failed' + (text ? ': ' + text : ''));
#else
abort(text);
#endif
}
}
#endif
#if ASSERTIONS
#if !hasExportedSymbol('malloc')
function _malloc() {
abort('malloc() called but not included in the build - add `_malloc` to EXPORTED_FUNCTIONS');
}
#endif
#if !hasExportedSymbol('free')
function _free() {
abort('free() called but not included in the build - add `_free` to EXPORTED_FUNCTIONS');
}
#endif
#endif
var isFileURI = (filename) => filename.startsWith('file://');
#include "runtime_common.js"
#if ASSERTIONS
assert(globalThis.Int32Array && globalThis.Float64Array && Int32Array.prototype.subarray && Int32Array.prototype.set,
'JS engine does not provide full typed array support');
#endif
#if RELOCATABLE || MAIN_MODULE
var __RELOC_FUNCS__ = [];
#endif
function preRun() {
#if ASSERTIONS && PTHREADS
assert(!ENVIRONMENT_IS_PTHREAD);
#endif
#if expectToReceiveOnModule('preRun')
if (Module['preRun']) {
if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
while (Module['preRun'].length) {
addOnPreRun(Module['preRun'].shift());
}
}
#if ASSERTIONS
consumedModuleProp('preRun');
#endif
#endif
<<< ATPRERUNS >>>
}
function initRuntime() {
#if RUNTIME_DEBUG
dbg('initRuntime');
#endif
#if ASSERTIONS
assert(!runtimeInitialized);
#endif
runtimeInitialized = true;
#if WASM_WORKERS
if (ENVIRONMENT_IS_WASM_WORKER) return _wasmWorkerInitializeRuntime();
#endif
#if PTHREADS
if (ENVIRONMENT_IS_PTHREAD) return startWorker();
#endif
#if STACK_OVERFLOW_CHECK >= 2
setStackLimits();
#endif
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
#if MAIN_MODULE || RELOCATABLE
callRuntimeCallbacks(__RELOC_FUNCS__);
#endif
<<< ATINITS >>>
#if hasExportedSymbol('__wasm_call_ctors')
#if WASM_ESM_INTEGRATION
___wasm_call_ctors();
#else
wasmExports['__wasm_call_ctors']();
#endif
#if RUNTIME_DEBUG
dbg('done __wasm_call_ctors');
#endif
#endif
<<< ATPOSTCTORS >>>
#if RUNTIME_DEBUG
dbg('done ATPOSTCTORS');
#endif
}
#if HAS_MAIN
function preMain() {
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
<<< ATMAINS >>>
}
#endif
#if EXIT_RUNTIME
function exitRuntime() {
#if RUNTIME_DEBUG
dbg('exitRuntime');
#endif
#if ASSERTIONS
assert(!runtimeExited);
#endif
#if ASYNCIFY == 1 && ASSERTIONS
Asyncify.state = Asyncify.State.Disabled;
#endif
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
{{{ runIfWorkerThread('return;') }}}
#if !STANDALONE_WASM
___funcs_on_exit();
#endif
<<< ATEXITS >>>
#if PTHREADS
PThread.terminateAllThreads();
#endif
runtimeExited = true;
}
#endif
function postRun() {
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
{{{ runIfWorkerThread('return;') }}}
#if expectToReceiveOnModule('postRun')
if (Module['postRun']) {
if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
while (Module['postRun'].length) {
addOnPostRun(Module['postRun'].shift());
}
}
#if ASSERTIONS
consumedModuleProp('postRun');
#endif
#endif
<<< ATPOSTRUNS >>>
}
function abort(what) {
#if expectToReceiveOnModule('onAbort')
Module['onAbort']?.(what);
#endif
what = 'Aborted(' + what + ')';
err(what);
ABORT = true;
#if ASSERTIONS == 0
what += '. Build with -sASSERTIONS for more info.';
#elif ASYNCIFY == 1
if (what.search(/RuntimeError: [Uu]nreachable/) >= 0) {
what += '. "unreachable" may be due to ASYNCIFY_STACK_SIZE not being large enough (try increasing it)';
}
#endif
#if WASM_EXCEPTIONS == 1
if (runtimeInitialized) {
___trap();
}
#endif
var e = new WebAssembly.RuntimeError(what);
#if MODULARIZE
readyPromiseReject?.(e);
#endif
throw e;
}
#if ASSERTIONS && !('$FS' in addedLibraryItems)
var FS = {
error() {
abort('Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM');
},
init() { FS.error() },
createDataFile() { FS.error() },
createPreloadedFile() { FS.error() },
createLazyFile() { FS.error() },
open() { FS.error() },
mkdev() { FS.error() },
registerDevice() { FS.error() },
analyzePath() { FS.error() },
ErrnoError() { FS.error() },
};
{{{
addAtModule(`
Module['FS_createDataFile'] = FS.createDataFile;
Module['FS_createPreloadedFile'] = FS.createPreloadedFile;
`);
}}}
#endif
#if ASSERTIONS
function createExportWrapper(name, nargs) {
return (...args) => {
assert(runtimeInitialized, `native function \`${name}\` called before runtime initialization`);
#if EXIT_RUNTIME
assert(!runtimeExited, `native function \`${name}\` called after runtime exit (use NO_EXIT_RUNTIME to keep it alive after main() exits)`);
#endif
var f = wasmExports[name];
assert(f, `exported native function \`${name}\` not found`);
assert(args.length <= nargs, `native function \`${name}\` called with ${args.length} args but expects ${nargs}`);
return f(...args);
};
}
#endif
#if ABORT_ON_WASM_EXCEPTIONS
var abortWrapperDepth = 0;
function makeAbortWrapper(original) {
return (...args) => {
if (ABORT) {
throw new Error('program has already aborted!');
}
abortWrapperDepth++;
try {
return original(...args);
} catch (e) {
if (
ABORT
|| abortWrapperDepth > 1
#if SUPPORT_LONGJMP == 'emscripten'
#if EXCEPTION_STACK_TRACES
|| e instanceof EmscriptenSjLj
#else
|| e === Infinity
#endif
#endif
|| e === 'unwind'
) {
throw e;
}
abort('unhandled exception: ' + [e, e.stack]);
}
finally {
abortWrapperDepth--;
}
}
}
function instrumentWasmExportsWithAbort(exports) {
var instExports = {};
for (var name in exports) {
var original = exports[name];
if (typeof original == 'function') {
instExports[name] = makeAbortWrapper(original);
} else {
instExports[name] = original;
}
}
return instExports;
}
function instrumentWasmTableWithAbort() {
var realGet = wasmTable.get;
var wrapperCache = {};
wasmTable.get = (i) => {
var func = realGet.call(wasmTable, {{{ toIndexType('i') }}});
var cached = wrapperCache[i];
if (!cached || cached.func !== func) {
cached = wrapperCache[i] = {
func,
wrapper: makeAbortWrapper(func)
}
}
return cached.wrapper;
};
}
#endif
#if !SOURCE_PHASE_IMPORTS && !WASM_ESM_INTEGRATION
var wasmBinaryFile;
#if WASM2JS && WASM != 2
function findWasmBinary(file) {}
function getBinarySync(file) {}
function getWasmBinary(file) {}
#else
function findWasmBinary() {
#if SINGLE_FILE && SINGLE_FILE_BINARY_ENCODE && !WASM2JS
return binaryDecode("<<< WASM_BINARY_DATA >>>");
#elif SINGLE_FILE
return base64Decode('<<< WASM_BINARY_DATA >>>');
#elif AUDIO_WORKLET || !EXPORT_ES6
return locateFile('{{{ WASM_BINARY_FILE }}}');
#else
#if ENVIRONMENT_MAY_BE_SHELL
if (ENVIRONMENT_IS_SHELL) {
return '{{{ WASM_BINARY_FILE }}}';
}
#endif
#if ENVIRONMENT_MAY_BE_AUDIO_WORKLET && !AUDIO_WORKLET
if (ENVIRONMENT_IS_AUDIO_WORKLET) {
return '{{{ WASM_BINARY_FILE }}}';
}
#endif
if (Module['locateFile']) {
return locateFile('{{{ WASM_BINARY_FILE }}}');
}
return new URL('{{{ WASM_BINARY_FILE }}}', import.meta.url).href;
#endif
}
function getBinarySync(file) {
#if SINGLE_FILE && SINGLE_FILE_BINARY_ENCODE
return file;
#else
#if SINGLE_FILE
if (ArrayBuffer.isView(file)) {
return file;
}
#endif
#if expectToReceiveOnModule('wasmBinary') || WASM2JS
if (file == wasmBinaryFile && wasmBinary) {
return new Uint8Array(wasmBinary);
}
#endif
if (readBinary) {
return readBinary(file);
}
#if WASM_ASYNC_COMPILATION
throw 'both async and sync fetching of the wasm failed';
#else
throw 'sync fetching of the wasm failed: you can preload it to Module["wasmBinary"] manually, or emcc.py will do that for you when generating HTML (but not JS)';
#endif
#endif
}
async function getWasmBinary(binaryFile) {
#if !SINGLE_FILE
if (!wasmBinary) {
try {
var response = await readAsync(binaryFile);
return new Uint8Array(response);
} catch {
}
}
#endif
return getBinarySync(binaryFile);
}
#endif
#if SPLIT_MODULE
{{{ makeModuleReceiveWithVar('loadSplitModule', undefined, 'instantiateSync') }}}
var splitModuleProxyHandler = {
get(target, moduleName, receiver) {
if (moduleName.startsWith('placeholder')) {
let secondaryFile;
if (moduleName == 'placeholder') {
secondaryFile = wasmBinaryFile.slice(0, -5) + '.deferred.wasm';
} else {
let moduleID = moduleName.split('.')[1];
secondaryFile = wasmBinaryFile.slice(0, -5) + '.' + moduleID + '.wasm';
}
return new Proxy({}, {
get(target, base, receiver) {
return (...args) => {
#if ASYNCIFY == 2
throw new Error('Placeholder function "' + base + '" should not be called when using JSPI.');
#else
#if RUNTIME_DEBUG
dbg(`placeholder function called: ${base}`);
#endif
var imports = {'primary': wasmRawExports};
loadSplitModule(secondaryFile, imports, base);
#if RUNTIME_DEBUG
dbg('instantiated deferred module, continuing');
#endif
#if RELOCATABLE
base = 1 + parseInt(base);
#endif
return wasmTable.get({{{ toIndexType('base') }}})(...args);
#endif
}
}
});
}
return target[moduleName];
}
};
#endif
#if SPLIT_MODULE || !WASM_ASYNC_COMPILATION
function instantiateSync(file, info) {
var module;
var binary = getBinarySync(file);
#if NODE_CODE_CACHING
if (ENVIRONMENT_IS_NODE) {
var v8 = require('node:v8');
var cachedCodeFile = '{{{ WASM_BINARY_FILE }}}.' + v8.cachedDataVersionTag() + '.cached';
cachedCodeFile = locateFile(cachedCodeFile);
var hasCached = fs.existsSync(cachedCodeFile);
if (hasCached) {
#if RUNTIME_DEBUG
dbg('NODE_CODE_CACHING: loading module');
#endif
try {
module = v8.deserialize(fs.readFileSync(cachedCodeFile));
} catch (e) {
err(`NODE_CODE_CACHING: failed to deserialize, bad cache file? (${cachedCodeFile})`);
hasCached = false;
}
}
}
module ||= new WebAssembly.Module(binary);
if (ENVIRONMENT_IS_NODE && !hasCached) {
#if RUNTIME_DEBUG
dbg('NODE_CODE_CACHING: saving module');
#endif
fs.writeFileSync(cachedCodeFile, v8.serialize(module));
}
#else
module = new WebAssembly.Module(binary);
#endif
var instance = new WebAssembly.Instance(module, info);
return [instance, module];
}
#endif
#if WASM_ASYNC_COMPILATION
async function instantiateArrayBuffer(binaryFile, imports) {
try {
var binary = await getWasmBinary(binaryFile);
var instance = await WebAssembly.instantiate(binary, imports);
return instance;
} catch (reason) {
err(`failed to asynchronously prepare wasm: ${reason}`);
#if WASM == 2
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
if (globalThis.location) {
#endif
var search = location.search;
if (search.indexOf('_rwasm=0') < 0) {
location.href += (search ? search + '&' : '?') + '_rwasm=0';
return new Promise(() => {});
}
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
}
#endif
#endif
#if ASSERTIONS
if (isFileURI(binaryFile)) {
err(`warning: Loading from a file URI (${binaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);
}
#endif
abort(reason);
}
}
async function instantiateAsync(binary, binaryFile, imports) {
#if !SINGLE_FILE
if (!binary
#if MIN_SAFARI_VERSION < 150000
&& WebAssembly.instantiateStreaming
#endif
#if ENVIRONMENT_MAY_BE_WEBVIEW
&& !isFileURI(binaryFile)
#endif
#if ENVIRONMENT_MAY_BE_NODE
&& !ENVIRONMENT_IS_NODE
#endif
#if ENVIRONMENT_MAY_BE_SHELL
&& !ENVIRONMENT_IS_SHELL
#endif
) {
try {
var response = fetch(binaryFile, {{{ makeModuleReceiveExpr('fetchSettings', "{ credentials: 'same-origin' }") }}});
var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
return instantiationResult;
} catch (reason) {
err(`wasm streaming compile failed: ${reason}`);
err('falling back to ArrayBuffer instantiation');
};
}
#endif
return instantiateArrayBuffer(binaryFile, imports);
}
#endif
#endif
#if !WASM_ESM_INTEGRATION
function getWasmImports() {
#if PTHREADS || WASM_WORKERS || (IMPORTED_MEMORY && MODULARIZE == 'instance')
assignWasmImports();
#endif
#if ASYNCIFY && (ASSERTIONS || ASYNCIFY == 2)
#if PTHREADS
if (!wasmImports.__instrumented) {
wasmImports.__instrumented = true;
Asyncify.instrumentWasmImports(wasmImports);
}
#else
Asyncify.instrumentWasmImports(wasmImports);
#endif
#endif
#if MAIN_MODULE || RELOCATABLE
var GOTProxyHandler = new Proxy(new Set({{{ JSON.stringify(Array.from(WEAK_IMPORTS)) }}}), GOTHandler);
#endif
var imports = {
#if MINIFY_WASM_IMPORTED_MODULES
'a': wasmImports,
#else
'env': wasmImports,
'{{{ WASI_MODULE_NAME }}}': wasmImports,
#endif
#if MAIN_MODULE || RELOCATABLE
'GOT.mem': GOTProxyHandler,
'GOT.func': GOTProxyHandler,
#endif
};
#if SPLIT_MODULE
imports = new Proxy(imports, splitModuleProxyHandler);
#endif
return imports;
}
{{{ asyncIf(WASM_ASYNC_COMPILATION) }}}function createWasm() {
function receiveInstance(instance, module) {
#if RUNTIME_DEBUG
dbg('receiveInstance')
#endif
wasmExports = instance.exports;
#if MAIN_MODULE
#if RELOCATABLE
wasmExports = relocateExports(wasmExports, {{{ GLOBAL_BASE }}});
#endif
var origExports = wasmExports;
#endif
#if SPLIT_MODULE
wasmRawExports = wasmExports;
#endif
#if ASYNCIFY
wasmExports = Asyncify.instrumentWasmExports(wasmExports);
#endif
#if MAIN_MODULE
mergeLibSymbols(wasmExports, 'main')
var metadata = getDylinkMetadata(module);
#if AUTOLOAD_DYLIBS
if (metadata.neededDynlibs) {
dynamicLibraries = metadata.neededDynlibs.concat(dynamicLibraries);
}
#endif
#endif
#if ABORT_ON_WASM_EXCEPTIONS
wasmExports = instrumentWasmExportsWithAbort(wasmExports);
#endif
#if MEMORY64 || CAN_ADDRESS_2GB
wasmExports = applySignatureConversions(wasmExports);
#endif
#if PTHREADS
#if MAIN_MODULE
registerTLSInit(wasmExports['_emscripten_tls_init'], instance.exports, metadata);
#else
registerTLSInit(wasmExports['_emscripten_tls_init']);
#endif
#endif
#if hasExportedSymbol('__wasm_apply_data_relocs')
__RELOC_FUNCS__.push(wasmExports['__wasm_apply_data_relocs']);
#endif
#if RUNTIME_DEBUG
dbg('assigning exports')
#endif
assignWasmExports(wasmExports);
#if MAIN_MODULE
updateGOT(origExports);
#endif
#if EXPORTED_RUNTIME_METHODS.includes('wasmExports')
Module['wasmExports'] = wasmExports;
#endif
#if MAIN_MODULE
#if '$LDSO' in addedLibraryItems
LDSO.init();
#endif
loadDylibs();
#elif RELOCATABLE
reportUndefinedSymbols();
#endif
#if ABORT_ON_WASM_EXCEPTIONS
instrumentWasmTableWithAbort();
#endif
#if !IMPORTED_MEMORY
updateMemoryViews();
#endif
#if PTHREADS || WASM_WORKERS
wasmModule = module;
#endif
#if WASM_ASYNC_COMPILATION && !MODULARIZE
removeRunDependency('wasm-instantiate');
#endif
return wasmExports;
}
#if WASM_ASYNC_COMPILATION && !MODULARIZE
addRunDependency('wasm-instantiate');
#endif
#if WASM_ASYNC_COMPILATION
#if ASSERTIONS
var trueModule = Module;
#endif
function receiveInstantiationResult(result) {
#if ASSERTIONS
assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?');
trueModule = null;
#endif
#if SHARED_MEMORY || MAIN_MODULE
return receiveInstance(result['instance'], result['module']);
#else
return receiveInstance(result['instance']);
#endif
}
#endif
var info = getWasmImports();
#if expectToReceiveOnModule('instantiateWasm')
if (Module['instantiateWasm']) {
return new Promise((resolve, reject) => {
#if ASSERTIONS
try {
#endif
Module['instantiateWasm'](info, (inst, mod) => {
resolve(receiveInstance(inst, mod));
});
#if ASSERTIONS
} catch(e) {
err(`Module.instantiateWasm callback failed with error: ${e}`);
reject(e);
}
#endif
});
}
#endif
#if PTHREADS || WASM_WORKERS
if ({{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) {
#if ASSERTIONS
assert(wasmModule, "wasmModule should have been received via postMessage");
#endif
var instance = new WebAssembly.Instance(wasmModule, getWasmImports());
return receiveInstance(instance, wasmModule);
}
#endif
#if SOURCE_PHASE_IMPORTS
var instance = await WebAssembly.instantiate(wasmModule, info);
var exports = receiveInstantiationResult({instance, 'module':wasmModule});
return exports;
#else
wasmBinaryFile ??= findWasmBinary();
#if WASM_ASYNC_COMPILATION
#if RUNTIME_DEBUG
dbg('asynchronously preparing wasm');
#endif
var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
var exports = receiveInstantiationResult(result);
return exports;
#else
var result = instantiateSync(wasmBinaryFile, info);
#if PTHREADS || MAIN_MODULE
return receiveInstance(result[0], result[1]);
#else
return receiveInstance(result[0]);
#endif
#endif
#endif
}
#endif
#if !WASM_BIGINT
var tempDouble;
var tempI64;
#endif
#if RETAIN_COMPILER_SETTINGS
var compilerSettings = {{{ JSON.stringify(makeRetainedCompilerSettings()) }}} ;
function getCompilerSetting(name) {
if (!(name in compilerSettings)) return 'invalid compiler setting: ' + name;
return compilerSettings[name];
}
#endif
#if MAIN_MODULE && ASYNCIFY
var asyncifyStubs = {};
#endif