| |
| |
| |
| |
| |
|
|
| |
|
|
| #if LOAD_SOURCE_MAP |
| #include "source_map_support.js" |
| #endif |
|
|
| #if ASSERTIONS |
| var calledRun; |
| #endif |
|
|
| #if STANDALONE_WASM && MAIN_READS_PARAMS |
| var mainArgs = undefined; |
| #endif |
|
|
| #if HAS_MAIN |
| #if MAIN_READS_PARAMS |
| {{{ asyncIf(ASYNCIFY == 2) }}}function callMain(args = []) { |
| #else |
| {{{ asyncIf(ASYNCIFY == 2) }}}function callMain() { |
| #endif |
| #if ASSERTIONS |
| #if '$runDependencies' in addedLibraryItems |
| assert(runDependencies == 0, 'cannot call main when async dependencies remain! (listen on Module["onRuntimeInitialized"])'); |
| #endif |
| assert(typeof onPreRuns === 'undefined' || onPreRuns.length == 0, 'cannot call main when preRun functions remain to be called'); |
| #endif |
|
|
| var entryFunction = {{{ getEntryFunction() }}}; |
|
|
| #if PROXY_TO_PTHREAD |
| |
| |
| {{{ runtimeKeepalivePush() }}} |
| #endif |
|
|
| #if MAIN_MODULE |
| |
| |
| if (!entryFunction) return; |
| #endif |
|
|
| #if MAIN_READS_PARAMS && STANDALONE_WASM |
| mainArgs = [thisProgram].concat(args) |
| #elif MAIN_READS_PARAMS |
| args.unshift(thisProgram); |
|
|
| var argc = args.length; |
| var argv = stackAlloc((argc + 1) * {{{ POINTER_SIZE }}}); |
| var argv_ptr = argv; |
| for (var arg of args) { |
| {{{ makeSetValue('argv_ptr', 0, 'stringToUTF8OnStack(arg)', '*') }}}; |
| argv_ptr += {{{ POINTER_SIZE }}}; |
| } |
| {{{ makeSetValue('argv_ptr', 0, 0, '*') }}}; |
| #else |
| var argc = 0; |
| var argv = 0; |
| #endif |
|
|
| try { |
| #if ABORT_ON_WASM_EXCEPTIONS |
| |
| abortWrapperDepth++; |
| #endif |
|
|
| #if STANDALONE_WASM |
| entryFunction(); |
| |
| |
| var ret = 0; |
| #else |
| var ret = entryFunction(argc, {{{ to64('argv') }}}); |
| #endif |
|
|
| #if ASYNCIFY == 2 && !PROXY_TO_PTHREAD |
| |
| |
| |
| ret = await ret; |
| #endif |
| |
| exitJS(ret, true); |
| return ret; |
| } catch (e) { |
| return handleException(e); |
| } |
| #if ABORT_ON_WASM_EXCEPTIONS |
| finally { |
| |
| abortWrapperDepth--; |
| } |
| #endif |
| } |
| #endif |
|
|
| #if STACK_OVERFLOW_CHECK |
| function stackCheckInit() { |
| |
| |
| |
| #if ASSERTIONS && PTHREADS |
| |
| assert(!ENVIRONMENT_IS_PTHREAD); |
| #endif |
| _emscripten_stack_init(); |
| |
| writeStackCookie(); |
| } |
| #endif |
|
|
| #if MAIN_READS_PARAMS |
| function run(args = arguments_) { |
| #else |
| function run() { |
| #endif |
|
|
| #if '$runDependencies' in addedLibraryItems |
| if (runDependencies > 0) { |
| #if RUNTIME_DEBUG |
| dbg('run() called, but dependencies remain, so not running'); |
| #endif |
| dependenciesFulfilled = run; |
| return; |
| } |
| #endif |
|
|
| #if PTHREADS || WASM_WORKERS |
| if ({{{ ENVIRONMENT_IS_WORKER_THREAD() }}}) { |
| #if MODULARIZE |
| readyPromiseResolve?.(Module); |
| #endif |
| initRuntime(); |
| return; |
| } |
| #endif |
|
|
| #if STACK_OVERFLOW_CHECK |
| stackCheckInit(); |
| #endif |
|
|
| preRun(); |
|
|
| #if '$runDependencies' in addedLibraryItems |
| |
| if (runDependencies > 0) { |
| #if RUNTIME_DEBUG |
| dbg('run() called, but dependencies remain, so not running'); |
| #endif |
| dependenciesFulfilled = run; |
| return; |
| } |
| #endif |
|
|
| {{{ asyncIf(ASYNCIFY == 2) }}}function doRun() { |
| |
| |
| #if ASSERTIONS |
| assert(!calledRun); |
| calledRun = true; |
| #endif |
| Module['calledRun'] = true; |
|
|
| if (ABORT) return; |
|
|
| initRuntime(); |
|
|
| #if HAS_MAIN |
| preMain(); |
| #endif |
|
|
| #if MODULARIZE |
| readyPromiseResolve?.(Module); |
| #endif |
| #if expectToReceiveOnModule('onRuntimeInitialized') |
| Module['onRuntimeInitialized']?.(); |
| #if ASSERTIONS |
| consumedModuleProp('onRuntimeInitialized'); |
| #endif |
| #endif |
|
|
| #if HAS_MAIN |
| var noInitialRun = {{{ makeModuleReceiveExpr('noInitialRun', !INVOKE_RUN) }}}; |
| #if MAIN_READS_PARAMS |
| if (!noInitialRun) {{{ awaitIf(ASYNCIFY == 2) }}}callMain(args); |
| #else |
| if (!noInitialRun) {{{ awaitIf(ASYNCIFY == 2) }}}callMain(); |
| #endif |
| #else |
| #if ASSERTIONS |
| assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]'); |
| #endif |
| #endif |
|
|
| postRun(); |
| } |
|
|
| #if expectToReceiveOnModule('setStatus') |
| if (Module['setStatus']) { |
| Module['setStatus']('Running...'); |
| setTimeout(() => { |
| setTimeout(() => Module['setStatus'](''), 1); |
| doRun(); |
| }, 1); |
| } else |
| #endif |
| { |
| doRun(); |
| } |
| #if STACK_OVERFLOW_CHECK |
| checkStackCookie(); |
| #endif |
| } |
|
|
| #if ASSERTIONS |
| #if EXIT_RUNTIME == 0 |
| function checkUnflushedContent() { |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| var oldOut = out; |
| var oldErr = err; |
| var has = false; |
| out = err = (x) => { |
| has = true; |
| } |
| try { |
| #if SYSCALLS_REQUIRE_FILESYSTEM == 0 && '$flush_NO_FILESYSTEM' in addedLibraryItems |
| flush_NO_FILESYSTEM(); |
| #elif WASMFS && hasExportedSymbol('wasmfs_flush') |
| |
| |
| _wasmfs_flush(); |
| #elif hasExportedSymbol('fflush') |
| _fflush(0); |
| #endif |
| #if '$FS' in addedLibraryItems && '$TTY' in addedLibraryItems |
| |
| for (var name of ['stdout', 'stderr']) { |
| var info = FS.analyzePath('/dev/' + name); |
| if (!info) return; |
| var stream = info.object; |
| var rdev = stream.rdev; |
| var tty = TTY.ttys[rdev]; |
| if (tty?.output?.length) { |
| has = true; |
| } |
| } |
| #endif |
| } catch(e) {} |
| out = oldOut; |
| err = oldErr; |
| if (has) { |
| warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the Emscripten FAQ), or make sure to emit a newline when you printf etc.'); |
| #if FILESYSTEM == 0 || SYSCALLS_REQUIRE_FILESYSTEM == 0 |
| warnOnce('(this may also be due to not including full filesystem support - try building with -sFORCE_FILESYSTEM)'); |
| #endif |
| } |
| } |
| #endif |
| #endif |
|
|
| var wasmExports; |
| #if SPLIT_MODULE |
| var wasmRawExports; |
| #endif |
|
|
| #if MODULARIZE == 'instance' |
| |
| |
| #if ASSERTIONS |
| var initCalled = false; |
| #endif |
| export default async function init(moduleArg = {}) { |
| #if ASSERTIONS |
| assert(!initCalled); |
| initCalled = true; |
| #endif |
| Object.assign(Module, moduleArg); |
| processModuleArgs(); |
| #if WASM_ESM_INTEGRATION |
| #if PTHREADS |
| registerTLSInit(__emscripten_tls_init); |
| #endif |
| updateMemoryViews(); |
| #if DYNCALLS && '$dynCalls' in addedLibraryItems |
|
|
| assignDynCalls(); |
| #endif |
| #else |
| wasmExports = await createWasm(); |
| #endif |
| run(); |
| } |
|
|
| #if ENVIRONMENT_MAY_BE_NODE |
| |
| if (ENVIRONMENT_IS_NODE |
| #if PTHREADS || WASM_WORKERS |
| && !{{{ ENVIRONMENT_IS_WORKER_THREAD() }}} |
| #endif |
| ) |
| { |
| const url = await import('node:url'); |
| const isMainModule = url.pathToFileURL(process.argv[1]).href === import.meta.url; |
| if (isMainModule) await init(); |
| } |
| #endif |
|
|
| #if ENVIRONMENT_MAY_BE_SHELL |
| if (ENVIRONMENT_IS_SHELL) { |
| |
| await init(); |
| } |
| #endif |
|
|
| #else |
|
|
| #if WASM_WORKERS || PTHREADS |
| if ({{{ ENVIRONMENT_IS_MAIN_THREAD() }}}) { |
| |
| |
| #endif |
|
|
| #if WASM_ASYNC_COMPILATION |
|
|
| #if MODULARIZE |
| |
| |
| wasmExports = await createWasm(); |
| #else |
| |
| |
| createWasm(); |
| #endif |
|
|
| #else |
| wasmExports = createWasm(); |
| #endif |
|
|
| run(); |
|
|
| #if WASM_WORKERS || PTHREADS |
| } |
| #endif |
|
|
| #endif |
|
|