├── README.md ├── functions.c ├── functions.js ├── functions.wasm ├── index.html └── script.js /README.md: -------------------------------------------------------------------------------- 1 | # C-Language-To-WASM 2 | Convert C Language code to web assembly using emscripten. 3 | 4 | Download emcc. 5 | https://emscripten.org/docs/getting_started/downloads.html 6 | 7 | Download git terminal from this url if you haven't installed it already. 8 | https://git-scm.com/downloads 9 | 10 | Use the following command to create the .wasm file. Discard the html if you don't need it. 11 | 12 | emcc functions.c -s WASM=1 -o functions.html 13 | -------------------------------------------------------------------------------- /functions.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | EMSCRIPTEN_KEEPALIVE 4 | float add(float x, float y) { 5 | return x + y; 6 | } -------------------------------------------------------------------------------- /functions.js: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Emscripten Authors. All rights reserved. 2 | // Emscripten is available under two separate licenses, the MIT license and the 3 | // University of Illinois/NCSA Open Source License. Both these licenses can be 4 | // found in the LICENSE file. 5 | 6 | // The Module object: Our interface to the outside world. We import 7 | // and export values on it. There are various ways Module can be used: 8 | // 1. Not defined. We create it here 9 | // 2. A function parameter, function(Module) { ..generated code.. } 10 | // 3. pre-run appended it, var Module = {}; ..generated code.. 11 | // 4. External script tag defines var Module. 12 | // We need to check if Module already exists (e.g. case 3 above). 13 | // Substitution will be replaced with actual code on later stage of the build, 14 | // this way Closure Compiler will not mangle it (e.g. case 4. above). 15 | // Note that if you want to run closure, and also to use Module 16 | // after the generated code, you will need to define var Module = {}; 17 | // before the code. Then that object will be used in the code, and you 18 | // can continue to use Module afterwards as well. 19 | var Module = typeof Module !== 'undefined' ? Module : {}; 20 | 21 | // --pre-jses are emitted after the Module integration code, so that they can 22 | // refer to Module (if they choose; they can also define Module) 23 | // {{PRE_JSES}} 24 | 25 | // Sometimes an existing Module object exists with properties 26 | // meant to overwrite the default module functionality. Here 27 | // we collect those properties and reapply _after_ we configure 28 | // the current environment's defaults to avoid having to be so 29 | // defensive during initialization. 30 | var moduleOverrides = {}; 31 | var key; 32 | for (key in Module) { 33 | if (Module.hasOwnProperty(key)) { 34 | moduleOverrides[key] = Module[key]; 35 | } 36 | } 37 | 38 | var arguments_ = []; 39 | var thisProgram = './this.program'; 40 | var quit_ = function(status, toThrow) { 41 | throw toThrow; 42 | }; 43 | 44 | // Determine the runtime environment we are in. You can customize this by 45 | // setting the ENVIRONMENT setting at compile time (see settings.js). 46 | 47 | var ENVIRONMENT_IS_WEB = false; 48 | var ENVIRONMENT_IS_WORKER = false; 49 | var ENVIRONMENT_IS_NODE = false; 50 | var ENVIRONMENT_HAS_NODE = false; 51 | var ENVIRONMENT_IS_SHELL = false; 52 | ENVIRONMENT_IS_WEB = typeof window === 'object'; 53 | ENVIRONMENT_IS_WORKER = typeof importScripts === 'function'; 54 | // A web environment like Electron.js can have Node enabled, so we must 55 | // distinguish between Node-enabled environments and Node environments per se. 56 | // This will allow the former to do things like mount NODEFS. 57 | // Extended check using process.versions fixes issue #8816. 58 | // (Also makes redundant the original check that 'require' is a function.) 59 | ENVIRONMENT_HAS_NODE = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string'; 60 | ENVIRONMENT_IS_NODE = ENVIRONMENT_HAS_NODE && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER; 61 | ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; 62 | 63 | if (Module['ENVIRONMENT']) { 64 | throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)'); 65 | } 66 | 67 | 68 | 69 | // `/` should be present at the end if `scriptDirectory` is not empty 70 | var scriptDirectory = ''; 71 | function locateFile(path) { 72 | if (Module['locateFile']) { 73 | return Module['locateFile'](path, scriptDirectory); 74 | } 75 | return scriptDirectory + path; 76 | } 77 | 78 | // Hooks that are implemented differently in different runtime environments. 79 | var read_, 80 | readAsync, 81 | readBinary, 82 | setWindowTitle; 83 | 84 | var nodeFS; 85 | var nodePath; 86 | 87 | if (ENVIRONMENT_IS_NODE) { 88 | scriptDirectory = __dirname + '/'; 89 | 90 | 91 | read_ = function shell_read(filename, binary) { 92 | if (!nodeFS) nodeFS = require('fs'); 93 | if (!nodePath) nodePath = require('path'); 94 | filename = nodePath['normalize'](filename); 95 | return nodeFS['readFileSync'](filename, binary ? null : 'utf8'); 96 | }; 97 | 98 | readBinary = function readBinary(filename) { 99 | var ret = read_(filename, true); 100 | if (!ret.buffer) { 101 | ret = new Uint8Array(ret); 102 | } 103 | assert(ret.buffer); 104 | return ret; 105 | }; 106 | 107 | 108 | 109 | 110 | if (process['argv'].length > 1) { 111 | thisProgram = process['argv'][1].replace(/\\/g, '/'); 112 | } 113 | 114 | arguments_ = process['argv'].slice(2); 115 | 116 | if (typeof module !== 'undefined') { 117 | module['exports'] = Module; 118 | } 119 | 120 | process['on']('uncaughtException', function(ex) { 121 | // suppress ExitStatus exceptions from showing an error 122 | if (!(ex instanceof ExitStatus)) { 123 | throw ex; 124 | } 125 | }); 126 | 127 | process['on']('unhandledRejection', abort); 128 | 129 | quit_ = function(status) { 130 | process['exit'](status); 131 | }; 132 | 133 | Module['inspect'] = function () { return '[Emscripten Module object]'; }; 134 | 135 | 136 | } else 137 | if (ENVIRONMENT_IS_SHELL) { 138 | 139 | 140 | if (typeof read != 'undefined') { 141 | read_ = function shell_read(f) { 142 | return read(f); 143 | }; 144 | } 145 | 146 | readBinary = function readBinary(f) { 147 | var data; 148 | if (typeof readbuffer === 'function') { 149 | return new Uint8Array(readbuffer(f)); 150 | } 151 | data = read(f, 'binary'); 152 | assert(typeof data === 'object'); 153 | return data; 154 | }; 155 | 156 | if (typeof scriptArgs != 'undefined') { 157 | arguments_ = scriptArgs; 158 | } else if (typeof arguments != 'undefined') { 159 | arguments_ = arguments; 160 | } 161 | 162 | if (typeof quit === 'function') { 163 | quit_ = function(status) { 164 | quit(status); 165 | }; 166 | } 167 | 168 | if (typeof print !== 'undefined') { 169 | // Prefer to use print/printErr where they exist, as they usually work better. 170 | if (typeof console === 'undefined') console = {}; 171 | console.log = print; 172 | console.warn = console.error = typeof printErr !== 'undefined' ? printErr : print; 173 | } 174 | } else 175 | 176 | // Note that this includes Node.js workers when relevant (pthreads is enabled). 177 | // Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and 178 | // ENVIRONMENT_HAS_NODE. 179 | if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { 180 | if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled 181 | scriptDirectory = self.location.href; 182 | } else if (document.currentScript) { // web 183 | scriptDirectory = document.currentScript.src; 184 | } 185 | // blob urls look like blob:http://site.com/etc/etc and we cannot infer anything from them. 186 | // otherwise, slice off the final part of the url to find the script directory. 187 | // if scriptDirectory does not contain a slash, lastIndexOf will return -1, 188 | // and scriptDirectory will correctly be replaced with an empty string. 189 | if (scriptDirectory.indexOf('blob:') !== 0) { 190 | scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf('/')+1); 191 | } else { 192 | scriptDirectory = ''; 193 | } 194 | 195 | 196 | // Differentiate the Web Worker from the Node Worker case, as reading must 197 | // be done differently. 198 | { 199 | 200 | 201 | read_ = function shell_read(url) { 202 | var xhr = new XMLHttpRequest(); 203 | xhr.open('GET', url, false); 204 | xhr.send(null); 205 | return xhr.responseText; 206 | }; 207 | 208 | if (ENVIRONMENT_IS_WORKER) { 209 | readBinary = function readBinary(url) { 210 | var xhr = new XMLHttpRequest(); 211 | xhr.open('GET', url, false); 212 | xhr.responseType = 'arraybuffer'; 213 | xhr.send(null); 214 | return new Uint8Array(xhr.response); 215 | }; 216 | } 217 | 218 | readAsync = function readAsync(url, onload, onerror) { 219 | var xhr = new XMLHttpRequest(); 220 | xhr.open('GET', url, true); 221 | xhr.responseType = 'arraybuffer'; 222 | xhr.onload = function xhr_onload() { 223 | if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0 224 | onload(xhr.response); 225 | return; 226 | } 227 | onerror(); 228 | }; 229 | xhr.onerror = onerror; 230 | xhr.send(null); 231 | }; 232 | 233 | 234 | 235 | 236 | } 237 | 238 | setWindowTitle = function(title) { document.title = title }; 239 | } else 240 | { 241 | throw new Error('environment detection error'); 242 | } 243 | 244 | 245 | // Set up the out() and err() hooks, which are how we can print to stdout or 246 | // stderr, respectively. 247 | var out = Module['print'] || console.log.bind(console); 248 | var err = Module['printErr'] || console.warn.bind(console); 249 | 250 | // Merge back in the overrides 251 | for (key in moduleOverrides) { 252 | if (moduleOverrides.hasOwnProperty(key)) { 253 | Module[key] = moduleOverrides[key]; 254 | } 255 | } 256 | // Free the object hierarchy contained in the overrides, this lets the GC 257 | // reclaim data used e.g. in memoryInitializerRequest, which is a large typed array. 258 | moduleOverrides = null; 259 | 260 | // Emit code to handle expected values on the Module object. This applies Module.x 261 | // to the proper local x. This has two benefits: first, we only emit it if it is 262 | // expected to arrive, and second, by using a local everywhere else that can be 263 | // minified. 264 | if (Module['arguments']) arguments_ = Module['arguments'];if (!Object.getOwnPropertyDescriptor(Module, 'arguments')) Object.defineProperty(Module, 'arguments', { configurable: true, get: function() { abort('Module.arguments has been replaced with plain arguments_') } }); 265 | if (Module['thisProgram']) thisProgram = Module['thisProgram'];if (!Object.getOwnPropertyDescriptor(Module, 'thisProgram')) Object.defineProperty(Module, 'thisProgram', { configurable: true, get: function() { abort('Module.thisProgram has been replaced with plain thisProgram') } }); 266 | if (Module['quit']) quit_ = Module['quit'];if (!Object.getOwnPropertyDescriptor(Module, 'quit')) Object.defineProperty(Module, 'quit', { configurable: true, get: function() { abort('Module.quit has been replaced with plain quit_') } }); 267 | 268 | // perform assertions in shell.js after we set up out() and err(), as otherwise if an assertion fails it cannot print the message 269 | // Assertions on removed incoming Module JS APIs. 270 | assert(typeof Module['memoryInitializerPrefixURL'] === 'undefined', 'Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead'); 271 | assert(typeof Module['pthreadMainPrefixURL'] === 'undefined', 'Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead'); 272 | assert(typeof Module['cdInitializerPrefixURL'] === 'undefined', 'Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead'); 273 | assert(typeof Module['filePackagePrefixURL'] === 'undefined', 'Module.filePackagePrefixURL option was removed, use Module.locateFile instead'); 274 | assert(typeof Module['read'] === 'undefined', 'Module.read option was removed (modify read_ in JS)'); 275 | assert(typeof Module['readAsync'] === 'undefined', 'Module.readAsync option was removed (modify readAsync in JS)'); 276 | assert(typeof Module['readBinary'] === 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)'); 277 | assert(typeof Module['setWindowTitle'] === 'undefined', 'Module.setWindowTitle option was removed (modify setWindowTitle in JS)'); 278 | if (!Object.getOwnPropertyDescriptor(Module, 'read')) Object.defineProperty(Module, 'read', { configurable: true, get: function() { abort('Module.read has been replaced with plain read_') } }); 279 | if (!Object.getOwnPropertyDescriptor(Module, 'readAsync')) Object.defineProperty(Module, 'readAsync', { configurable: true, get: function() { abort('Module.readAsync has been replaced with plain readAsync') } }); 280 | if (!Object.getOwnPropertyDescriptor(Module, 'readBinary')) Object.defineProperty(Module, 'readBinary', { configurable: true, get: function() { abort('Module.readBinary has been replaced with plain readBinary') } }); 281 | // TODO: add when SDL2 is fixed if (!Object.getOwnPropertyDescriptor(Module, 'setWindowTitle')) Object.defineProperty(Module, 'setWindowTitle', { configurable: true, get: function() { abort('Module.setWindowTitle has been replaced with plain setWindowTitle') } }); 282 | var IDBFS = 'IDBFS is no longer included by default; build with -lidbfs.js'; 283 | var PROXYFS = 'PROXYFS is no longer included by default; build with -lproxyfs.js'; 284 | var WORKERFS = 'WORKERFS is no longer included by default; build with -lworkerfs.js'; 285 | var NODEFS = 'NODEFS is no longer included by default; build with -lnodefs.js'; 286 | 287 | 288 | // TODO remove when SDL2 is fixed (also see above) 289 | 290 | 291 | 292 | // Copyright 2017 The Emscripten Authors. All rights reserved. 293 | // Emscripten is available under two separate licenses, the MIT license and the 294 | // University of Illinois/NCSA Open Source License. Both these licenses can be 295 | // found in the LICENSE file. 296 | 297 | // {{PREAMBLE_ADDITIONS}} 298 | 299 | var STACK_ALIGN = 16; 300 | 301 | // stack management, and other functionality that is provided by the compiled code, 302 | // should not be used before it is ready 303 | stackSave = stackRestore = stackAlloc = function() { 304 | abort('cannot use the stack before compiled code is ready to run, and has provided stack access'); 305 | }; 306 | 307 | function staticAlloc(size) { 308 | abort('staticAlloc is no longer available at runtime; instead, perform static allocations at compile time (using makeStaticAlloc)'); 309 | } 310 | 311 | function dynamicAlloc(size) { 312 | assert(DYNAMICTOP_PTR); 313 | var ret = HEAP32[DYNAMICTOP_PTR>>2]; 314 | var end = (ret + size + 15) & -16; 315 | if (end > _emscripten_get_heap_size()) { 316 | abort('failure to dynamicAlloc - memory growth etc. is not supported there, call malloc/sbrk directly'); 317 | } 318 | HEAP32[DYNAMICTOP_PTR>>2] = end; 319 | return ret; 320 | } 321 | 322 | function alignMemory(size, factor) { 323 | if (!factor) factor = STACK_ALIGN; // stack alignment (16-byte) by default 324 | return Math.ceil(size / factor) * factor; 325 | } 326 | 327 | function getNativeTypeSize(type) { 328 | switch (type) { 329 | case 'i1': case 'i8': return 1; 330 | case 'i16': return 2; 331 | case 'i32': return 4; 332 | case 'i64': return 8; 333 | case 'float': return 4; 334 | case 'double': return 8; 335 | default: { 336 | if (type[type.length-1] === '*') { 337 | return 4; // A pointer 338 | } else if (type[0] === 'i') { 339 | var bits = parseInt(type.substr(1)); 340 | assert(bits % 8 === 0, 'getNativeTypeSize invalid bits ' + bits + ', type ' + type); 341 | return bits / 8; 342 | } else { 343 | return 0; 344 | } 345 | } 346 | } 347 | } 348 | 349 | function warnOnce(text) { 350 | if (!warnOnce.shown) warnOnce.shown = {}; 351 | if (!warnOnce.shown[text]) { 352 | warnOnce.shown[text] = 1; 353 | err(text); 354 | } 355 | } 356 | 357 | var asm2wasmImports = { // special asm2wasm imports 358 | "f64-rem": function(x, y) { 359 | return x % y; 360 | }, 361 | "debugger": function() { 362 | debugger; 363 | } 364 | }; 365 | 366 | 367 | 368 | 369 | // Wraps a JS function as a wasm function with a given signature. 370 | function convertJsFunctionToWasm(func, sig) { 371 | 372 | // If the type reflection proposal is available, use the new 373 | // "WebAssembly.Function" constructor. 374 | // Otherwise, construct a minimal wasm module importing the JS function and 375 | // re-exporting it. 376 | if (typeof WebAssembly.Function === "function") { 377 | var typeNames = { 378 | 'i': 'i32', 379 | 'j': 'i64', 380 | 'f': 'f32', 381 | 'd': 'f64' 382 | }; 383 | var type = { 384 | parameters: [], 385 | results: sig[0] == 'v' ? [] : [typeNames[sig[0]]] 386 | }; 387 | for (var i = 1; i < sig.length; ++i) { 388 | type.parameters.push(typeNames[sig[i]]); 389 | } 390 | return new WebAssembly.Function(type, func); 391 | } 392 | 393 | // The module is static, with the exception of the type section, which is 394 | // generated based on the signature passed in. 395 | var typeSection = [ 396 | 0x01, // id: section, 397 | 0x00, // length: 0 (placeholder) 398 | 0x01, // count: 1 399 | 0x60, // form: func 400 | ]; 401 | var sigRet = sig.slice(0, 1); 402 | var sigParam = sig.slice(1); 403 | var typeCodes = { 404 | 'i': 0x7f, // i32 405 | 'j': 0x7e, // i64 406 | 'f': 0x7d, // f32 407 | 'd': 0x7c, // f64 408 | }; 409 | 410 | // Parameters, length + signatures 411 | typeSection.push(sigParam.length); 412 | for (var i = 0; i < sigParam.length; ++i) { 413 | typeSection.push(typeCodes[sigParam[i]]); 414 | } 415 | 416 | // Return values, length + signatures 417 | // With no multi-return in MVP, either 0 (void) or 1 (anything else) 418 | if (sigRet == 'v') { 419 | typeSection.push(0x00); 420 | } else { 421 | typeSection = typeSection.concat([0x01, typeCodes[sigRet]]); 422 | } 423 | 424 | // Write the overall length of the type section back into the section header 425 | // (excepting the 2 bytes for the section id and length) 426 | typeSection[1] = typeSection.length - 2; 427 | 428 | // Rest of the module is static 429 | var bytes = new Uint8Array([ 430 | 0x00, 0x61, 0x73, 0x6d, // magic ("\0asm") 431 | 0x01, 0x00, 0x00, 0x00, // version: 1 432 | ].concat(typeSection, [ 433 | 0x02, 0x07, // import section 434 | // (import "e" "f" (func 0 (type 0))) 435 | 0x01, 0x01, 0x65, 0x01, 0x66, 0x00, 0x00, 436 | 0x07, 0x05, // export section 437 | // (export "f" (func 0 (type 0))) 438 | 0x01, 0x01, 0x66, 0x00, 0x00, 439 | ])); 440 | 441 | // We can compile this wasm module synchronously because it is very small. 442 | // This accepts an import (at "e.f"), that it reroutes to an export (at "f") 443 | var module = new WebAssembly.Module(bytes); 444 | var instance = new WebAssembly.Instance(module, { 445 | 'e': { 446 | 'f': func 447 | } 448 | }); 449 | var wrappedFunc = instance.exports['f']; 450 | return wrappedFunc; 451 | } 452 | 453 | // Add a wasm function to the table. 454 | function addFunctionWasm(func, sig) { 455 | var table = wasmTable; 456 | var ret = table.length; 457 | 458 | // Grow the table 459 | try { 460 | table.grow(1); 461 | } catch (err) { 462 | if (!err instanceof RangeError) { 463 | throw err; 464 | } 465 | throw 'Unable to grow wasm table. Use a higher value for RESERVED_FUNCTION_POINTERS or set ALLOW_TABLE_GROWTH.'; 466 | } 467 | 468 | // Insert new element 469 | try { 470 | // Attempting to call this with JS function will cause of table.set() to fail 471 | table.set(ret, func); 472 | } catch (err) { 473 | if (!err instanceof TypeError) { 474 | throw err; 475 | } 476 | assert(typeof sig !== 'undefined', 'Missing signature argument to addFunction'); 477 | var wrapped = convertJsFunctionToWasm(func, sig); 478 | table.set(ret, wrapped); 479 | } 480 | 481 | return ret; 482 | } 483 | 484 | function removeFunctionWasm(index) { 485 | // TODO(sbc): Look into implementing this to allow re-using of table slots 486 | } 487 | 488 | // 'sig' parameter is required for the llvm backend but only when func is not 489 | // already a WebAssembly function. 490 | function addFunction(func, sig) { 491 | assert(typeof func !== 'undefined'); 492 | 493 | return addFunctionWasm(func, sig); 494 | } 495 | 496 | function removeFunction(index) { 497 | removeFunctionWasm(index); 498 | } 499 | 500 | var funcWrappers = {}; 501 | 502 | function getFuncWrapper(func, sig) { 503 | if (!func) return; // on null pointer, return undefined 504 | assert(sig); 505 | if (!funcWrappers[sig]) { 506 | funcWrappers[sig] = {}; 507 | } 508 | var sigCache = funcWrappers[sig]; 509 | if (!sigCache[func]) { 510 | // optimize away arguments usage in common cases 511 | if (sig.length === 1) { 512 | sigCache[func] = function dynCall_wrapper() { 513 | return dynCall(sig, func); 514 | }; 515 | } else if (sig.length === 2) { 516 | sigCache[func] = function dynCall_wrapper(arg) { 517 | return dynCall(sig, func, [arg]); 518 | }; 519 | } else { 520 | // general case 521 | sigCache[func] = function dynCall_wrapper() { 522 | return dynCall(sig, func, Array.prototype.slice.call(arguments)); 523 | }; 524 | } 525 | } 526 | return sigCache[func]; 527 | } 528 | 529 | 530 | function makeBigInt(low, high, unsigned) { 531 | return unsigned ? ((+((low>>>0)))+((+((high>>>0)))*4294967296.0)) : ((+((low>>>0)))+((+((high|0)))*4294967296.0)); 532 | } 533 | 534 | function dynCall(sig, ptr, args) { 535 | if (args && args.length) { 536 | assert(args.length == sig.length-1); 537 | assert(('dynCall_' + sig) in Module, 'bad function pointer type - no table for sig \'' + sig + '\''); 538 | return Module['dynCall_' + sig].apply(null, [ptr].concat(args)); 539 | } else { 540 | assert(sig.length == 1); 541 | assert(('dynCall_' + sig) in Module, 'bad function pointer type - no table for sig \'' + sig + '\''); 542 | return Module['dynCall_' + sig].call(null, ptr); 543 | } 544 | } 545 | 546 | var tempRet0 = 0; 547 | 548 | var setTempRet0 = function(value) { 549 | tempRet0 = value; 550 | }; 551 | 552 | var getTempRet0 = function() { 553 | return tempRet0; 554 | }; 555 | 556 | function getCompilerSetting(name) { 557 | throw 'You must build with -s RETAIN_COMPILER_SETTINGS=1 for getCompilerSetting or emscripten_get_compiler_setting to work'; 558 | } 559 | 560 | var Runtime = { 561 | // helpful errors 562 | getTempRet0: function() { abort('getTempRet0() is now a top-level function, after removing the Runtime object. Remove "Runtime."') }, 563 | staticAlloc: function() { abort('staticAlloc() is now a top-level function, after removing the Runtime object. Remove "Runtime."') }, 564 | stackAlloc: function() { abort('stackAlloc() is now a top-level function, after removing the Runtime object. Remove "Runtime."') }, 565 | }; 566 | 567 | // The address globals begin at. Very low in memory, for code size and optimization opportunities. 568 | // Above 0 is static memory, starting with globals. 569 | // Then the stack. 570 | // Then 'dynamic' memory for sbrk. 571 | var GLOBAL_BASE = 1024; 572 | 573 | 574 | 575 | 576 | // === Preamble library stuff === 577 | 578 | // Documentation for the public APIs defined in this file must be updated in: 579 | // site/source/docs/api_reference/preamble.js.rst 580 | // A prebuilt local version of the documentation is available at: 581 | // site/build/text/docs/api_reference/preamble.js.txt 582 | // You can also build docs locally as HTML or other formats in site/ 583 | // An online HTML version (which may be of a different version of Emscripten) 584 | // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html 585 | 586 | 587 | var wasmBinary;if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];if (!Object.getOwnPropertyDescriptor(Module, 'wasmBinary')) Object.defineProperty(Module, 'wasmBinary', { configurable: true, get: function() { abort('Module.wasmBinary has been replaced with plain wasmBinary') } }); 588 | var noExitRuntime;if (Module['noExitRuntime']) noExitRuntime = Module['noExitRuntime'];if (!Object.getOwnPropertyDescriptor(Module, 'noExitRuntime')) Object.defineProperty(Module, 'noExitRuntime', { configurable: true, get: function() { abort('Module.noExitRuntime has been replaced with plain noExitRuntime') } }); 589 | 590 | 591 | if (typeof WebAssembly !== 'object') { 592 | abort('No WebAssembly support found. Build with -s WASM=0 to target JavaScript instead.'); 593 | } 594 | 595 | 596 | // In MINIMAL_RUNTIME, setValue() and getValue() are only available when building with safe heap enabled, for heap safety checking. 597 | // In traditional runtime, setValue() and getValue() are always available (although their use is highly discouraged due to perf penalties) 598 | 599 | /** @type {function(number, number, string, boolean=)} */ 600 | function setValue(ptr, value, type, noSafe) { 601 | type = type || 'i8'; 602 | if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit 603 | switch(type) { 604 | case 'i1': HEAP8[((ptr)>>0)]=value; break; 605 | case 'i8': HEAP8[((ptr)>>0)]=value; break; 606 | case 'i16': HEAP16[((ptr)>>1)]=value; break; 607 | case 'i32': HEAP32[((ptr)>>2)]=value; break; 608 | case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math_abs(tempDouble))) >= 1.0 ? (tempDouble > 0.0 ? ((Math_min((+(Math_floor((tempDouble)/4294967296.0))), 4294967295.0))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/4294967296.0)))))>>>0) : 0)],HEAP32[((ptr)>>2)]=tempI64[0],HEAP32[(((ptr)+(4))>>2)]=tempI64[1]); break; 609 | case 'float': HEAPF32[((ptr)>>2)]=value; break; 610 | case 'double': HEAPF64[((ptr)>>3)]=value; break; 611 | default: abort('invalid type for setValue: ' + type); 612 | } 613 | } 614 | 615 | /** @type {function(number, string, boolean=)} */ 616 | function getValue(ptr, type, noSafe) { 617 | type = type || 'i8'; 618 | if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit 619 | switch(type) { 620 | case 'i1': return HEAP8[((ptr)>>0)]; 621 | case 'i8': return HEAP8[((ptr)>>0)]; 622 | case 'i16': return HEAP16[((ptr)>>1)]; 623 | case 'i32': return HEAP32[((ptr)>>2)]; 624 | case 'i64': return HEAP32[((ptr)>>2)]; 625 | case 'float': return HEAPF32[((ptr)>>2)]; 626 | case 'double': return HEAPF64[((ptr)>>3)]; 627 | default: abort('invalid type for getValue: ' + type); 628 | } 629 | return null; 630 | } 631 | 632 | 633 | 634 | 635 | 636 | // Wasm globals 637 | 638 | var wasmMemory; 639 | 640 | // In fastcomp asm.js, we don't need a wasm Table at all. 641 | // In the wasm backend, we polyfill the WebAssembly object, 642 | // so this creates a (non-native-wasm) table for us. 643 | var wasmTable = new WebAssembly.Table({ 644 | 'initial': 1, 645 | 'maximum': 1 + 0, 646 | 'element': 'anyfunc' 647 | }); 648 | 649 | 650 | //======================================== 651 | // Runtime essentials 652 | //======================================== 653 | 654 | // whether we are quitting the application. no code should run after this. 655 | // set in exit() and abort() 656 | var ABORT = false; 657 | 658 | // set by exit() and abort(). Passed to 'onExit' handler. 659 | // NOTE: This is also used as the process return code code in shell environments 660 | // but only when noExitRuntime is false. 661 | var EXITSTATUS = 0; 662 | 663 | /** @type {function(*, string=)} */ 664 | function assert(condition, text) { 665 | if (!condition) { 666 | abort('Assertion failed: ' + text); 667 | } 668 | } 669 | 670 | // Returns the C function with a specified identifier (for C++, you need to do manual name mangling) 671 | function getCFunc(ident) { 672 | var func = Module['_' + ident]; // closure exported function 673 | assert(func, 'Cannot call unknown function ' + ident + ', make sure it is exported'); 674 | return func; 675 | } 676 | 677 | // C calling interface. 678 | function ccall(ident, returnType, argTypes, args, opts) { 679 | // For fast lookup of conversion functions 680 | var toC = { 681 | 'string': function(str) { 682 | var ret = 0; 683 | if (str !== null && str !== undefined && str !== 0) { // null string 684 | // at most 4 bytes per UTF-8 code point, +1 for the trailing '\0' 685 | var len = (str.length << 2) + 1; 686 | ret = stackAlloc(len); 687 | stringToUTF8(str, ret, len); 688 | } 689 | return ret; 690 | }, 691 | 'array': function(arr) { 692 | var ret = stackAlloc(arr.length); 693 | writeArrayToMemory(arr, ret); 694 | return ret; 695 | } 696 | }; 697 | 698 | function convertReturnValue(ret) { 699 | if (returnType === 'string') return UTF8ToString(ret); 700 | if (returnType === 'boolean') return Boolean(ret); 701 | return ret; 702 | } 703 | 704 | var func = getCFunc(ident); 705 | var cArgs = []; 706 | var stack = 0; 707 | assert(returnType !== 'array', 'Return type should not be "array".'); 708 | if (args) { 709 | for (var i = 0; i < args.length; i++) { 710 | var converter = toC[argTypes[i]]; 711 | if (converter) { 712 | if (stack === 0) stack = stackSave(); 713 | cArgs[i] = converter(args[i]); 714 | } else { 715 | cArgs[i] = args[i]; 716 | } 717 | } 718 | } 719 | var ret = func.apply(null, cArgs); 720 | 721 | ret = convertReturnValue(ret); 722 | if (stack !== 0) stackRestore(stack); 723 | return ret; 724 | } 725 | 726 | function cwrap(ident, returnType, argTypes, opts) { 727 | return function() { 728 | return ccall(ident, returnType, argTypes, arguments, opts); 729 | } 730 | } 731 | 732 | var ALLOC_NORMAL = 0; // Tries to use _malloc() 733 | var ALLOC_STACK = 1; // Lives for the duration of the current function call 734 | var ALLOC_DYNAMIC = 2; // Cannot be freed except through sbrk 735 | var ALLOC_NONE = 3; // Do not allocate 736 | 737 | // allocate(): This is for internal use. You can use it yourself as well, but the interface 738 | // is a little tricky (see docs right below). The reason is that it is optimized 739 | // for multiple syntaxes to save space in generated code. So you should 740 | // normally not use allocate(), and instead allocate memory using _malloc(), 741 | // initialize it with setValue(), and so forth. 742 | // @slab: An array of data, or a number. If a number, then the size of the block to allocate, 743 | // in *bytes* (note that this is sometimes confusing: the next parameter does not 744 | // affect this!) 745 | // @types: Either an array of types, one for each byte (or 0 if no type at that position), 746 | // or a single type which is used for the entire block. This only matters if there 747 | // is initial data - if @slab is a number, then this does not matter at all and is 748 | // ignored. 749 | // @allocator: How to allocate memory, see ALLOC_* 750 | /** @type {function((TypedArray|Array|number), string, number, number=)} */ 751 | function allocate(slab, types, allocator, ptr) { 752 | var zeroinit, size; 753 | if (typeof slab === 'number') { 754 | zeroinit = true; 755 | size = slab; 756 | } else { 757 | zeroinit = false; 758 | size = slab.length; 759 | } 760 | 761 | var singleType = typeof types === 'string' ? types : null; 762 | 763 | var ret; 764 | if (allocator == ALLOC_NONE) { 765 | ret = ptr; 766 | } else { 767 | ret = [_malloc, 768 | stackAlloc, 769 | dynamicAlloc][allocator](Math.max(size, singleType ? 1 : types.length)); 770 | } 771 | 772 | if (zeroinit) { 773 | var stop; 774 | ptr = ret; 775 | assert((ret & 3) == 0); 776 | stop = ret + (size & ~3); 777 | for (; ptr < stop; ptr += 4) { 778 | HEAP32[((ptr)>>2)]=0; 779 | } 780 | stop = ret + size; 781 | while (ptr < stop) { 782 | HEAP8[((ptr++)>>0)]=0; 783 | } 784 | return ret; 785 | } 786 | 787 | if (singleType === 'i8') { 788 | if (slab.subarray || slab.slice) { 789 | HEAPU8.set(/** @type {!Uint8Array} */ (slab), ret); 790 | } else { 791 | HEAPU8.set(new Uint8Array(slab), ret); 792 | } 793 | return ret; 794 | } 795 | 796 | var i = 0, type, typeSize, previousType; 797 | while (i < size) { 798 | var curr = slab[i]; 799 | 800 | type = singleType || types[i]; 801 | if (type === 0) { 802 | i++; 803 | continue; 804 | } 805 | assert(type, 'Must know what type to store in allocate!'); 806 | 807 | if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later 808 | 809 | setValue(ret+i, curr, type); 810 | 811 | // no need to look up size unless type changes, so cache it 812 | if (previousType !== type) { 813 | typeSize = getNativeTypeSize(type); 814 | previousType = type; 815 | } 816 | i += typeSize; 817 | } 818 | 819 | return ret; 820 | } 821 | 822 | // Allocate memory during any stage of startup - static memory early on, dynamic memory later, malloc when ready 823 | function getMemory(size) { 824 | if (!runtimeInitialized) return dynamicAlloc(size); 825 | return _malloc(size); 826 | } 827 | 828 | 829 | 830 | 831 | /** @type {function(number, number=)} */ 832 | function Pointer_stringify(ptr, length) { 833 | abort("this function has been removed - you should use UTF8ToString(ptr, maxBytesToRead) instead!"); 834 | } 835 | 836 | // Given a pointer 'ptr' to a null-terminated ASCII-encoded string in the emscripten HEAP, returns 837 | // a copy of that string as a Javascript String object. 838 | 839 | function AsciiToString(ptr) { 840 | var str = ''; 841 | while (1) { 842 | var ch = HEAPU8[((ptr++)>>0)]; 843 | if (!ch) return str; 844 | str += String.fromCharCode(ch); 845 | } 846 | } 847 | 848 | // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr', 849 | // null-terminated and encoded in ASCII form. The copy will require at most str.length+1 bytes of space in the HEAP. 850 | 851 | function stringToAscii(str, outPtr) { 852 | return writeAsciiToMemory(str, outPtr, false); 853 | } 854 | 855 | 856 | // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the given array that contains uint8 values, returns 857 | // a copy of that string as a Javascript String object. 858 | 859 | var UTF8Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf8') : undefined; 860 | 861 | /** 862 | * @param {number} idx 863 | * @param {number=} maxBytesToRead 864 | * @return {string} 865 | */ 866 | function UTF8ArrayToString(u8Array, idx, maxBytesToRead) { 867 | var endIdx = idx + maxBytesToRead; 868 | var endPtr = idx; 869 | // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself. 870 | // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage. 871 | // (As a tiny code save trick, compare endPtr against endIdx using a negation, so that undefined means Infinity) 872 | while (u8Array[endPtr] && !(endPtr >= endIdx)) ++endPtr; 873 | 874 | if (endPtr - idx > 16 && u8Array.subarray && UTF8Decoder) { 875 | return UTF8Decoder.decode(u8Array.subarray(idx, endPtr)); 876 | } else { 877 | var str = ''; 878 | // If building with TextDecoder, we have already computed the string length above, so test loop end condition against that 879 | while (idx < endPtr) { 880 | // For UTF8 byte structure, see: 881 | // http://en.wikipedia.org/wiki/UTF-8#Description 882 | // https://www.ietf.org/rfc/rfc2279.txt 883 | // https://tools.ietf.org/html/rfc3629 884 | var u0 = u8Array[idx++]; 885 | if (!(u0 & 0x80)) { str += String.fromCharCode(u0); continue; } 886 | var u1 = u8Array[idx++] & 63; 887 | if ((u0 & 0xE0) == 0xC0) { str += String.fromCharCode(((u0 & 31) << 6) | u1); continue; } 888 | var u2 = u8Array[idx++] & 63; 889 | if ((u0 & 0xF0) == 0xE0) { 890 | u0 = ((u0 & 15) << 12) | (u1 << 6) | u2; 891 | } else { 892 | if ((u0 & 0xF8) != 0xF0) warnOnce('Invalid UTF-8 leading byte 0x' + u0.toString(16) + ' encountered when deserializing a UTF-8 string on the asm.js/wasm heap to a JS string!'); 893 | u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (u8Array[idx++] & 63); 894 | } 895 | 896 | if (u0 < 0x10000) { 897 | str += String.fromCharCode(u0); 898 | } else { 899 | var ch = u0 - 0x10000; 900 | str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF)); 901 | } 902 | } 903 | } 904 | return str; 905 | } 906 | 907 | // Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the emscripten HEAP, returns a 908 | // copy of that string as a Javascript String object. 909 | // maxBytesToRead: an optional length that specifies the maximum number of bytes to read. You can omit 910 | // this parameter to scan the string until the first \0 byte. If maxBytesToRead is 911 | // passed, and the string at [ptr, ptr+maxBytesToReadr[ contains a null byte in the 912 | // middle, then the string will cut short at that byte index (i.e. maxBytesToRead will 913 | // not produce a string of exact length [ptr, ptr+maxBytesToRead[) 914 | // N.B. mixing frequent uses of UTF8ToString() with and without maxBytesToRead may 915 | // throw JS JIT optimizations off, so it is worth to consider consistently using one 916 | // style or the other. 917 | /** 918 | * @param {number} ptr 919 | * @param {number=} maxBytesToRead 920 | * @return {string} 921 | */ 922 | function UTF8ToString(ptr, maxBytesToRead) { 923 | return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ''; 924 | } 925 | 926 | // Copies the given Javascript String object 'str' to the given byte array at address 'outIdx', 927 | // encoded in UTF8 form and null-terminated. The copy will require at most str.length*4+1 bytes of space in the HEAP. 928 | // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write. 929 | // Parameters: 930 | // str: the Javascript string to copy. 931 | // outU8Array: the array to copy to. Each index in this array is assumed to be one 8-byte element. 932 | // outIdx: The starting offset in the array to begin the copying. 933 | // maxBytesToWrite: The maximum number of bytes this function can write to the array. 934 | // This count should include the null terminator, 935 | // i.e. if maxBytesToWrite=1, only the null terminator will be written and nothing else. 936 | // maxBytesToWrite=0 does not write any bytes to the output, not even the null terminator. 937 | // Returns the number of bytes written, EXCLUDING the null terminator. 938 | 939 | function stringToUTF8Array(str, outU8Array, outIdx, maxBytesToWrite) { 940 | if (!(maxBytesToWrite > 0)) // Parameter maxBytesToWrite is not optional. Negative values, 0, null, undefined and false each don't write out any bytes. 941 | return 0; 942 | 943 | var startIdx = outIdx; 944 | var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator. 945 | for (var i = 0; i < str.length; ++i) { 946 | // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8. 947 | // See http://unicode.org/faq/utf_bom.html#utf16-3 948 | // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description and https://www.ietf.org/rfc/rfc2279.txt and https://tools.ietf.org/html/rfc3629 949 | var u = str.charCodeAt(i); // possibly a lead surrogate 950 | if (u >= 0xD800 && u <= 0xDFFF) { 951 | var u1 = str.charCodeAt(++i); 952 | u = 0x10000 + ((u & 0x3FF) << 10) | (u1 & 0x3FF); 953 | } 954 | if (u <= 0x7F) { 955 | if (outIdx >= endIdx) break; 956 | outU8Array[outIdx++] = u; 957 | } else if (u <= 0x7FF) { 958 | if (outIdx + 1 >= endIdx) break; 959 | outU8Array[outIdx++] = 0xC0 | (u >> 6); 960 | outU8Array[outIdx++] = 0x80 | (u & 63); 961 | } else if (u <= 0xFFFF) { 962 | if (outIdx + 2 >= endIdx) break; 963 | outU8Array[outIdx++] = 0xE0 | (u >> 12); 964 | outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63); 965 | outU8Array[outIdx++] = 0x80 | (u & 63); 966 | } else { 967 | if (outIdx + 3 >= endIdx) break; 968 | if (u >= 0x200000) warnOnce('Invalid Unicode code point 0x' + u.toString(16) + ' encountered when serializing a JS string to an UTF-8 string on the asm.js/wasm heap! (Valid unicode code points should be in range 0-0x1FFFFF).'); 969 | outU8Array[outIdx++] = 0xF0 | (u >> 18); 970 | outU8Array[outIdx++] = 0x80 | ((u >> 12) & 63); 971 | outU8Array[outIdx++] = 0x80 | ((u >> 6) & 63); 972 | outU8Array[outIdx++] = 0x80 | (u & 63); 973 | } 974 | } 975 | // Null-terminate the pointer to the buffer. 976 | outU8Array[outIdx] = 0; 977 | return outIdx - startIdx; 978 | } 979 | 980 | // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr', 981 | // null-terminated and encoded in UTF8 form. The copy will require at most str.length*4+1 bytes of space in the HEAP. 982 | // Use the function lengthBytesUTF8 to compute the exact number of bytes (excluding null terminator) that this function will write. 983 | // Returns the number of bytes written, EXCLUDING the null terminator. 984 | 985 | function stringToUTF8(str, outPtr, maxBytesToWrite) { 986 | assert(typeof maxBytesToWrite == 'number', 'stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!'); 987 | return stringToUTF8Array(str, HEAPU8,outPtr, maxBytesToWrite); 988 | } 989 | 990 | // Returns the number of bytes the given Javascript string takes if encoded as a UTF8 byte array, EXCLUDING the null terminator byte. 991 | function lengthBytesUTF8(str) { 992 | var len = 0; 993 | for (var i = 0; i < str.length; ++i) { 994 | // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! So decode UTF16->UTF32->UTF8. 995 | // See http://unicode.org/faq/utf_bom.html#utf16-3 996 | var u = str.charCodeAt(i); // possibly a lead surrogate 997 | if (u >= 0xD800 && u <= 0xDFFF) u = 0x10000 + ((u & 0x3FF) << 10) | (str.charCodeAt(++i) & 0x3FF); 998 | if (u <= 0x7F) ++len; 999 | else if (u <= 0x7FF) len += 2; 1000 | else if (u <= 0xFFFF) len += 3; 1001 | else len += 4; 1002 | } 1003 | return len; 1004 | } 1005 | 1006 | 1007 | // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns 1008 | // a copy of that string as a Javascript String object. 1009 | 1010 | var UTF16Decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined; 1011 | function UTF16ToString(ptr) { 1012 | assert(ptr % 2 == 0, 'Pointer passed to UTF16ToString must be aligned to two bytes!'); 1013 | var endPtr = ptr; 1014 | // TextDecoder needs to know the byte length in advance, it doesn't stop on null terminator by itself. 1015 | // Also, use the length info to avoid running tiny strings through TextDecoder, since .subarray() allocates garbage. 1016 | var idx = endPtr >> 1; 1017 | while (HEAP16[idx]) ++idx; 1018 | endPtr = idx << 1; 1019 | 1020 | if (endPtr - ptr > 32 && UTF16Decoder) { 1021 | return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)); 1022 | } else { 1023 | var i = 0; 1024 | 1025 | var str = ''; 1026 | while (1) { 1027 | var codeUnit = HEAP16[(((ptr)+(i*2))>>1)]; 1028 | if (codeUnit == 0) return str; 1029 | ++i; 1030 | // fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through. 1031 | str += String.fromCharCode(codeUnit); 1032 | } 1033 | } 1034 | } 1035 | 1036 | // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr', 1037 | // null-terminated and encoded in UTF16 form. The copy will require at most str.length*4+2 bytes of space in the HEAP. 1038 | // Use the function lengthBytesUTF16() to compute the exact number of bytes (excluding null terminator) that this function will write. 1039 | // Parameters: 1040 | // str: the Javascript string to copy. 1041 | // outPtr: Byte address in Emscripten HEAP where to write the string to. 1042 | // maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null 1043 | // terminator, i.e. if maxBytesToWrite=2, only the null terminator will be written and nothing else. 1044 | // maxBytesToWrite<2 does not write any bytes to the output, not even the null terminator. 1045 | // Returns the number of bytes written, EXCLUDING the null terminator. 1046 | 1047 | function stringToUTF16(str, outPtr, maxBytesToWrite) { 1048 | assert(outPtr % 2 == 0, 'Pointer passed to stringToUTF16 must be aligned to two bytes!'); 1049 | assert(typeof maxBytesToWrite == 'number', 'stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!'); 1050 | // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed. 1051 | if (maxBytesToWrite === undefined) { 1052 | maxBytesToWrite = 0x7FFFFFFF; 1053 | } 1054 | if (maxBytesToWrite < 2) return 0; 1055 | maxBytesToWrite -= 2; // Null terminator. 1056 | var startPtr = outPtr; 1057 | var numCharsToWrite = (maxBytesToWrite < str.length*2) ? (maxBytesToWrite / 2) : str.length; 1058 | for (var i = 0; i < numCharsToWrite; ++i) { 1059 | // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP. 1060 | var codeUnit = str.charCodeAt(i); // possibly a lead surrogate 1061 | HEAP16[((outPtr)>>1)]=codeUnit; 1062 | outPtr += 2; 1063 | } 1064 | // Null-terminate the pointer to the HEAP. 1065 | HEAP16[((outPtr)>>1)]=0; 1066 | return outPtr - startPtr; 1067 | } 1068 | 1069 | // Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte. 1070 | 1071 | function lengthBytesUTF16(str) { 1072 | return str.length*2; 1073 | } 1074 | 1075 | function UTF32ToString(ptr) { 1076 | assert(ptr % 4 == 0, 'Pointer passed to UTF32ToString must be aligned to four bytes!'); 1077 | var i = 0; 1078 | 1079 | var str = ''; 1080 | while (1) { 1081 | var utf32 = HEAP32[(((ptr)+(i*4))>>2)]; 1082 | if (utf32 == 0) 1083 | return str; 1084 | ++i; 1085 | // Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing. 1086 | // See http://unicode.org/faq/utf_bom.html#utf16-3 1087 | if (utf32 >= 0x10000) { 1088 | var ch = utf32 - 0x10000; 1089 | str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF)); 1090 | } else { 1091 | str += String.fromCharCode(utf32); 1092 | } 1093 | } 1094 | } 1095 | 1096 | // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr', 1097 | // null-terminated and encoded in UTF32 form. The copy will require at most str.length*4+4 bytes of space in the HEAP. 1098 | // Use the function lengthBytesUTF32() to compute the exact number of bytes (excluding null terminator) that this function will write. 1099 | // Parameters: 1100 | // str: the Javascript string to copy. 1101 | // outPtr: Byte address in Emscripten HEAP where to write the string to. 1102 | // maxBytesToWrite: The maximum number of bytes this function can write to the array. This count should include the null 1103 | // terminator, i.e. if maxBytesToWrite=4, only the null terminator will be written and nothing else. 1104 | // maxBytesToWrite<4 does not write any bytes to the output, not even the null terminator. 1105 | // Returns the number of bytes written, EXCLUDING the null terminator. 1106 | 1107 | function stringToUTF32(str, outPtr, maxBytesToWrite) { 1108 | assert(outPtr % 4 == 0, 'Pointer passed to stringToUTF32 must be aligned to four bytes!'); 1109 | assert(typeof maxBytesToWrite == 'number', 'stringToUTF32(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!'); 1110 | // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed. 1111 | if (maxBytesToWrite === undefined) { 1112 | maxBytesToWrite = 0x7FFFFFFF; 1113 | } 1114 | if (maxBytesToWrite < 4) return 0; 1115 | var startPtr = outPtr; 1116 | var endPtr = startPtr + maxBytesToWrite - 4; 1117 | for (var i = 0; i < str.length; ++i) { 1118 | // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap. 1119 | // See http://unicode.org/faq/utf_bom.html#utf16-3 1120 | var codeUnit = str.charCodeAt(i); // possibly a lead surrogate 1121 | if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) { 1122 | var trailSurrogate = str.charCodeAt(++i); 1123 | codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF); 1124 | } 1125 | HEAP32[((outPtr)>>2)]=codeUnit; 1126 | outPtr += 4; 1127 | if (outPtr + 4 > endPtr) break; 1128 | } 1129 | // Null-terminate the pointer to the HEAP. 1130 | HEAP32[((outPtr)>>2)]=0; 1131 | return outPtr - startPtr; 1132 | } 1133 | 1134 | // Returns the number of bytes the given Javascript string takes if encoded as a UTF16 byte array, EXCLUDING the null terminator byte. 1135 | 1136 | function lengthBytesUTF32(str) { 1137 | var len = 0; 1138 | for (var i = 0; i < str.length; ++i) { 1139 | // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap. 1140 | // See http://unicode.org/faq/utf_bom.html#utf16-3 1141 | var codeUnit = str.charCodeAt(i); 1142 | if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) ++i; // possibly a lead surrogate, so skip over the tail surrogate. 1143 | len += 4; 1144 | } 1145 | 1146 | return len; 1147 | } 1148 | 1149 | // Allocate heap space for a JS string, and write it there. 1150 | // It is the responsibility of the caller to free() that memory. 1151 | function allocateUTF8(str) { 1152 | var size = lengthBytesUTF8(str) + 1; 1153 | var ret = _malloc(size); 1154 | if (ret) stringToUTF8Array(str, HEAP8, ret, size); 1155 | return ret; 1156 | } 1157 | 1158 | // Allocate stack space for a JS string, and write it there. 1159 | function allocateUTF8OnStack(str) { 1160 | var size = lengthBytesUTF8(str) + 1; 1161 | var ret = stackAlloc(size); 1162 | stringToUTF8Array(str, HEAP8, ret, size); 1163 | return ret; 1164 | } 1165 | 1166 | // Deprecated: This function should not be called because it is unsafe and does not provide 1167 | // a maximum length limit of how many bytes it is allowed to write. Prefer calling the 1168 | // function stringToUTF8Array() instead, which takes in a maximum length that can be used 1169 | // to be secure from out of bounds writes. 1170 | /** @deprecated */ 1171 | function writeStringToMemory(string, buffer, dontAddNull) { 1172 | warnOnce('writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!'); 1173 | 1174 | var /** @type {number} */ lastChar, /** @type {number} */ end; 1175 | if (dontAddNull) { 1176 | // stringToUTF8Array always appends null. If we don't want to do that, remember the 1177 | // character that existed at the location where the null will be placed, and restore 1178 | // that after the write (below). 1179 | end = buffer + lengthBytesUTF8(string); 1180 | lastChar = HEAP8[end]; 1181 | } 1182 | stringToUTF8(string, buffer, Infinity); 1183 | if (dontAddNull) HEAP8[end] = lastChar; // Restore the value under the null character. 1184 | } 1185 | 1186 | function writeArrayToMemory(array, buffer) { 1187 | assert(array.length >= 0, 'writeArrayToMemory array must have a length (should be an array or typed array)') 1188 | HEAP8.set(array, buffer); 1189 | } 1190 | 1191 | function writeAsciiToMemory(str, buffer, dontAddNull) { 1192 | for (var i = 0; i < str.length; ++i) { 1193 | assert(str.charCodeAt(i) === str.charCodeAt(i)&0xff); 1194 | HEAP8[((buffer++)>>0)]=str.charCodeAt(i); 1195 | } 1196 | // Null-terminate the pointer to the HEAP. 1197 | if (!dontAddNull) HEAP8[((buffer)>>0)]=0; 1198 | } 1199 | 1200 | 1201 | 1202 | 1203 | // Memory management 1204 | 1205 | var PAGE_SIZE = 16384; 1206 | var WASM_PAGE_SIZE = 65536; 1207 | var ASMJS_PAGE_SIZE = 16777216; 1208 | 1209 | function alignUp(x, multiple) { 1210 | if (x % multiple > 0) { 1211 | x += multiple - (x % multiple); 1212 | } 1213 | return x; 1214 | } 1215 | 1216 | var HEAP, 1217 | /** @type {ArrayBuffer} */ 1218 | buffer, 1219 | /** @type {Int8Array} */ 1220 | HEAP8, 1221 | /** @type {Uint8Array} */ 1222 | HEAPU8, 1223 | /** @type {Int16Array} */ 1224 | HEAP16, 1225 | /** @type {Uint16Array} */ 1226 | HEAPU16, 1227 | /** @type {Int32Array} */ 1228 | HEAP32, 1229 | /** @type {Uint32Array} */ 1230 | HEAPU32, 1231 | /** @type {Float32Array} */ 1232 | HEAPF32, 1233 | /** @type {Float64Array} */ 1234 | HEAPF64; 1235 | 1236 | function updateGlobalBufferAndViews(buf) { 1237 | buffer = buf; 1238 | Module['HEAP8'] = HEAP8 = new Int8Array(buf); 1239 | Module['HEAP16'] = HEAP16 = new Int16Array(buf); 1240 | Module['HEAP32'] = HEAP32 = new Int32Array(buf); 1241 | Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf); 1242 | Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf); 1243 | Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf); 1244 | Module['HEAPF32'] = HEAPF32 = new Float32Array(buf); 1245 | Module['HEAPF64'] = HEAPF64 = new Float64Array(buf); 1246 | } 1247 | 1248 | var STATIC_BASE = 1024, 1249 | STACK_BASE = 5244592, 1250 | STACKTOP = STACK_BASE, 1251 | STACK_MAX = 1712, 1252 | DYNAMIC_BASE = 5244592, 1253 | DYNAMICTOP_PTR = 1552; 1254 | 1255 | assert(STACK_BASE % 16 === 0, 'stack must start aligned'); 1256 | assert(DYNAMIC_BASE % 16 === 0, 'heap must start aligned'); 1257 | 1258 | 1259 | 1260 | var TOTAL_STACK = 5242880; 1261 | if (Module['TOTAL_STACK']) assert(TOTAL_STACK === Module['TOTAL_STACK'], 'the stack size can no longer be determined at runtime') 1262 | 1263 | var INITIAL_TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 16777216;if (!Object.getOwnPropertyDescriptor(Module, 'TOTAL_MEMORY')) Object.defineProperty(Module, 'TOTAL_MEMORY', { configurable: true, get: function() { abort('Module.TOTAL_MEMORY has been replaced with plain INITIAL_TOTAL_MEMORY') } }); 1264 | 1265 | assert(INITIAL_TOTAL_MEMORY >= TOTAL_STACK, 'TOTAL_MEMORY should be larger than TOTAL_STACK, was ' + INITIAL_TOTAL_MEMORY + '! (TOTAL_STACK=' + TOTAL_STACK + ')'); 1266 | 1267 | // check for full engine support (use string 'subarray' to avoid closure compiler confusion) 1268 | assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && Int32Array.prototype.subarray !== undefined && Int32Array.prototype.set !== undefined, 1269 | 'JS engine does not provide full typed array support'); 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | // In standalone mode, the wasm creates the memory, and the user can't provide it. 1277 | // In non-standalone/normal mode, we create the memory here. 1278 | 1279 | // Create the main memory. (Note: this isn't used in STANDALONE_WASM mode since the wasm 1280 | // memory is created in the wasm, not in JS.) 1281 | 1282 | if (Module['wasmMemory']) { 1283 | wasmMemory = Module['wasmMemory']; 1284 | } else 1285 | { 1286 | wasmMemory = new WebAssembly.Memory({ 1287 | 'initial': INITIAL_TOTAL_MEMORY / WASM_PAGE_SIZE 1288 | , 1289 | 'maximum': INITIAL_TOTAL_MEMORY / WASM_PAGE_SIZE 1290 | }); 1291 | } 1292 | 1293 | 1294 | if (wasmMemory) { 1295 | buffer = wasmMemory.buffer; 1296 | } 1297 | 1298 | // If the user provides an incorrect length, just use that length instead rather than providing the user to 1299 | // specifically provide the memory length with Module['TOTAL_MEMORY']. 1300 | INITIAL_TOTAL_MEMORY = buffer.byteLength; 1301 | assert(INITIAL_TOTAL_MEMORY % WASM_PAGE_SIZE === 0); 1302 | updateGlobalBufferAndViews(buffer); 1303 | 1304 | HEAP32[DYNAMICTOP_PTR>>2] = DYNAMIC_BASE; 1305 | 1306 | 1307 | 1308 | 1309 | // Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode. 1310 | function writeStackCookie() { 1311 | assert((STACK_MAX & 3) == 0); 1312 | // The stack grows downwards 1313 | HEAPU32[(STACK_MAX >> 2)+1] = 0x02135467; 1314 | HEAPU32[(STACK_MAX >> 2)+2] = 0x89BACDFE; 1315 | // Also test the global address 0 for integrity. 1316 | // We don't do this with ASan because ASan does its own checks for this. 1317 | HEAP32[0] = 0x63736d65; /* 'emsc' */ 1318 | } 1319 | 1320 | function checkStackCookie() { 1321 | var cookie1 = HEAPU32[(STACK_MAX >> 2)+1]; 1322 | var cookie2 = HEAPU32[(STACK_MAX >> 2)+2]; 1323 | if (cookie1 != 0x02135467 || cookie2 != 0x89BACDFE) { 1324 | abort('Stack overflow! Stack cookie has been overwritten, expected hex dwords 0x89BACDFE and 0x02135467, but received 0x' + cookie2.toString(16) + ' ' + cookie1.toString(16)); 1325 | } 1326 | // Also test the global address 0 for integrity. 1327 | // We don't do this with ASan because ASan does its own checks for this. 1328 | if (HEAP32[0] !== 0x63736d65 /* 'emsc' */) abort('Runtime error: The application has corrupted its heap memory area (address zero)!'); 1329 | } 1330 | 1331 | function abortStackOverflow(allocSize) { 1332 | abort('Stack overflow! Attempted to allocate ' + allocSize + ' bytes on the stack, but stack has only ' + (STACK_MAX - stackSave() + allocSize) + ' bytes available!'); 1333 | } 1334 | 1335 | 1336 | 1337 | 1338 | // Endianness check (note: assumes compiler arch was little-endian) 1339 | (function() { 1340 | var h16 = new Int16Array(1); 1341 | var h8 = new Int8Array(h16.buffer); 1342 | h16[0] = 0x6373; 1343 | if (h8[0] !== 0x73 || h8[1] !== 0x63) throw 'Runtime error: expected the system to be little-endian!'; 1344 | })(); 1345 | 1346 | function abortFnPtrError(ptr, sig) { 1347 | abort("Invalid function pointer " + ptr + " called with signature '" + sig + "'. Perhaps this is an invalid value (e.g. caused by calling a virtual method on a NULL pointer)? Or calling a function with an incorrect type, which will fail? (it is worth building your source files with -Werror (warnings are errors), as warnings can indicate undefined behavior which can cause this). Build with ASSERTIONS=2 for more info."); 1348 | } 1349 | 1350 | 1351 | 1352 | function callRuntimeCallbacks(callbacks) { 1353 | while(callbacks.length > 0) { 1354 | var callback = callbacks.shift(); 1355 | if (typeof callback == 'function') { 1356 | callback(); 1357 | continue; 1358 | } 1359 | var func = callback.func; 1360 | if (typeof func === 'number') { 1361 | if (callback.arg === undefined) { 1362 | Module['dynCall_v'](func); 1363 | } else { 1364 | Module['dynCall_vi'](func, callback.arg); 1365 | } 1366 | } else { 1367 | func(callback.arg === undefined ? null : callback.arg); 1368 | } 1369 | } 1370 | } 1371 | 1372 | var __ATPRERUN__ = []; // functions called before the runtime is initialized 1373 | var __ATINIT__ = []; // functions called during startup 1374 | var __ATMAIN__ = []; // functions called when main() is to be run 1375 | var __ATEXIT__ = []; // functions called during shutdown 1376 | var __ATPOSTRUN__ = []; // functions called after the main() is called 1377 | 1378 | var runtimeInitialized = false; 1379 | var runtimeExited = false; 1380 | 1381 | 1382 | function preRun() { 1383 | 1384 | if (Module['preRun']) { 1385 | if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']]; 1386 | while (Module['preRun'].length) { 1387 | addOnPreRun(Module['preRun'].shift()); 1388 | } 1389 | } 1390 | 1391 | callRuntimeCallbacks(__ATPRERUN__); 1392 | } 1393 | 1394 | function initRuntime() { 1395 | checkStackCookie(); 1396 | assert(!runtimeInitialized); 1397 | runtimeInitialized = true; 1398 | 1399 | callRuntimeCallbacks(__ATINIT__); 1400 | } 1401 | 1402 | function preMain() { 1403 | checkStackCookie(); 1404 | 1405 | callRuntimeCallbacks(__ATMAIN__); 1406 | } 1407 | 1408 | function exitRuntime() { 1409 | checkStackCookie(); 1410 | runtimeExited = true; 1411 | } 1412 | 1413 | function postRun() { 1414 | checkStackCookie(); 1415 | 1416 | if (Module['postRun']) { 1417 | if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']]; 1418 | while (Module['postRun'].length) { 1419 | addOnPostRun(Module['postRun'].shift()); 1420 | } 1421 | } 1422 | 1423 | callRuntimeCallbacks(__ATPOSTRUN__); 1424 | } 1425 | 1426 | function addOnPreRun(cb) { 1427 | __ATPRERUN__.unshift(cb); 1428 | } 1429 | 1430 | function addOnInit(cb) { 1431 | __ATINIT__.unshift(cb); 1432 | } 1433 | 1434 | function addOnPreMain(cb) { 1435 | __ATMAIN__.unshift(cb); 1436 | } 1437 | 1438 | function addOnExit(cb) { 1439 | } 1440 | 1441 | function addOnPostRun(cb) { 1442 | __ATPOSTRUN__.unshift(cb); 1443 | } 1444 | 1445 | function unSign(value, bits, ignore) { 1446 | if (value >= 0) { 1447 | return value; 1448 | } 1449 | return bits <= 32 ? 2*Math.abs(1 << (bits-1)) + value // Need some trickery, since if bits == 32, we are right at the limit of the bits JS uses in bitshifts 1450 | : Math.pow(2, bits) + value; 1451 | } 1452 | function reSign(value, bits, ignore) { 1453 | if (value <= 0) { 1454 | return value; 1455 | } 1456 | var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32 1457 | : Math.pow(2, bits-1); 1458 | if (value >= half && (bits <= 32 || value > half)) { // for huge values, we can hit the precision limit and always get true here. so don't do that 1459 | // but, in general there is no perfect solution here. With 64-bit ints, we get rounding and errors 1460 | // TODO: In i64 mode 1, resign the two parts separately and safely 1461 | value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts 1462 | } 1463 | return value; 1464 | } 1465 | 1466 | 1467 | assert(Math.imul, 'This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); 1468 | assert(Math.fround, 'This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); 1469 | assert(Math.clz32, 'This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); 1470 | assert(Math.trunc, 'This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill'); 1471 | 1472 | var Math_abs = Math.abs; 1473 | var Math_cos = Math.cos; 1474 | var Math_sin = Math.sin; 1475 | var Math_tan = Math.tan; 1476 | var Math_acos = Math.acos; 1477 | var Math_asin = Math.asin; 1478 | var Math_atan = Math.atan; 1479 | var Math_atan2 = Math.atan2; 1480 | var Math_exp = Math.exp; 1481 | var Math_log = Math.log; 1482 | var Math_sqrt = Math.sqrt; 1483 | var Math_ceil = Math.ceil; 1484 | var Math_floor = Math.floor; 1485 | var Math_pow = Math.pow; 1486 | var Math_imul = Math.imul; 1487 | var Math_fround = Math.fround; 1488 | var Math_round = Math.round; 1489 | var Math_min = Math.min; 1490 | var Math_max = Math.max; 1491 | var Math_clz32 = Math.clz32; 1492 | var Math_trunc = Math.trunc; 1493 | 1494 | 1495 | 1496 | // A counter of dependencies for calling run(). If we need to 1497 | // do asynchronous work before running, increment this and 1498 | // decrement it. Incrementing must happen in a place like 1499 | // Module.preRun (used by emcc to add file preloading). 1500 | // Note that you can add dependencies in preRun, even though 1501 | // it happens right before run - run will be postponed until 1502 | // the dependencies are met. 1503 | var runDependencies = 0; 1504 | var runDependencyWatcher = null; 1505 | var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled 1506 | var runDependencyTracking = {}; 1507 | 1508 | function getUniqueRunDependency(id) { 1509 | var orig = id; 1510 | while (1) { 1511 | if (!runDependencyTracking[id]) return id; 1512 | id = orig + Math.random(); 1513 | } 1514 | return id; 1515 | } 1516 | 1517 | function addRunDependency(id) { 1518 | runDependencies++; 1519 | 1520 | if (Module['monitorRunDependencies']) { 1521 | Module['monitorRunDependencies'](runDependencies); 1522 | } 1523 | 1524 | if (id) { 1525 | assert(!runDependencyTracking[id]); 1526 | runDependencyTracking[id] = 1; 1527 | if (runDependencyWatcher === null && typeof setInterval !== 'undefined') { 1528 | // Check for missing dependencies every few seconds 1529 | runDependencyWatcher = setInterval(function() { 1530 | if (ABORT) { 1531 | clearInterval(runDependencyWatcher); 1532 | runDependencyWatcher = null; 1533 | return; 1534 | } 1535 | var shown = false; 1536 | for (var dep in runDependencyTracking) { 1537 | if (!shown) { 1538 | shown = true; 1539 | err('still waiting on run dependencies:'); 1540 | } 1541 | err('dependency: ' + dep); 1542 | } 1543 | if (shown) { 1544 | err('(end of list)'); 1545 | } 1546 | }, 10000); 1547 | } 1548 | } else { 1549 | err('warning: run dependency added without ID'); 1550 | } 1551 | } 1552 | 1553 | function removeRunDependency(id) { 1554 | runDependencies--; 1555 | 1556 | if (Module['monitorRunDependencies']) { 1557 | Module['monitorRunDependencies'](runDependencies); 1558 | } 1559 | 1560 | if (id) { 1561 | assert(runDependencyTracking[id]); 1562 | delete runDependencyTracking[id]; 1563 | } else { 1564 | err('warning: run dependency removed without ID'); 1565 | } 1566 | if (runDependencies == 0) { 1567 | if (runDependencyWatcher !== null) { 1568 | clearInterval(runDependencyWatcher); 1569 | runDependencyWatcher = null; 1570 | } 1571 | if (dependenciesFulfilled) { 1572 | var callback = dependenciesFulfilled; 1573 | dependenciesFulfilled = null; 1574 | callback(); // can add another dependenciesFulfilled 1575 | } 1576 | } 1577 | } 1578 | 1579 | Module["preloadedImages"] = {}; // maps url to image data 1580 | Module["preloadedAudios"] = {}; // maps url to audio data 1581 | 1582 | 1583 | function abort(what) { 1584 | if (Module['onAbort']) { 1585 | Module['onAbort'](what); 1586 | } 1587 | 1588 | what += ''; 1589 | out(what); 1590 | err(what); 1591 | 1592 | ABORT = true; 1593 | EXITSTATUS = 1; 1594 | 1595 | var output = 'abort(' + what + ') at ' + stackTrace(); 1596 | what = output; 1597 | 1598 | // Throw a wasm runtime error, because a JS error might be seen as a foreign 1599 | // exception, which means we'd run destructors on it. We need the error to 1600 | // simply make the program stop. 1601 | throw new WebAssembly.RuntimeError(what); 1602 | } 1603 | 1604 | 1605 | var memoryInitializer = null; 1606 | 1607 | 1608 | 1609 | 1610 | // show errors on likely calls to FS when it was not included 1611 | var FS = { 1612 | error: function() { 1613 | 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 -s FORCE_FILESYSTEM=1'); 1614 | }, 1615 | init: function() { FS.error() }, 1616 | createDataFile: function() { FS.error() }, 1617 | createPreloadedFile: function() { FS.error() }, 1618 | createLazyFile: function() { FS.error() }, 1619 | open: function() { FS.error() }, 1620 | mkdev: function() { FS.error() }, 1621 | registerDevice: function() { FS.error() }, 1622 | analyzePath: function() { FS.error() }, 1623 | loadFilesFromDB: function() { FS.error() }, 1624 | 1625 | ErrnoError: function ErrnoError() { FS.error() }, 1626 | }; 1627 | Module['FS_createDataFile'] = FS.createDataFile; 1628 | Module['FS_createPreloadedFile'] = FS.createPreloadedFile; 1629 | 1630 | 1631 | 1632 | // Copyright 2017 The Emscripten Authors. All rights reserved. 1633 | // Emscripten is available under two separate licenses, the MIT license and the 1634 | // University of Illinois/NCSA Open Source License. Both these licenses can be 1635 | // found in the LICENSE file. 1636 | 1637 | // Prefix of data URIs emitted by SINGLE_FILE and related options. 1638 | var dataURIPrefix = 'data:application/octet-stream;base64,'; 1639 | 1640 | // Indicates whether filename is a base64 data URI. 1641 | function isDataURI(filename) { 1642 | return String.prototype.startsWith ? 1643 | filename.startsWith(dataURIPrefix) : 1644 | filename.indexOf(dataURIPrefix) === 0; 1645 | } 1646 | 1647 | 1648 | 1649 | 1650 | var wasmBinaryFile = 'functions.wasm'; 1651 | if (!isDataURI(wasmBinaryFile)) { 1652 | wasmBinaryFile = locateFile(wasmBinaryFile); 1653 | } 1654 | 1655 | function getBinary() { 1656 | try { 1657 | if (wasmBinary) { 1658 | return new Uint8Array(wasmBinary); 1659 | } 1660 | 1661 | if (readBinary) { 1662 | return readBinary(wasmBinaryFile); 1663 | } else { 1664 | throw "both async and sync fetching of the wasm failed"; 1665 | } 1666 | } 1667 | catch (err) { 1668 | abort(err); 1669 | } 1670 | } 1671 | 1672 | function getBinaryPromise() { 1673 | // if we don't have the binary yet, and have the Fetch api, use that 1674 | // in some environments, like Electron's render process, Fetch api may be present, but have a different context than expected, let's only use it on the Web 1675 | if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === 'function') { 1676 | return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) { 1677 | if (!response['ok']) { 1678 | throw "failed to load wasm binary file at '" + wasmBinaryFile + "'"; 1679 | } 1680 | return response['arrayBuffer'](); 1681 | }).catch(function () { 1682 | return getBinary(); 1683 | }); 1684 | } 1685 | // Otherwise, getBinary should be able to get it synchronously 1686 | return new Promise(function(resolve, reject) { 1687 | resolve(getBinary()); 1688 | }); 1689 | } 1690 | 1691 | 1692 | 1693 | // Create the wasm instance. 1694 | // Receives the wasm imports, returns the exports. 1695 | function createWasm() { 1696 | // prepare imports 1697 | var info = { 1698 | 'env': asmLibraryArg, 1699 | 'wasi_snapshot_preview1': asmLibraryArg 1700 | }; 1701 | // Load the wasm module and create an instance of using native support in the JS engine. 1702 | // handle a generated wasm instance, receiving its exports and 1703 | // performing other necessary setup 1704 | function receiveInstance(instance, module) { 1705 | var exports = instance.exports; 1706 | Module['asm'] = exports; 1707 | removeRunDependency('wasm-instantiate'); 1708 | } 1709 | // we can't run yet (except in a pthread, where we have a custom sync instantiator) 1710 | addRunDependency('wasm-instantiate'); 1711 | 1712 | 1713 | // Async compilation can be confusing when an error on the page overwrites Module 1714 | // (for example, if the order of elements is wrong, and the one defining Module is 1715 | // later), so we save Module and check it later. 1716 | var trueModule = Module; 1717 | function receiveInstantiatedSource(output) { 1718 | // 'output' is a WebAssemblyInstantiatedSource object which has both the module and instance. 1719 | // receiveInstance() will swap in the exports (to Module.asm) so they can be called 1720 | assert(Module === trueModule, 'the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?'); 1721 | trueModule = null; 1722 | // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line. 1723 | // When the regression is fixed, can restore the above USE_PTHREADS-enabled path. 1724 | receiveInstance(output['instance']); 1725 | } 1726 | 1727 | 1728 | function instantiateArrayBuffer(receiver) { 1729 | return getBinaryPromise().then(function(binary) { 1730 | return WebAssembly.instantiate(binary, info); 1731 | }).then(receiver, function(reason) { 1732 | err('failed to asynchronously prepare wasm: ' + reason); 1733 | abort(reason); 1734 | }); 1735 | } 1736 | 1737 | // Prefer streaming instantiation if available. 1738 | function instantiateAsync() { 1739 | if (!wasmBinary && 1740 | typeof WebAssembly.instantiateStreaming === 'function' && 1741 | !isDataURI(wasmBinaryFile) && 1742 | typeof fetch === 'function') { 1743 | fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function (response) { 1744 | var result = WebAssembly.instantiateStreaming(response, info); 1745 | return result.then(receiveInstantiatedSource, function(reason) { 1746 | // We expect the most common failure cause to be a bad MIME type for the binary, 1747 | // in which case falling back to ArrayBuffer instantiation should work. 1748 | err('wasm streaming compile failed: ' + reason); 1749 | err('falling back to ArrayBuffer instantiation'); 1750 | instantiateArrayBuffer(receiveInstantiatedSource); 1751 | }); 1752 | }); 1753 | } else { 1754 | return instantiateArrayBuffer(receiveInstantiatedSource); 1755 | } 1756 | } 1757 | // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback 1758 | // to manually instantiate the Wasm module themselves. This allows pages to run the instantiation parallel 1759 | // to any other async startup actions they are performing. 1760 | if (Module['instantiateWasm']) { 1761 | try { 1762 | var exports = Module['instantiateWasm'](info, receiveInstance); 1763 | return exports; 1764 | } catch(e) { 1765 | err('Module.instantiateWasm callback failed with error: ' + e); 1766 | return false; 1767 | } 1768 | } 1769 | 1770 | instantiateAsync(); 1771 | return {}; // no exports yet; we'll fill them in later 1772 | } 1773 | 1774 | 1775 | // Globals used by JS i64 conversions 1776 | var tempDouble; 1777 | var tempI64; 1778 | 1779 | // === Body === 1780 | 1781 | var ASM_CONSTS = { 1782 | 1783 | }; 1784 | 1785 | 1786 | 1787 | 1788 | // STATICTOP = STATIC_BASE + 688; 1789 | /* global initializers */ __ATINIT__.push({ func: function() { ___wasm_call_ctors() } }); 1790 | 1791 | 1792 | 1793 | 1794 | /* no memory initializer */ 1795 | // {{PRE_LIBRARY}} 1796 | 1797 | 1798 | function demangle(func) { 1799 | warnOnce('warning: build with -s DEMANGLE_SUPPORT=1 to link in libcxxabi demangling'); 1800 | return func; 1801 | } 1802 | 1803 | function demangleAll(text) { 1804 | var regex = 1805 | /\b_Z[\w\d_]+/g; 1806 | return text.replace(regex, 1807 | function(x) { 1808 | var y = demangle(x); 1809 | return x === y ? x : (y + ' [' + x + ']'); 1810 | }); 1811 | } 1812 | 1813 | function jsStackTrace() { 1814 | var err = new Error(); 1815 | if (!err.stack) { 1816 | // IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown, 1817 | // so try that as a special-case. 1818 | try { 1819 | throw new Error(0); 1820 | } catch(e) { 1821 | err = e; 1822 | } 1823 | if (!err.stack) { 1824 | return '(no stack trace available)'; 1825 | } 1826 | } 1827 | return err.stack.toString(); 1828 | } 1829 | 1830 | function stackTrace() { 1831 | var js = jsStackTrace(); 1832 | if (Module['extraStackTrace']) js += '\n' + Module['extraStackTrace'](); 1833 | return demangleAll(js); 1834 | } 1835 | 1836 | function ___handle_stack_overflow() { 1837 | abort('stack overflow') 1838 | } 1839 | 1840 | function ___lock() {} 1841 | 1842 | function ___unlock() {} 1843 | 1844 | function _emscripten_get_heap_size() { 1845 | return HEAP8.length; 1846 | } 1847 | 1848 | function _emscripten_get_sbrk_ptr() { 1849 | return 1552; 1850 | } 1851 | 1852 | 1853 | function abortOnCannotGrowMemory(requestedSize) { 1854 | abort('Cannot enlarge memory arrays to size ' + requestedSize + ' bytes (OOM). Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value ' + HEAP8.length + ', (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 '); 1855 | }function _emscripten_resize_heap(requestedSize) { 1856 | abortOnCannotGrowMemory(requestedSize); 1857 | } 1858 | 1859 | 1860 | function _emscripten_memcpy_big(dest, src, num) { 1861 | HEAPU8.set(HEAPU8.subarray(src, src+num), dest); 1862 | } 1863 | 1864 | function _memcpy(dest, src, num) { 1865 | dest = dest|0; src = src|0; num = num|0; 1866 | var ret = 0; 1867 | var aligned_dest_end = 0; 1868 | var block_aligned_dest_end = 0; 1869 | var dest_end = 0; 1870 | // Test against a benchmarked cutoff limit for when HEAPU8.set() becomes faster to use. 1871 | if ((num|0) >= 8192) { 1872 | _emscripten_memcpy_big(dest|0, src|0, num|0)|0; 1873 | return dest|0; 1874 | } 1875 | 1876 | ret = dest|0; 1877 | dest_end = (dest + num)|0; 1878 | if ((dest&3) == (src&3)) { 1879 | // The initial unaligned < 4-byte front. 1880 | while (dest & 3) { 1881 | if ((num|0) == 0) return ret|0; 1882 | HEAP8[((dest)>>0)]=((HEAP8[((src)>>0)])|0); 1883 | dest = (dest+1)|0; 1884 | src = (src+1)|0; 1885 | num = (num-1)|0; 1886 | } 1887 | aligned_dest_end = (dest_end & -4)|0; 1888 | block_aligned_dest_end = (aligned_dest_end - 64)|0; 1889 | while ((dest|0) <= (block_aligned_dest_end|0) ) { 1890 | HEAP32[((dest)>>2)]=((HEAP32[((src)>>2)])|0); 1891 | HEAP32[(((dest)+(4))>>2)]=((HEAP32[(((src)+(4))>>2)])|0); 1892 | HEAP32[(((dest)+(8))>>2)]=((HEAP32[(((src)+(8))>>2)])|0); 1893 | HEAP32[(((dest)+(12))>>2)]=((HEAP32[(((src)+(12))>>2)])|0); 1894 | HEAP32[(((dest)+(16))>>2)]=((HEAP32[(((src)+(16))>>2)])|0); 1895 | HEAP32[(((dest)+(20))>>2)]=((HEAP32[(((src)+(20))>>2)])|0); 1896 | HEAP32[(((dest)+(24))>>2)]=((HEAP32[(((src)+(24))>>2)])|0); 1897 | HEAP32[(((dest)+(28))>>2)]=((HEAP32[(((src)+(28))>>2)])|0); 1898 | HEAP32[(((dest)+(32))>>2)]=((HEAP32[(((src)+(32))>>2)])|0); 1899 | HEAP32[(((dest)+(36))>>2)]=((HEAP32[(((src)+(36))>>2)])|0); 1900 | HEAP32[(((dest)+(40))>>2)]=((HEAP32[(((src)+(40))>>2)])|0); 1901 | HEAP32[(((dest)+(44))>>2)]=((HEAP32[(((src)+(44))>>2)])|0); 1902 | HEAP32[(((dest)+(48))>>2)]=((HEAP32[(((src)+(48))>>2)])|0); 1903 | HEAP32[(((dest)+(52))>>2)]=((HEAP32[(((src)+(52))>>2)])|0); 1904 | HEAP32[(((dest)+(56))>>2)]=((HEAP32[(((src)+(56))>>2)])|0); 1905 | HEAP32[(((dest)+(60))>>2)]=((HEAP32[(((src)+(60))>>2)])|0); 1906 | dest = (dest+64)|0; 1907 | src = (src+64)|0; 1908 | } 1909 | while ((dest|0) < (aligned_dest_end|0) ) { 1910 | HEAP32[((dest)>>2)]=((HEAP32[((src)>>2)])|0); 1911 | dest = (dest+4)|0; 1912 | src = (src+4)|0; 1913 | } 1914 | } else { 1915 | // In the unaligned copy case, unroll a bit as well. 1916 | aligned_dest_end = (dest_end - 4)|0; 1917 | while ((dest|0) < (aligned_dest_end|0) ) { 1918 | HEAP8[((dest)>>0)]=((HEAP8[((src)>>0)])|0); 1919 | HEAP8[(((dest)+(1))>>0)]=((HEAP8[(((src)+(1))>>0)])|0); 1920 | HEAP8[(((dest)+(2))>>0)]=((HEAP8[(((src)+(2))>>0)])|0); 1921 | HEAP8[(((dest)+(3))>>0)]=((HEAP8[(((src)+(3))>>0)])|0); 1922 | dest = (dest+4)|0; 1923 | src = (src+4)|0; 1924 | } 1925 | } 1926 | // The remaining unaligned < 4 byte tail. 1927 | while ((dest|0) < (dest_end|0)) { 1928 | HEAP8[((dest)>>0)]=((HEAP8[((src)>>0)])|0); 1929 | dest = (dest+1)|0; 1930 | src = (src+1)|0; 1931 | } 1932 | return ret|0; 1933 | } 1934 | 1935 | function _memset(ptr, value, num) { 1936 | ptr = ptr|0; value = value|0; num = num|0; 1937 | var end = 0, aligned_end = 0, block_aligned_end = 0, value4 = 0; 1938 | end = (ptr + num)|0; 1939 | 1940 | value = value & 0xff; 1941 | if ((num|0) >= 67 /* 64 bytes for an unrolled loop + 3 bytes for unaligned head*/) { 1942 | while ((ptr&3) != 0) { 1943 | HEAP8[((ptr)>>0)]=value; 1944 | ptr = (ptr+1)|0; 1945 | } 1946 | 1947 | aligned_end = (end & -4)|0; 1948 | value4 = value | (value << 8) | (value << 16) | (value << 24); 1949 | 1950 | block_aligned_end = (aligned_end - 64)|0; 1951 | 1952 | while((ptr|0) <= (block_aligned_end|0)) { 1953 | HEAP32[((ptr)>>2)]=value4; 1954 | HEAP32[(((ptr)+(4))>>2)]=value4; 1955 | HEAP32[(((ptr)+(8))>>2)]=value4; 1956 | HEAP32[(((ptr)+(12))>>2)]=value4; 1957 | HEAP32[(((ptr)+(16))>>2)]=value4; 1958 | HEAP32[(((ptr)+(20))>>2)]=value4; 1959 | HEAP32[(((ptr)+(24))>>2)]=value4; 1960 | HEAP32[(((ptr)+(28))>>2)]=value4; 1961 | HEAP32[(((ptr)+(32))>>2)]=value4; 1962 | HEAP32[(((ptr)+(36))>>2)]=value4; 1963 | HEAP32[(((ptr)+(40))>>2)]=value4; 1964 | HEAP32[(((ptr)+(44))>>2)]=value4; 1965 | HEAP32[(((ptr)+(48))>>2)]=value4; 1966 | HEAP32[(((ptr)+(52))>>2)]=value4; 1967 | HEAP32[(((ptr)+(56))>>2)]=value4; 1968 | HEAP32[(((ptr)+(60))>>2)]=value4; 1969 | ptr = (ptr + 64)|0; 1970 | } 1971 | 1972 | while ((ptr|0) < (aligned_end|0) ) { 1973 | HEAP32[((ptr)>>2)]=value4; 1974 | ptr = (ptr+4)|0; 1975 | } 1976 | } 1977 | // The remaining bytes. 1978 | while ((ptr|0) < (end|0)) { 1979 | HEAP8[((ptr)>>0)]=value; 1980 | ptr = (ptr+1)|0; 1981 | } 1982 | return (end-num)|0; 1983 | } 1984 | var ASSERTIONS = true; 1985 | 1986 | // Copyright 2017 The Emscripten Authors. All rights reserved. 1987 | // Emscripten is available under two separate licenses, the MIT license and the 1988 | // University of Illinois/NCSA Open Source License. Both these licenses can be 1989 | // found in the LICENSE file. 1990 | 1991 | /** @type {function(string, boolean=, number=)} */ 1992 | function intArrayFromString(stringy, dontAddNull, length) { 1993 | var len = length > 0 ? length : lengthBytesUTF8(stringy)+1; 1994 | var u8array = new Array(len); 1995 | var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length); 1996 | if (dontAddNull) u8array.length = numBytesWritten; 1997 | return u8array; 1998 | } 1999 | 2000 | function intArrayToString(array) { 2001 | var ret = []; 2002 | for (var i = 0; i < array.length; i++) { 2003 | var chr = array[i]; 2004 | if (chr > 0xFF) { 2005 | if (ASSERTIONS) { 2006 | assert(false, 'Character code ' + chr + ' (' + String.fromCharCode(chr) + ') at offset ' + i + ' not in 0x00-0xFF.'); 2007 | } 2008 | chr &= 0xFF; 2009 | } 2010 | ret.push(String.fromCharCode(chr)); 2011 | } 2012 | return ret.join(''); 2013 | } 2014 | 2015 | 2016 | // ASM_LIBRARY EXTERN PRIMITIVES: Int8Array,Int32Array 2017 | 2018 | var asmGlobalArg = {}; 2019 | var asmLibraryArg = { "__handle_stack_overflow": ___handle_stack_overflow, "__lock": ___lock, "__unlock": ___unlock, "emscripten_get_sbrk_ptr": _emscripten_get_sbrk_ptr, "emscripten_resize_heap": _emscripten_resize_heap, "memory": wasmMemory, "table": wasmTable }; 2020 | var asm = createWasm(); 2021 | var real____wasm_call_ctors = asm["__wasm_call_ctors"]; 2022 | asm["__wasm_call_ctors"] = function() { 2023 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2024 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2025 | return real____wasm_call_ctors.apply(null, arguments); 2026 | }; 2027 | 2028 | var real__add = asm["add"]; 2029 | asm["add"] = function() { 2030 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2031 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2032 | return real__add.apply(null, arguments); 2033 | }; 2034 | 2035 | var real____errno_location = asm["__errno_location"]; 2036 | asm["__errno_location"] = function() { 2037 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2038 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2039 | return real____errno_location.apply(null, arguments); 2040 | }; 2041 | 2042 | var real__fflush = asm["fflush"]; 2043 | asm["fflush"] = function() { 2044 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2045 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2046 | return real__fflush.apply(null, arguments); 2047 | }; 2048 | 2049 | var real__setThrew = asm["setThrew"]; 2050 | asm["setThrew"] = function() { 2051 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2052 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2053 | return real__setThrew.apply(null, arguments); 2054 | }; 2055 | 2056 | var real__malloc = asm["malloc"]; 2057 | asm["malloc"] = function() { 2058 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2059 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2060 | return real__malloc.apply(null, arguments); 2061 | }; 2062 | 2063 | var real__free = asm["free"]; 2064 | asm["free"] = function() { 2065 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2066 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2067 | return real__free.apply(null, arguments); 2068 | }; 2069 | 2070 | var real____set_stack_limit = asm["__set_stack_limit"]; 2071 | asm["__set_stack_limit"] = function() { 2072 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2073 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2074 | return real____set_stack_limit.apply(null, arguments); 2075 | }; 2076 | 2077 | var real_stackSave = asm["stackSave"]; 2078 | asm["stackSave"] = function() { 2079 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2080 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2081 | return real_stackSave.apply(null, arguments); 2082 | }; 2083 | 2084 | var real_stackAlloc = asm["stackAlloc"]; 2085 | asm["stackAlloc"] = function() { 2086 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2087 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2088 | return real_stackAlloc.apply(null, arguments); 2089 | }; 2090 | 2091 | var real_stackRestore = asm["stackRestore"]; 2092 | asm["stackRestore"] = function() { 2093 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2094 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2095 | return real_stackRestore.apply(null, arguments); 2096 | }; 2097 | 2098 | var real___growWasmMemory = asm["__growWasmMemory"]; 2099 | asm["__growWasmMemory"] = function() { 2100 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2101 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2102 | return real___growWasmMemory.apply(null, arguments); 2103 | }; 2104 | 2105 | Module["asm"] = asm; 2106 | var ___wasm_call_ctors = Module["___wasm_call_ctors"] = function() { 2107 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2108 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2109 | return Module["asm"]["__wasm_call_ctors"].apply(null, arguments) 2110 | }; 2111 | 2112 | var _add = Module["_add"] = function() { 2113 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2114 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2115 | return Module["asm"]["add"].apply(null, arguments) 2116 | }; 2117 | 2118 | var ___errno_location = Module["___errno_location"] = function() { 2119 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2120 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2121 | return Module["asm"]["__errno_location"].apply(null, arguments) 2122 | }; 2123 | 2124 | var _fflush = Module["_fflush"] = function() { 2125 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2126 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2127 | return Module["asm"]["fflush"].apply(null, arguments) 2128 | }; 2129 | 2130 | var _setThrew = Module["_setThrew"] = function() { 2131 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2132 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2133 | return Module["asm"]["setThrew"].apply(null, arguments) 2134 | }; 2135 | 2136 | var _malloc = Module["_malloc"] = function() { 2137 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2138 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2139 | return Module["asm"]["malloc"].apply(null, arguments) 2140 | }; 2141 | 2142 | var _free = Module["_free"] = function() { 2143 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2144 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2145 | return Module["asm"]["free"].apply(null, arguments) 2146 | }; 2147 | 2148 | var ___set_stack_limit = Module["___set_stack_limit"] = function() { 2149 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2150 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2151 | return Module["asm"]["__set_stack_limit"].apply(null, arguments) 2152 | }; 2153 | 2154 | var stackSave = Module["stackSave"] = function() { 2155 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2156 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2157 | return Module["asm"]["stackSave"].apply(null, arguments) 2158 | }; 2159 | 2160 | var stackAlloc = Module["stackAlloc"] = function() { 2161 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2162 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2163 | return Module["asm"]["stackAlloc"].apply(null, arguments) 2164 | }; 2165 | 2166 | var stackRestore = Module["stackRestore"] = function() { 2167 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2168 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2169 | return Module["asm"]["stackRestore"].apply(null, arguments) 2170 | }; 2171 | 2172 | var __growWasmMemory = Module["__growWasmMemory"] = function() { 2173 | assert(runtimeInitialized, 'you need to wait for the runtime to be ready (e.g. wait for main() to be called)'); 2174 | assert(!runtimeExited, 'the runtime was exited (use NO_EXIT_RUNTIME to keep it alive after main() exits)'); 2175 | return Module["asm"]["__growWasmMemory"].apply(null, arguments) 2176 | }; 2177 | 2178 | 2179 | 2180 | 2181 | // === Auto-generated postamble setup entry stuff === 2182 | 2183 | Module['asm'] = asm; 2184 | 2185 | if (!Object.getOwnPropertyDescriptor(Module, "intArrayFromString")) Module["intArrayFromString"] = function() { abort("'intArrayFromString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2186 | if (!Object.getOwnPropertyDescriptor(Module, "intArrayToString")) Module["intArrayToString"] = function() { abort("'intArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2187 | if (!Object.getOwnPropertyDescriptor(Module, "ccall")) Module["ccall"] = function() { abort("'ccall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2188 | if (!Object.getOwnPropertyDescriptor(Module, "cwrap")) Module["cwrap"] = function() { abort("'cwrap' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2189 | if (!Object.getOwnPropertyDescriptor(Module, "setValue")) Module["setValue"] = function() { abort("'setValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2190 | if (!Object.getOwnPropertyDescriptor(Module, "getValue")) Module["getValue"] = function() { abort("'getValue' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2191 | if (!Object.getOwnPropertyDescriptor(Module, "allocate")) Module["allocate"] = function() { abort("'allocate' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2192 | if (!Object.getOwnPropertyDescriptor(Module, "getMemory")) Module["getMemory"] = function() { abort("'getMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2193 | if (!Object.getOwnPropertyDescriptor(Module, "AsciiToString")) Module["AsciiToString"] = function() { abort("'AsciiToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2194 | if (!Object.getOwnPropertyDescriptor(Module, "stringToAscii")) Module["stringToAscii"] = function() { abort("'stringToAscii' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2195 | if (!Object.getOwnPropertyDescriptor(Module, "UTF8ArrayToString")) Module["UTF8ArrayToString"] = function() { abort("'UTF8ArrayToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2196 | if (!Object.getOwnPropertyDescriptor(Module, "UTF8ToString")) Module["UTF8ToString"] = function() { abort("'UTF8ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2197 | if (!Object.getOwnPropertyDescriptor(Module, "stringToUTF8Array")) Module["stringToUTF8Array"] = function() { abort("'stringToUTF8Array' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2198 | if (!Object.getOwnPropertyDescriptor(Module, "stringToUTF8")) Module["stringToUTF8"] = function() { abort("'stringToUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2199 | if (!Object.getOwnPropertyDescriptor(Module, "lengthBytesUTF8")) Module["lengthBytesUTF8"] = function() { abort("'lengthBytesUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2200 | if (!Object.getOwnPropertyDescriptor(Module, "UTF16ToString")) Module["UTF16ToString"] = function() { abort("'UTF16ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2201 | if (!Object.getOwnPropertyDescriptor(Module, "stringToUTF16")) Module["stringToUTF16"] = function() { abort("'stringToUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2202 | if (!Object.getOwnPropertyDescriptor(Module, "lengthBytesUTF16")) Module["lengthBytesUTF16"] = function() { abort("'lengthBytesUTF16' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2203 | if (!Object.getOwnPropertyDescriptor(Module, "UTF32ToString")) Module["UTF32ToString"] = function() { abort("'UTF32ToString' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2204 | if (!Object.getOwnPropertyDescriptor(Module, "stringToUTF32")) Module["stringToUTF32"] = function() { abort("'stringToUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2205 | if (!Object.getOwnPropertyDescriptor(Module, "lengthBytesUTF32")) Module["lengthBytesUTF32"] = function() { abort("'lengthBytesUTF32' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2206 | if (!Object.getOwnPropertyDescriptor(Module, "allocateUTF8")) Module["allocateUTF8"] = function() { abort("'allocateUTF8' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2207 | if (!Object.getOwnPropertyDescriptor(Module, "stackTrace")) Module["stackTrace"] = function() { abort("'stackTrace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2208 | if (!Object.getOwnPropertyDescriptor(Module, "addOnPreRun")) Module["addOnPreRun"] = function() { abort("'addOnPreRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2209 | if (!Object.getOwnPropertyDescriptor(Module, "addOnInit")) Module["addOnInit"] = function() { abort("'addOnInit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2210 | if (!Object.getOwnPropertyDescriptor(Module, "addOnPreMain")) Module["addOnPreMain"] = function() { abort("'addOnPreMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2211 | if (!Object.getOwnPropertyDescriptor(Module, "addOnExit")) Module["addOnExit"] = function() { abort("'addOnExit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2212 | if (!Object.getOwnPropertyDescriptor(Module, "addOnPostRun")) Module["addOnPostRun"] = function() { abort("'addOnPostRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2213 | if (!Object.getOwnPropertyDescriptor(Module, "writeStringToMemory")) Module["writeStringToMemory"] = function() { abort("'writeStringToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2214 | if (!Object.getOwnPropertyDescriptor(Module, "writeArrayToMemory")) Module["writeArrayToMemory"] = function() { abort("'writeArrayToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2215 | if (!Object.getOwnPropertyDescriptor(Module, "writeAsciiToMemory")) Module["writeAsciiToMemory"] = function() { abort("'writeAsciiToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2216 | if (!Object.getOwnPropertyDescriptor(Module, "addRunDependency")) Module["addRunDependency"] = function() { abort("'addRunDependency' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2217 | if (!Object.getOwnPropertyDescriptor(Module, "removeRunDependency")) Module["removeRunDependency"] = function() { abort("'removeRunDependency' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2218 | if (!Object.getOwnPropertyDescriptor(Module, "ENV")) Module["ENV"] = function() { abort("'ENV' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2219 | if (!Object.getOwnPropertyDescriptor(Module, "FS")) Module["FS"] = function() { abort("'FS' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2220 | if (!Object.getOwnPropertyDescriptor(Module, "FS_createFolder")) Module["FS_createFolder"] = function() { abort("'FS_createFolder' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2221 | if (!Object.getOwnPropertyDescriptor(Module, "FS_createPath")) Module["FS_createPath"] = function() { abort("'FS_createPath' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2222 | if (!Object.getOwnPropertyDescriptor(Module, "FS_createDataFile")) Module["FS_createDataFile"] = function() { abort("'FS_createDataFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2223 | if (!Object.getOwnPropertyDescriptor(Module, "FS_createPreloadedFile")) Module["FS_createPreloadedFile"] = function() { abort("'FS_createPreloadedFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2224 | if (!Object.getOwnPropertyDescriptor(Module, "FS_createLazyFile")) Module["FS_createLazyFile"] = function() { abort("'FS_createLazyFile' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2225 | if (!Object.getOwnPropertyDescriptor(Module, "FS_createLink")) Module["FS_createLink"] = function() { abort("'FS_createLink' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2226 | if (!Object.getOwnPropertyDescriptor(Module, "FS_createDevice")) Module["FS_createDevice"] = function() { abort("'FS_createDevice' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2227 | if (!Object.getOwnPropertyDescriptor(Module, "FS_unlink")) Module["FS_unlink"] = function() { abort("'FS_unlink' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") }; 2228 | if (!Object.getOwnPropertyDescriptor(Module, "GL")) Module["GL"] = function() { abort("'GL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2229 | if (!Object.getOwnPropertyDescriptor(Module, "dynamicAlloc")) Module["dynamicAlloc"] = function() { abort("'dynamicAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2230 | if (!Object.getOwnPropertyDescriptor(Module, "loadDynamicLibrary")) Module["loadDynamicLibrary"] = function() { abort("'loadDynamicLibrary' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2231 | if (!Object.getOwnPropertyDescriptor(Module, "loadWebAssemblyModule")) Module["loadWebAssemblyModule"] = function() { abort("'loadWebAssemblyModule' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2232 | if (!Object.getOwnPropertyDescriptor(Module, "getLEB")) Module["getLEB"] = function() { abort("'getLEB' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2233 | if (!Object.getOwnPropertyDescriptor(Module, "getFunctionTables")) Module["getFunctionTables"] = function() { abort("'getFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2234 | if (!Object.getOwnPropertyDescriptor(Module, "alignFunctionTables")) Module["alignFunctionTables"] = function() { abort("'alignFunctionTables' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2235 | if (!Object.getOwnPropertyDescriptor(Module, "registerFunctions")) Module["registerFunctions"] = function() { abort("'registerFunctions' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2236 | if (!Object.getOwnPropertyDescriptor(Module, "addFunction")) Module["addFunction"] = function() { abort("'addFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2237 | if (!Object.getOwnPropertyDescriptor(Module, "removeFunction")) Module["removeFunction"] = function() { abort("'removeFunction' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2238 | if (!Object.getOwnPropertyDescriptor(Module, "getFuncWrapper")) Module["getFuncWrapper"] = function() { abort("'getFuncWrapper' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2239 | if (!Object.getOwnPropertyDescriptor(Module, "prettyPrint")) Module["prettyPrint"] = function() { abort("'prettyPrint' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2240 | if (!Object.getOwnPropertyDescriptor(Module, "makeBigInt")) Module["makeBigInt"] = function() { abort("'makeBigInt' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2241 | if (!Object.getOwnPropertyDescriptor(Module, "dynCall")) Module["dynCall"] = function() { abort("'dynCall' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2242 | if (!Object.getOwnPropertyDescriptor(Module, "getCompilerSetting")) Module["getCompilerSetting"] = function() { abort("'getCompilerSetting' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2243 | if (!Object.getOwnPropertyDescriptor(Module, "print")) Module["print"] = function() { abort("'print' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2244 | if (!Object.getOwnPropertyDescriptor(Module, "printErr")) Module["printErr"] = function() { abort("'printErr' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2245 | if (!Object.getOwnPropertyDescriptor(Module, "getTempRet0")) Module["getTempRet0"] = function() { abort("'getTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2246 | if (!Object.getOwnPropertyDescriptor(Module, "setTempRet0")) Module["setTempRet0"] = function() { abort("'setTempRet0' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2247 | if (!Object.getOwnPropertyDescriptor(Module, "callMain")) Module["callMain"] = function() { abort("'callMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2248 | if (!Object.getOwnPropertyDescriptor(Module, "abort")) Module["abort"] = function() { abort("'abort' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2249 | if (!Object.getOwnPropertyDescriptor(Module, "Pointer_stringify")) Module["Pointer_stringify"] = function() { abort("'Pointer_stringify' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2250 | if (!Object.getOwnPropertyDescriptor(Module, "warnOnce")) Module["warnOnce"] = function() { abort("'warnOnce' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2251 | if (!Object.getOwnPropertyDescriptor(Module, "stackSave")) Module["stackSave"] = function() { abort("'stackSave' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2252 | if (!Object.getOwnPropertyDescriptor(Module, "stackRestore")) Module["stackRestore"] = function() { abort("'stackRestore' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2253 | if (!Object.getOwnPropertyDescriptor(Module, "stackAlloc")) Module["stackAlloc"] = function() { abort("'stackAlloc' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2254 | if (!Object.getOwnPropertyDescriptor(Module, "establishStackSpace")) Module["establishStackSpace"] = function() { abort("'establishStackSpace' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") }; 2255 | Module["writeStackCookie"] = writeStackCookie; 2256 | Module["checkStackCookie"] = checkStackCookie; 2257 | Module["abortStackOverflow"] = abortStackOverflow;if (!Object.getOwnPropertyDescriptor(Module, "ALLOC_NORMAL")) Object.defineProperty(Module, "ALLOC_NORMAL", { configurable: true, get: function() { abort("'ALLOC_NORMAL' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } }); 2258 | if (!Object.getOwnPropertyDescriptor(Module, "ALLOC_STACK")) Object.defineProperty(Module, "ALLOC_STACK", { configurable: true, get: function() { abort("'ALLOC_STACK' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } }); 2259 | if (!Object.getOwnPropertyDescriptor(Module, "ALLOC_DYNAMIC")) Object.defineProperty(Module, "ALLOC_DYNAMIC", { configurable: true, get: function() { abort("'ALLOC_DYNAMIC' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } }); 2260 | if (!Object.getOwnPropertyDescriptor(Module, "ALLOC_NONE")) Object.defineProperty(Module, "ALLOC_NONE", { configurable: true, get: function() { abort("'ALLOC_NONE' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") } }); 2261 | if (!Object.getOwnPropertyDescriptor(Module, "calledRun")) Object.defineProperty(Module, "calledRun", { configurable: true, get: function() { abort("'calledRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ). Alternatively, forcing filesystem support (-s FORCE_FILESYSTEM=1) can export this for you") } }); 2262 | 2263 | 2264 | 2265 | var calledRun; 2266 | 2267 | 2268 | /** 2269 | * @constructor 2270 | * @this {ExitStatus} 2271 | */ 2272 | function ExitStatus(status) { 2273 | this.name = "ExitStatus"; 2274 | this.message = "Program terminated with exit(" + status + ")"; 2275 | this.status = status; 2276 | } 2277 | 2278 | var calledMain = false; 2279 | 2280 | 2281 | dependenciesFulfilled = function runCaller() { 2282 | // If run has never been called, and we should call run (INVOKE_RUN is true, and Module.noInitialRun is not false) 2283 | if (!calledRun) run(); 2284 | if (!calledRun) dependenciesFulfilled = runCaller; // try this again later, after new deps are fulfilled 2285 | }; 2286 | 2287 | 2288 | 2289 | 2290 | 2291 | /** @type {function(Array=)} */ 2292 | function run(args) { 2293 | args = args || arguments_; 2294 | 2295 | if (runDependencies > 0) { 2296 | return; 2297 | } 2298 | 2299 | writeStackCookie(); 2300 | 2301 | preRun(); 2302 | 2303 | if (runDependencies > 0) return; // a preRun added a dependency, run will be called later 2304 | 2305 | function doRun() { 2306 | // run may have just been called through dependencies being fulfilled just in this very frame, 2307 | // or while the async setStatus time below was happening 2308 | if (calledRun) return; 2309 | calledRun = true; 2310 | 2311 | if (ABORT) return; 2312 | 2313 | initRuntime(); 2314 | 2315 | preMain(); 2316 | 2317 | if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized'](); 2318 | 2319 | assert(!Module['_main'], 'compiled without a main, but one is present. if you added it from JS, use Module["onRuntimeInitialized"]'); 2320 | 2321 | postRun(); 2322 | } 2323 | 2324 | if (Module['setStatus']) { 2325 | Module['setStatus']('Running...'); 2326 | setTimeout(function() { 2327 | setTimeout(function() { 2328 | Module['setStatus'](''); 2329 | }, 1); 2330 | doRun(); 2331 | }, 1); 2332 | } else 2333 | { 2334 | doRun(); 2335 | } 2336 | checkStackCookie(); 2337 | } 2338 | Module['run'] = run; 2339 | 2340 | function checkUnflushedContent() { 2341 | // Compiler settings do not allow exiting the runtime, so flushing 2342 | // the streams is not possible. but in ASSERTIONS mode we check 2343 | // if there was something to flush, and if so tell the user they 2344 | // should request that the runtime be exitable. 2345 | // Normally we would not even include flush() at all, but in ASSERTIONS 2346 | // builds we do so just for this check, and here we see if there is any 2347 | // content to flush, that is, we check if there would have been 2348 | // something a non-ASSERTIONS build would have not seen. 2349 | // How we flush the streams depends on whether we are in SYSCALLS_REQUIRE_FILESYSTEM=0 2350 | // mode (which has its own special function for this; otherwise, all 2351 | // the code is inside libc) 2352 | var print = out; 2353 | var printErr = err; 2354 | var has = false; 2355 | out = err = function(x) { 2356 | has = true; 2357 | } 2358 | try { // it doesn't matter if it fails 2359 | var flush = null; 2360 | if (flush) flush(0); 2361 | } catch(e) {} 2362 | out = print; 2363 | err = printErr; 2364 | if (has) { 2365 | warnOnce('stdio streams had content in them that was not flushed. you should set EXIT_RUNTIME to 1 (see the FAQ), or make sure to emit a newline when you printf etc.'); 2366 | warnOnce('(this may also be due to not including full filesystem support - try building with -s FORCE_FILESYSTEM=1)'); 2367 | } 2368 | } 2369 | 2370 | function exit(status, implicit) { 2371 | checkUnflushedContent(); 2372 | 2373 | // if this is just main exit-ing implicitly, and the status is 0, then we 2374 | // don't need to do anything here and can just leave. if the status is 2375 | // non-zero, though, then we need to report it. 2376 | // (we may have warned about this earlier, if a situation justifies doing so) 2377 | if (implicit && noExitRuntime && status === 0) { 2378 | return; 2379 | } 2380 | 2381 | if (noExitRuntime) { 2382 | // if exit() was called, we may warn the user if the runtime isn't actually being shut down 2383 | if (!implicit) { 2384 | err('program exited (with status: ' + status + '), but EXIT_RUNTIME is not set, so halting execution but not exiting the runtime or preventing further async execution (build with EXIT_RUNTIME=1, if you want a true shutdown)'); 2385 | } 2386 | } else { 2387 | 2388 | ABORT = true; 2389 | EXITSTATUS = status; 2390 | 2391 | exitRuntime(); 2392 | 2393 | if (Module['onExit']) Module['onExit'](status); 2394 | } 2395 | 2396 | quit_(status, new ExitStatus(status)); 2397 | } 2398 | 2399 | if (Module['preInit']) { 2400 | if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']]; 2401 | while (Module['preInit'].length > 0) { 2402 | Module['preInit'].pop()(); 2403 | } 2404 | } 2405 | 2406 | 2407 | noExitRuntime = true; 2408 | 2409 | run(); 2410 | 2411 | 2412 | 2413 | 2414 | 2415 | // {{MODULE_ADDITIONS}} 2416 | 2417 | 2418 | 2419 | -------------------------------------------------------------------------------- /functions.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Nitij/C-Language-To-WASM/6278d1c123e1cced225b7771e200f5691bd234cc/functions.wasm -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | let wasmExports = null; 2 | 3 | let wasmMemory = new WebAssembly.Memory({initial: 256, maximum: 256}); 4 | 5 | let wasmTable = new WebAssembly.Table({ 6 | 'initial': 1, 7 | 'maximum': 1, 8 | 'element': 'anyfunc' 9 | }); 10 | 11 | let asmLibraryArg = { 12 | "__handle_stack_overflow": ()=>{}, 13 | "emscripten_resize_heap": ()=>{}, 14 | "__lock": ()=>{}, 15 | "__unlock": ()=>{}, 16 | "memory": wasmMemory, 17 | "table": wasmTable 18 | }; 19 | 20 | var info = { 21 | 'env': asmLibraryArg, 22 | 'wasi_snapshot_preview1': asmLibraryArg 23 | }; 24 | 25 | async function loadWasm(){ 26 | let response = await fetch('functions.wasm'); 27 | let bytes = await response.arrayBuffer(); 28 | let wasmObj = await WebAssembly.instantiate(bytes, info); 29 | wasmExports = wasmObj.instance.exports; 30 | } 31 | 32 | loadWasm(); --------------------------------------------------------------------------------