PageRenderTime 72ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 3ms

/EmTutor/disk_harmonic_map.js

https://github.com/cfwen/extremal
JavaScript | 8820 lines | 6000 code | 2235 blank | 585 comment | 1569 complexity | c7972acae3b376c706ee2722441c2e98 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. // Note: For maximum-speed code, see "Optimizing Code" on the Emscripten wiki, https://github.com/kripken/emscripten/wiki/Optimizing-Code
  2. // Note: Some Emscripten settings may limit the speed of the generated code.
  3. // The Module object: Our interface to the outside world. We import
  4. // and export values on it, and do the work to get that through
  5. // closure compiler if necessary. There are various ways Module can be used:
  6. // 1. Not defined. We create it here
  7. // 2. A function parameter, function(Module) { ..generated code.. }
  8. // 3. pre-run appended it, var Module = {}; ..generated code..
  9. // 4. External script tag defines var Module.
  10. // We need to do an eval in order to handle the closure compiler
  11. // case, where this code here is minified but Module was defined
  12. // elsewhere (e.g. case 4 above). We also need to check if Module
  13. // already exists (e.g. case 3 above).
  14. // Note that if you want to run closure, and also to use Module
  15. // after the generated code, you will need to define var Module = {};
  16. // before the code. Then that object will be used in the code, and you
  17. // can continue to use Module afterwards as well.
  18. var Module;
  19. if (!Module) Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
  20. // Sometimes an existing Module object exists with properties
  21. // meant to overwrite the default module functionality. Here
  22. // we collect those properties and reapply _after_ we configure
  23. // the current environment's defaults to avoid having to be so
  24. // defensive during initialization.
  25. var moduleOverrides = {};
  26. for (var key in Module) {
  27. if (Module.hasOwnProperty(key)) {
  28. moduleOverrides[key] = Module[key];
  29. }
  30. }
  31. // The environment setup code below is customized to use Module.
  32. // *** Environment setup code ***
  33. var ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function';
  34. var ENVIRONMENT_IS_WEB = typeof window === 'object';
  35. var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
  36. var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
  37. if (ENVIRONMENT_IS_NODE) {
  38. // Expose functionality in the same simple way that the shells work
  39. // Note that we pollute the global namespace here, otherwise we break in node
  40. if (!Module['print']) Module['print'] = function print(x) {
  41. process['stdout'].write(x + '\n');
  42. };
  43. if (!Module['printErr']) Module['printErr'] = function printErr(x) {
  44. process['stderr'].write(x + '\n');
  45. };
  46. var nodeFS = require('fs');
  47. var nodePath = require('path');
  48. Module['read'] = function read(filename, binary) {
  49. filename = nodePath['normalize'](filename);
  50. var ret = nodeFS['readFileSync'](filename);
  51. // The path is absolute if the normalized version is the same as the resolved.
  52. if (!ret && filename != nodePath['resolve'](filename)) {
  53. filename = path.join(__dirname, '..', 'src', filename);
  54. ret = nodeFS['readFileSync'](filename);
  55. }
  56. if (ret && !binary) ret = ret.toString();
  57. return ret;
  58. };
  59. Module['readBinary'] = function readBinary(filename) { return Module['read'](filename, true) };
  60. Module['load'] = function load(f) {
  61. globalEval(read(f));
  62. };
  63. Module['arguments'] = process['argv'].slice(2);
  64. module['exports'] = Module;
  65. }
  66. else if (ENVIRONMENT_IS_SHELL) {
  67. if (!Module['print']) Module['print'] = print;
  68. if (typeof printErr != 'undefined') Module['printErr'] = printErr; // not present in v8 or older sm
  69. if (typeof read != 'undefined') {
  70. Module['read'] = read;
  71. } else {
  72. Module['read'] = function read() { throw 'no read() available (jsc?)' };
  73. }
  74. Module['readBinary'] = function readBinary(f) {
  75. return read(f, 'binary');
  76. };
  77. if (typeof scriptArgs != 'undefined') {
  78. Module['arguments'] = scriptArgs;
  79. } else if (typeof arguments != 'undefined') {
  80. Module['arguments'] = arguments;
  81. }
  82. this['Module'] = Module;
  83. eval("if (typeof gc === 'function' && gc.toString().indexOf('[native code]') > 0) var gc = undefined"); // wipe out the SpiderMonkey shell 'gc' function, which can confuse closure (uses it as a minified name, and it is then initted to a non-falsey value unexpectedly)
  84. }
  85. else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
  86. Module['read'] = function read(url) {
  87. var xhr = new XMLHttpRequest();
  88. xhr.open('GET', url, false);
  89. xhr.send(null);
  90. return xhr.responseText;
  91. };
  92. if (typeof arguments != 'undefined') {
  93. Module['arguments'] = arguments;
  94. }
  95. if (typeof console !== 'undefined') {
  96. if (!Module['print']) Module['print'] = function print(x) {
  97. console.log(x);
  98. };
  99. if (!Module['printErr']) Module['printErr'] = function printErr(x) {
  100. console.log(x);
  101. };
  102. } else {
  103. // Probably a worker, and without console.log. We can do very little here...
  104. var TRY_USE_DUMP = false;
  105. if (!Module['print']) Module['print'] = (TRY_USE_DUMP && (typeof(dump) !== "undefined") ? (function(x) {
  106. dump(x);
  107. }) : (function(x) {
  108. // self.postMessage(x); // enable this if you want stdout to be sent as messages
  109. }));
  110. }
  111. if (ENVIRONMENT_IS_WEB) {
  112. this['Module'] = Module;
  113. } else {
  114. Module['load'] = importScripts;
  115. }
  116. }
  117. else {
  118. // Unreachable because SHELL is dependant on the others
  119. throw 'Unknown runtime environment. Where are we?';
  120. }
  121. function globalEval(x) {
  122. eval.call(null, x);
  123. }
  124. if (!Module['load'] == 'undefined' && Module['read']) {
  125. Module['load'] = function load(f) {
  126. globalEval(Module['read'](f));
  127. };
  128. }
  129. if (!Module['print']) {
  130. Module['print'] = function(){};
  131. }
  132. if (!Module['printErr']) {
  133. Module['printErr'] = Module['print'];
  134. }
  135. if (!Module['arguments']) {
  136. Module['arguments'] = [];
  137. }
  138. // *** Environment setup code ***
  139. // Closure helpers
  140. Module.print = Module['print'];
  141. Module.printErr = Module['printErr'];
  142. // Callbacks
  143. Module['preRun'] = [];
  144. Module['postRun'] = [];
  145. // Merge back in the overrides
  146. for (var key in moduleOverrides) {
  147. if (moduleOverrides.hasOwnProperty(key)) {
  148. Module[key] = moduleOverrides[key];
  149. }
  150. }
  151. // === Auto-generated preamble library stuff ===
  152. //========================================
  153. // Runtime code shared with compiler
  154. //========================================
  155. var Runtime = {
  156. stackSave: function () {
  157. return STACKTOP;
  158. },
  159. stackRestore: function (stackTop) {
  160. STACKTOP = stackTop;
  161. },
  162. forceAlign: function (target, quantum) {
  163. quantum = quantum || 4;
  164. if (quantum == 1) return target;
  165. if (isNumber(target) && isNumber(quantum)) {
  166. return Math.ceil(target/quantum)*quantum;
  167. } else if (isNumber(quantum) && isPowerOfTwo(quantum)) {
  168. return '(((' +target + ')+' + (quantum-1) + ')&' + -quantum + ')';
  169. }
  170. return 'Math.ceil((' + target + ')/' + quantum + ')*' + quantum;
  171. },
  172. isNumberType: function (type) {
  173. return type in Runtime.INT_TYPES || type in Runtime.FLOAT_TYPES;
  174. },
  175. isPointerType: function isPointerType(type) {
  176. return type[type.length-1] == '*';
  177. },
  178. isStructType: function isStructType(type) {
  179. if (isPointerType(type)) return false;
  180. if (isArrayType(type)) return true;
  181. if (/<?\{ ?[^}]* ?\}>?/.test(type)) return true; // { i32, i8 } etc. - anonymous struct types
  182. // See comment in isStructPointerType()
  183. return type[0] == '%';
  184. },
  185. INT_TYPES: {"i1":0,"i8":0,"i16":0,"i32":0,"i64":0},
  186. FLOAT_TYPES: {"float":0,"double":0},
  187. or64: function (x, y) {
  188. var l = (x | 0) | (y | 0);
  189. var h = (Math.round(x / 4294967296) | Math.round(y / 4294967296)) * 4294967296;
  190. return l + h;
  191. },
  192. and64: function (x, y) {
  193. var l = (x | 0) & (y | 0);
  194. var h = (Math.round(x / 4294967296) & Math.round(y / 4294967296)) * 4294967296;
  195. return l + h;
  196. },
  197. xor64: function (x, y) {
  198. var l = (x | 0) ^ (y | 0);
  199. var h = (Math.round(x / 4294967296) ^ Math.round(y / 4294967296)) * 4294967296;
  200. return l + h;
  201. },
  202. getNativeTypeSize: function (type) {
  203. switch (type) {
  204. case 'i1': case 'i8': return 1;
  205. case 'i16': return 2;
  206. case 'i32': return 4;
  207. case 'i64': return 8;
  208. case 'float': return 4;
  209. case 'double': return 8;
  210. default: {
  211. if (type[type.length-1] === '*') {
  212. return Runtime.QUANTUM_SIZE; // A pointer
  213. } else if (type[0] === 'i') {
  214. var bits = parseInt(type.substr(1));
  215. assert(bits % 8 === 0);
  216. return bits/8;
  217. } else {
  218. return 0;
  219. }
  220. }
  221. }
  222. },
  223. getNativeFieldSize: function (type) {
  224. return Math.max(Runtime.getNativeTypeSize(type), Runtime.QUANTUM_SIZE);
  225. },
  226. dedup: function dedup(items, ident) {
  227. var seen = {};
  228. if (ident) {
  229. return items.filter(function(item) {
  230. if (seen[item[ident]]) return false;
  231. seen[item[ident]] = true;
  232. return true;
  233. });
  234. } else {
  235. return items.filter(function(item) {
  236. if (seen[item]) return false;
  237. seen[item] = true;
  238. return true;
  239. });
  240. }
  241. },
  242. set: function set() {
  243. var args = typeof arguments[0] === 'object' ? arguments[0] : arguments;
  244. var ret = {};
  245. for (var i = 0; i < args.length; i++) {
  246. ret[args[i]] = 0;
  247. }
  248. return ret;
  249. },
  250. STACK_ALIGN: 8,
  251. getAlignSize: function (type, size, vararg) {
  252. // we align i64s and doubles on 64-bit boundaries, unlike x86
  253. if (vararg) return 8;
  254. if (!vararg && (type == 'i64' || type == 'double')) return 8;
  255. if (!type) return Math.min(size, 8); // align structures internally to 64 bits
  256. return Math.min(size || (type ? Runtime.getNativeFieldSize(type) : 0), Runtime.QUANTUM_SIZE);
  257. },
  258. calculateStructAlignment: function calculateStructAlignment(type) {
  259. type.flatSize = 0;
  260. type.alignSize = 0;
  261. var diffs = [];
  262. var prev = -1;
  263. var index = 0;
  264. type.flatIndexes = type.fields.map(function(field) {
  265. index++;
  266. var size, alignSize;
  267. if (Runtime.isNumberType(field) || Runtime.isPointerType(field)) {
  268. size = Runtime.getNativeTypeSize(field); // pack char; char; in structs, also char[X]s.
  269. alignSize = Runtime.getAlignSize(field, size);
  270. } else if (Runtime.isStructType(field)) {
  271. if (field[1] === '0') {
  272. // this is [0 x something]. When inside another structure like here, it must be at the end,
  273. // and it adds no size
  274. // XXX this happens in java-nbody for example... assert(index === type.fields.length, 'zero-length in the middle!');
  275. size = 0;
  276. if (Types.types[field]) {
  277. alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
  278. } else {
  279. alignSize = type.alignSize || QUANTUM_SIZE;
  280. }
  281. } else {
  282. size = Types.types[field].flatSize;
  283. alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
  284. }
  285. } else if (field[0] == 'b') {
  286. // bN, large number field, like a [N x i8]
  287. size = field.substr(1)|0;
  288. alignSize = 1;
  289. } else if (field[0] === '<') {
  290. // vector type
  291. size = alignSize = Types.types[field].flatSize; // fully aligned
  292. } else if (field[0] === 'i') {
  293. // illegal integer field, that could not be legalized because it is an internal structure field
  294. // it is ok to have such fields, if we just use them as markers of field size and nothing more complex
  295. size = alignSize = parseInt(field.substr(1))/8;
  296. assert(size % 1 === 0, 'cannot handle non-byte-size field ' + field);
  297. } else {
  298. assert(false, 'invalid type for calculateStructAlignment');
  299. }
  300. if (type.packed) alignSize = 1;
  301. type.alignSize = Math.max(type.alignSize, alignSize);
  302. var curr = Runtime.alignMemory(type.flatSize, alignSize); // if necessary, place this on aligned memory
  303. type.flatSize = curr + size;
  304. if (prev >= 0) {
  305. diffs.push(curr-prev);
  306. }
  307. prev = curr;
  308. return curr;
  309. });
  310. if (type.name_ && type.name_[0] === '[') {
  311. // arrays have 2 elements, so we get the proper difference. then we scale here. that way we avoid
  312. // allocating a potentially huge array for [999999 x i8] etc.
  313. type.flatSize = parseInt(type.name_.substr(1))*type.flatSize/2;
  314. }
  315. type.flatSize = Runtime.alignMemory(type.flatSize, type.alignSize);
  316. if (diffs.length == 0) {
  317. type.flatFactor = type.flatSize;
  318. } else if (Runtime.dedup(diffs).length == 1) {
  319. type.flatFactor = diffs[0];
  320. }
  321. type.needsFlattening = (type.flatFactor != 1);
  322. return type.flatIndexes;
  323. },
  324. generateStructInfo: function (struct, typeName, offset) {
  325. var type, alignment;
  326. if (typeName) {
  327. offset = offset || 0;
  328. type = (typeof Types === 'undefined' ? Runtime.typeInfo : Types.types)[typeName];
  329. if (!type) return null;
  330. if (type.fields.length != struct.length) {
  331. printErr('Number of named fields must match the type for ' + typeName + ': possibly duplicate struct names. Cannot return structInfo');
  332. return null;
  333. }
  334. alignment = type.flatIndexes;
  335. } else {
  336. var type = { fields: struct.map(function(item) { return item[0] }) };
  337. alignment = Runtime.calculateStructAlignment(type);
  338. }
  339. var ret = {
  340. __size__: type.flatSize
  341. };
  342. if (typeName) {
  343. struct.forEach(function(item, i) {
  344. if (typeof item === 'string') {
  345. ret[item] = alignment[i] + offset;
  346. } else {
  347. // embedded struct
  348. var key;
  349. for (var k in item) key = k;
  350. ret[key] = Runtime.generateStructInfo(item[key], type.fields[i], alignment[i]);
  351. }
  352. });
  353. } else {
  354. struct.forEach(function(item, i) {
  355. ret[item[1]] = alignment[i];
  356. });
  357. }
  358. return ret;
  359. },
  360. dynCall: function (sig, ptr, args) {
  361. if (args && args.length) {
  362. if (!args.splice) args = Array.prototype.slice.call(args);
  363. args.splice(0, 0, ptr);
  364. return Module['dynCall_' + sig].apply(null, args);
  365. } else {
  366. return Module['dynCall_' + sig].call(null, ptr);
  367. }
  368. },
  369. functionPointers: [],
  370. addFunction: function (func) {
  371. for (var i = 0; i < Runtime.functionPointers.length; i++) {
  372. if (!Runtime.functionPointers[i]) {
  373. Runtime.functionPointers[i] = func;
  374. return 2*(1 + i);
  375. }
  376. }
  377. throw 'Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS.';
  378. },
  379. removeFunction: function (index) {
  380. Runtime.functionPointers[(index-2)/2] = null;
  381. },
  382. getAsmConst: function (code, numArgs) {
  383. // code is a constant string on the heap, so we can cache these
  384. if (!Runtime.asmConstCache) Runtime.asmConstCache = {};
  385. var func = Runtime.asmConstCache[code];
  386. if (func) return func;
  387. var args = [];
  388. for (var i = 0; i < numArgs; i++) {
  389. args.push(String.fromCharCode(36) + i); // $0, $1 etc
  390. }
  391. code = Pointer_stringify(code);
  392. if (code[0] === '"') {
  393. // tolerate EM_ASM("..code..") even though EM_ASM(..code..) is correct
  394. if (code.indexOf('"', 1) === code.length-1) {
  395. code = code.substr(1, code.length-2);
  396. } else {
  397. // something invalid happened, e.g. EM_ASM("..code($0)..", input)
  398. abort('invalid EM_ASM input |' + code + '|. Please use EM_ASM(..code..) (no quotes) or EM_ASM({ ..code($0).. }, input) (to input values)');
  399. }
  400. }
  401. return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + code + ' })'); // new Function does not allow upvars in node
  402. },
  403. warnOnce: function (text) {
  404. if (!Runtime.warnOnce.shown) Runtime.warnOnce.shown = {};
  405. if (!Runtime.warnOnce.shown[text]) {
  406. Runtime.warnOnce.shown[text] = 1;
  407. Module.printErr(text);
  408. }
  409. },
  410. funcWrappers: {},
  411. getFuncWrapper: function (func, sig) {
  412. assert(sig);
  413. if (!Runtime.funcWrappers[func]) {
  414. Runtime.funcWrappers[func] = function dynCall_wrapper() {
  415. return Runtime.dynCall(sig, func, arguments);
  416. };
  417. }
  418. return Runtime.funcWrappers[func];
  419. },
  420. UTF8Processor: function () {
  421. var buffer = [];
  422. var needed = 0;
  423. this.processCChar = function (code) {
  424. code = code & 0xFF;
  425. if (buffer.length == 0) {
  426. if ((code & 0x80) == 0x00) { // 0xxxxxxx
  427. return String.fromCharCode(code);
  428. }
  429. buffer.push(code);
  430. if ((code & 0xE0) == 0xC0) { // 110xxxxx
  431. needed = 1;
  432. } else if ((code & 0xF0) == 0xE0) { // 1110xxxx
  433. needed = 2;
  434. } else { // 11110xxx
  435. needed = 3;
  436. }
  437. return '';
  438. }
  439. if (needed) {
  440. buffer.push(code);
  441. needed--;
  442. if (needed > 0) return '';
  443. }
  444. var c1 = buffer[0];
  445. var c2 = buffer[1];
  446. var c3 = buffer[2];
  447. var c4 = buffer[3];
  448. var ret;
  449. if (buffer.length == 2) {
  450. ret = String.fromCharCode(((c1 & 0x1F) << 6) | (c2 & 0x3F));
  451. } else if (buffer.length == 3) {
  452. ret = String.fromCharCode(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6) | (c3 & 0x3F));
  453. } else {
  454. // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
  455. var codePoint = ((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) |
  456. ((c3 & 0x3F) << 6) | (c4 & 0x3F);
  457. ret = String.fromCharCode(
  458. Math.floor((codePoint - 0x10000) / 0x400) + 0xD800,
  459. (codePoint - 0x10000) % 0x400 + 0xDC00);
  460. }
  461. buffer.length = 0;
  462. return ret;
  463. }
  464. this.processJSString = function processJSString(string) {
  465. string = unescape(encodeURIComponent(string));
  466. var ret = [];
  467. for (var i = 0; i < string.length; i++) {
  468. ret.push(string.charCodeAt(i));
  469. }
  470. return ret;
  471. }
  472. },
  473. stackAlloc: function (size) { var ret = STACKTOP;STACKTOP = (STACKTOP + size)|0;STACKTOP = (((STACKTOP)+7)&-8); return ret; },
  474. staticAlloc: function (size) { var ret = STATICTOP;STATICTOP = (STATICTOP + size)|0;STATICTOP = (((STATICTOP)+7)&-8); return ret; },
  475. dynamicAlloc: function (size) { var ret = DYNAMICTOP;DYNAMICTOP = (DYNAMICTOP + size)|0;DYNAMICTOP = (((DYNAMICTOP)+7)&-8); if (DYNAMICTOP >= TOTAL_MEMORY) enlargeMemory();; return ret; },
  476. alignMemory: function (size,quantum) { var ret = size = Math.ceil((size)/(quantum ? quantum : 8))*(quantum ? quantum : 8); return ret; },
  477. makeBigInt: function (low,high,unsigned) { var ret = (unsigned ? ((+((low>>>0)))+((+((high>>>0)))*(+4294967296))) : ((+((low>>>0)))+((+((high|0)))*(+4294967296)))); return ret; },
  478. GLOBAL_BASE: 8,
  479. QUANTUM_SIZE: 4,
  480. __dummy__: 0
  481. }
  482. Module['Runtime'] = Runtime;
  483. //========================================
  484. // Runtime essentials
  485. //========================================
  486. var __THREW__ = 0; // Used in checking for thrown exceptions.
  487. var ABORT = false; // whether we are quitting the application. no code should run after this. set in exit() and abort()
  488. var EXITSTATUS = 0;
  489. var undef = 0;
  490. // tempInt is used for 32-bit signed values or smaller. tempBigInt is used
  491. // for 32-bit unsigned values or more than 32 bits. TODO: audit all uses of tempInt
  492. var tempValue, tempInt, tempBigInt, tempInt2, tempBigInt2, tempPair, tempBigIntI, tempBigIntR, tempBigIntS, tempBigIntP, tempBigIntD, tempDouble, tempFloat;
  493. var tempI64, tempI64b;
  494. var tempRet0, tempRet1, tempRet2, tempRet3, tempRet4, tempRet5, tempRet6, tempRet7, tempRet8, tempRet9;
  495. function assert(condition, text) {
  496. if (!condition) {
  497. abort('Assertion failed: ' + text);
  498. }
  499. }
  500. var globalScope = this;
  501. // C calling interface. A convenient way to call C functions (in C files, or
  502. // defined with extern "C").
  503. //
  504. // Note: LLVM optimizations can inline and remove functions, after which you will not be
  505. // able to call them. Closure can also do so. To avoid that, add your function to
  506. // the exports using something like
  507. //
  508. // -s EXPORTED_FUNCTIONS='["_main", "_myfunc"]'
  509. //
  510. // @param ident The name of the C function (note that C++ functions will be name-mangled - use extern "C")
  511. // @param returnType The return type of the function, one of the JS types 'number', 'string' or 'array' (use 'number' for any C pointer, and
  512. // 'array' for JavaScript arrays and typed arrays; note that arrays are 8-bit).
  513. // @param argTypes An array of the types of arguments for the function (if there are no arguments, this can be ommitted). Types are as in returnType,
  514. // except that 'array' is not possible (there is no way for us to know the length of the array)
  515. // @param args An array of the arguments to the function, as native JS values (as in returnType)
  516. // Note that string arguments will be stored on the stack (the JS string will become a C string on the stack).
  517. // @return The return value, as a native JS value (as in returnType)
  518. function ccall(ident, returnType, argTypes, args) {
  519. return ccallFunc(getCFunc(ident), returnType, argTypes, args);
  520. }
  521. Module["ccall"] = ccall;
  522. // Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
  523. function getCFunc(ident) {
  524. try {
  525. var func = Module['_' + ident]; // closure exported function
  526. if (!func) func = eval('_' + ident); // explicit lookup
  527. } catch(e) {
  528. }
  529. assert(func, 'Cannot call unknown function ' + ident + ' (perhaps LLVM optimizations or closure removed it?)');
  530. return func;
  531. }
  532. // Internal function that does a C call using a function, not an identifier
  533. function ccallFunc(func, returnType, argTypes, args) {
  534. var stack = 0;
  535. function toC(value, type) {
  536. if (type == 'string') {
  537. if (value === null || value === undefined || value === 0) return 0; // null string
  538. value = intArrayFromString(value);
  539. type = 'array';
  540. }
  541. if (type == 'array') {
  542. if (!stack) stack = Runtime.stackSave();
  543. var ret = Runtime.stackAlloc(value.length);
  544. writeArrayToMemory(value, ret);
  545. return ret;
  546. }
  547. return value;
  548. }
  549. function fromC(value, type) {
  550. if (type == 'string') {
  551. return Pointer_stringify(value);
  552. }
  553. assert(type != 'array');
  554. return value;
  555. }
  556. var i = 0;
  557. var cArgs = args ? args.map(function(arg) {
  558. return toC(arg, argTypes[i++]);
  559. }) : [];
  560. var ret = fromC(func.apply(null, cArgs), returnType);
  561. if (stack) Runtime.stackRestore(stack);
  562. return ret;
  563. }
  564. // Returns a native JS wrapper for a C function. This is similar to ccall, but
  565. // returns a function you can call repeatedly in a normal way. For example:
  566. //
  567. // var my_function = cwrap('my_c_function', 'number', ['number', 'number']);
  568. // alert(my_function(5, 22));
  569. // alert(my_function(99, 12));
  570. //
  571. function cwrap(ident, returnType, argTypes) {
  572. var func = getCFunc(ident);
  573. return function() {
  574. return ccallFunc(func, returnType, argTypes, Array.prototype.slice.call(arguments));
  575. }
  576. }
  577. Module["cwrap"] = cwrap;
  578. // Sets a value in memory in a dynamic way at run-time. Uses the
  579. // type data. This is the same as makeSetValue, except that
  580. // makeSetValue is done at compile-time and generates the needed
  581. // code then, whereas this function picks the right code at
  582. // run-time.
  583. // Note that setValue and getValue only do *aligned* writes and reads!
  584. // Note that ccall uses JS types as for defining types, while setValue and
  585. // getValue need LLVM types ('i8', 'i32') - this is a lower-level operation
  586. function setValue(ptr, value, type, noSafe) {
  587. type = type || 'i8';
  588. if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
  589. switch(type) {
  590. case 'i1': HEAP8[(ptr)]=value; break;
  591. case 'i8': HEAP8[(ptr)]=value; break;
  592. case 'i16': HEAP16[((ptr)>>1)]=value; break;
  593. case 'i32': HEAP32[((ptr)>>2)]=value; break;
  594. case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math_abs(tempDouble))) >= (+1) ? (tempDouble > (+0) ? ((Math_min((+(Math_floor((tempDouble)/(+4294967296)))), (+4294967295)))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/(+4294967296))))))>>>0) : 0)],HEAP32[((ptr)>>2)]=tempI64[0],HEAP32[(((ptr)+(4))>>2)]=tempI64[1]); break;
  595. case 'float': HEAPF32[((ptr)>>2)]=value; break;
  596. case 'double': HEAPF64[((ptr)>>3)]=value; break;
  597. default: abort('invalid type for setValue: ' + type);
  598. }
  599. }
  600. Module['setValue'] = setValue;
  601. // Parallel to setValue.
  602. function getValue(ptr, type, noSafe) {
  603. type = type || 'i8';
  604. if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
  605. switch(type) {
  606. case 'i1': return HEAP8[(ptr)];
  607. case 'i8': return HEAP8[(ptr)];
  608. case 'i16': return HEAP16[((ptr)>>1)];
  609. case 'i32': return HEAP32[((ptr)>>2)];
  610. case 'i64': return HEAP32[((ptr)>>2)];
  611. case 'float': return HEAPF32[((ptr)>>2)];
  612. case 'double': return HEAPF64[((ptr)>>3)];
  613. default: abort('invalid type for setValue: ' + type);
  614. }
  615. return null;
  616. }
  617. Module['getValue'] = getValue;
  618. var ALLOC_NORMAL = 0; // Tries to use _malloc()
  619. var ALLOC_STACK = 1; // Lives for the duration of the current function call
  620. var ALLOC_STATIC = 2; // Cannot be freed
  621. var ALLOC_DYNAMIC = 3; // Cannot be freed except through sbrk
  622. var ALLOC_NONE = 4; // Do not allocate
  623. Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
  624. Module['ALLOC_STACK'] = ALLOC_STACK;
  625. Module['ALLOC_STATIC'] = ALLOC_STATIC;
  626. Module['ALLOC_DYNAMIC'] = ALLOC_DYNAMIC;
  627. Module['ALLOC_NONE'] = ALLOC_NONE;
  628. // allocate(): This is for internal use. You can use it yourself as well, but the interface
  629. // is a little tricky (see docs right below). The reason is that it is optimized
  630. // for multiple syntaxes to save space in generated code. So you should
  631. // normally not use allocate(), and instead allocate memory using _malloc(),
  632. // initialize it with setValue(), and so forth.
  633. // @slab: An array of data, or a number. If a number, then the size of the block to allocate,
  634. // in *bytes* (note that this is sometimes confusing: the next parameter does not
  635. // affect this!)
  636. // @types: Either an array of types, one for each byte (or 0 if no type at that position),
  637. // or a single type which is used for the entire block. This only matters if there
  638. // is initial data - if @slab is a number, then this does not matter at all and is
  639. // ignored.
  640. // @allocator: How to allocate memory, see ALLOC_*
  641. function allocate(slab, types, allocator, ptr) {
  642. var zeroinit, size;
  643. if (typeof slab === 'number') {
  644. zeroinit = true;
  645. size = slab;
  646. } else {
  647. zeroinit = false;
  648. size = slab.length;
  649. }
  650. var singleType = typeof types === 'string' ? types : null;
  651. var ret;
  652. if (allocator == ALLOC_NONE) {
  653. ret = ptr;
  654. } else {
  655. ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc, Runtime.dynamicAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length));
  656. }
  657. if (zeroinit) {
  658. var ptr = ret, stop;
  659. assert((ret & 3) == 0);
  660. stop = ret + (size & ~3);
  661. for (; ptr < stop; ptr += 4) {
  662. HEAP32[((ptr)>>2)]=0;
  663. }
  664. stop = ret + size;
  665. while (ptr < stop) {
  666. HEAP8[((ptr++)|0)]=0;
  667. }
  668. return ret;
  669. }
  670. if (singleType === 'i8') {
  671. if (slab.subarray || slab.slice) {
  672. HEAPU8.set(slab, ret);
  673. } else {
  674. HEAPU8.set(new Uint8Array(slab), ret);
  675. }
  676. return ret;
  677. }
  678. var i = 0, type, typeSize, previousType;
  679. while (i < size) {
  680. var curr = slab[i];
  681. if (typeof curr === 'function') {
  682. curr = Runtime.getFunctionIndex(curr);
  683. }
  684. type = singleType || types[i];
  685. if (type === 0) {
  686. i++;
  687. continue;
  688. }
  689. if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later
  690. setValue(ret+i, curr, type);
  691. // no need to look up size unless type changes, so cache it
  692. if (previousType !== type) {
  693. typeSize = Runtime.getNativeTypeSize(type);
  694. previousType = type;
  695. }
  696. i += typeSize;
  697. }
  698. return ret;
  699. }
  700. Module['allocate'] = allocate;
  701. function Pointer_stringify(ptr, /* optional */ length) {
  702. // TODO: use TextDecoder
  703. // Find the length, and check for UTF while doing so
  704. var hasUtf = false;
  705. var t;
  706. var i = 0;
  707. while (1) {
  708. t = HEAPU8[(((ptr)+(i))|0)];
  709. if (t >= 128) hasUtf = true;
  710. else if (t == 0 && !length) break;
  711. i++;
  712. if (length && i == length) break;
  713. }
  714. if (!length) length = i;
  715. var ret = '';
  716. if (!hasUtf) {
  717. var MAX_CHUNK = 1024; // split up into chunks, because .apply on a huge string can overflow the stack
  718. var curr;
  719. while (length > 0) {
  720. curr = String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + Math.min(length, MAX_CHUNK)));
  721. ret = ret ? ret + curr : curr;
  722. ptr += MAX_CHUNK;
  723. length -= MAX_CHUNK;
  724. }
  725. return ret;
  726. }
  727. var utf8 = new Runtime.UTF8Processor();
  728. for (i = 0; i < length; i++) {
  729. t = HEAPU8[(((ptr)+(i))|0)];
  730. ret += utf8.processCChar(t);
  731. }
  732. return ret;
  733. }
  734. Module['Pointer_stringify'] = Pointer_stringify;
  735. // Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
  736. // a copy of that string as a Javascript String object.
  737. function UTF16ToString(ptr) {
  738. var i = 0;
  739. var str = '';
  740. while (1) {
  741. var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
  742. if (codeUnit == 0)
  743. return str;
  744. ++i;
  745. // fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
  746. str += String.fromCharCode(codeUnit);
  747. }
  748. }
  749. Module['UTF16ToString'] = UTF16ToString;
  750. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  751. // null-terminated and encoded in UTF16LE form. The copy will require at most (str.length*2+1)*2 bytes of space in the HEAP.
  752. function stringToUTF16(str, outPtr) {
  753. for(var i = 0; i < str.length; ++i) {
  754. // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
  755. var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
  756. HEAP16[(((outPtr)+(i*2))>>1)]=codeUnit;
  757. }
  758. // Null-terminate the pointer to the HEAP.
  759. HEAP16[(((outPtr)+(str.length*2))>>1)]=0;
  760. }
  761. Module['stringToUTF16'] = stringToUTF16;
  762. // Given a pointer 'ptr' to a null-terminated UTF32LE-encoded string in the emscripten HEAP, returns
  763. // a copy of that string as a Javascript String object.
  764. function UTF32ToString(ptr) {
  765. var i = 0;
  766. var str = '';
  767. while (1) {
  768. var utf32 = HEAP32[(((ptr)+(i*4))>>2)];
  769. if (utf32 == 0)
  770. return str;
  771. ++i;
  772. // 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.
  773. if (utf32 >= 0x10000) {
  774. var ch = utf32 - 0x10000;
  775. str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
  776. } else {
  777. str += String.fromCharCode(utf32);
  778. }
  779. }
  780. }
  781. Module['UTF32ToString'] = UTF32ToString;
  782. // Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
  783. // null-terminated and encoded in UTF32LE form. The copy will require at most (str.length+1)*4 bytes of space in the HEAP,
  784. // but can use less, since str.length does not return the number of characters in the string, but the number of UTF-16 code units in the string.
  785. function stringToUTF32(str, outPtr) {
  786. var iChar = 0;
  787. for(var iCodeUnit = 0; iCodeUnit < str.length; ++iCodeUnit) {
  788. // 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.
  789. var codeUnit = str.charCodeAt(iCodeUnit); // possibly a lead surrogate
  790. if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
  791. var trailSurrogate = str.charCodeAt(++iCodeUnit);
  792. codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
  793. }
  794. HEAP32[(((outPtr)+(iChar*4))>>2)]=codeUnit;
  795. ++iChar;
  796. }
  797. // Null-terminate the pointer to the HEAP.
  798. HEAP32[(((outPtr)+(iChar*4))>>2)]=0;
  799. }
  800. Module['stringToUTF32'] = stringToUTF32;
  801. function demangle(func) {
  802. try {
  803. // Special-case the entry point, since its name differs from other name mangling.
  804. if (func == 'Object._main' || func == '_main') {
  805. return 'main()';
  806. }
  807. if (typeof func === 'number') func = Pointer_stringify(func);
  808. if (func[0] !== '_') return func;
  809. if (func[1] !== '_') return func; // C function
  810. if (func[2] !== 'Z') return func;
  811. switch (func[3]) {
  812. case 'n': return 'operator new()';
  813. case 'd': return 'operator delete()';
  814. }
  815. var i = 3;
  816. // params, etc.
  817. var basicTypes = {
  818. 'v': 'void',
  819. 'b': 'bool',
  820. 'c': 'char',
  821. 's': 'short',
  822. 'i': 'int',
  823. 'l': 'long',
  824. 'f': 'float',
  825. 'd': 'double',
  826. 'w': 'wchar_t',
  827. 'a': 'signed char',
  828. 'h': 'unsigned char',
  829. 't': 'unsigned short',
  830. 'j': 'unsigned int',
  831. 'm': 'unsigned long',
  832. 'x': 'long long',
  833. 'y': 'unsigned long long',
  834. 'z': '...'
  835. };
  836. function dump(x) {
  837. //return;
  838. if (x) Module.print(x);
  839. Module.print(func);
  840. var pre = '';
  841. for (var a = 0; a < i; a++) pre += ' ';
  842. Module.print (pre + '^');
  843. }
  844. var subs = [];
  845. function parseNested() {
  846. i++;
  847. if (func[i] === 'K') i++; // ignore const
  848. var parts = [];
  849. while (func[i] !== 'E') {
  850. if (func[i] === 'S') { // substitution
  851. i++;
  852. var next = func.indexOf('_', i);
  853. var num = func.substring(i, next) || 0;
  854. parts.push(subs[num] || '?');
  855. i = next+1;
  856. continue;
  857. }
  858. if (func[i] === 'C') { // constructor
  859. parts.push(parts[parts.length-1]);
  860. i += 2;
  861. continue;
  862. }
  863. var size = parseInt(func.substr(i));
  864. var pre = size.toString().length;
  865. if (!size || !pre) { i--; break; } // counter i++ below us
  866. var curr = func.substr(i + pre, size);
  867. parts.push(curr);
  868. subs.push(curr);
  869. i += pre + size;
  870. }
  871. i++; // skip E
  872. return parts;
  873. }
  874. var first = true;
  875. function parse(rawList, limit, allowVoid) { // main parser
  876. limit = limit || Infinity;
  877. var ret = '', list = [];
  878. function flushList() {
  879. return '(' + list.join(', ') + ')';
  880. }
  881. var name;
  882. if (func[i] === 'N') {
  883. // namespaced N-E
  884. name = parseNested().join('::');
  885. limit--;
  886. if (limit === 0) return rawList ? [name] : name;
  887. } else {
  888. // not namespaced
  889. if (func[i] === 'K' || (first && func[i] === 'L')) i++; // ignore const and first 'L'
  890. var size = parseInt(func.substr(i));
  891. if (size) {
  892. var pre = size.toString().length;
  893. name = func.substr(i + pre, size);
  894. i += pre + size;
  895. }
  896. }
  897. first = false;
  898. if (func[i] === 'I') {
  899. i++;
  900. var iList = parse(true);
  901. var iRet = parse(true, 1, true);
  902. ret += iRet[0] + ' ' + name + '<' + iList.join(', ') + '>';
  903. } else {
  904. ret = name;
  905. }
  906. paramLoop: while (i < func.length && limit-- > 0) {
  907. //dump('paramLoop');
  908. var c = func[i++];
  909. if (c in basicTypes) {
  910. list.push(basicTypes[c]);
  911. } else {
  912. switch (c) {
  913. case 'P': list.push(parse(true, 1, true)[0] + '*'); break; // pointer
  914. case 'R': list.push(parse(true, 1, true)[0] + '&'); break; // reference
  915. case 'L': { // literal
  916. i++; // skip basic type
  917. var end = func.indexOf('E', i);
  918. var size = end - i;
  919. list.push(func.substr(i, size));
  920. i += size + 2; // size + 'EE'
  921. break;
  922. }
  923. case 'A': { // array
  924. var size = parseInt(func.substr(i));
  925. i += size.toString().length;
  926. if (func[i] !== '_') throw '?';
  927. i++; // skip _
  928. list.push(parse(true, 1, true)[0] + ' [' + size + ']');
  929. break;
  930. }
  931. case 'E': break paramLoop;
  932. default: ret += '?' + c; break paramLoop;
  933. }
  934. }
  935. }
  936. if (!allowVoid && list.length === 1 && list[0] === 'void') list = []; // avoid (void)
  937. return rawList ? list : ret + flushList();
  938. }
  939. return parse();
  940. } catch(e) {
  941. return func;
  942. }
  943. }
  944. function demangleAll(text) {
  945. return text.replace(/__Z[\w\d_]+/g, function(x) { var y = demangle(x); return x === y ? x : (x + ' [' + y + ']') });
  946. }
  947. function stackTrace() {
  948. var stack = new Error().stack;
  949. return stack ? demangleAll(stack) : '(no stack trace available)'; // Stack trace is not available at least on IE10 and Safari 6.
  950. }
  951. // Memory management
  952. var PAGE_SIZE = 4096;
  953. function alignMemoryPage(x) {
  954. return (x+4095)&-4096;
  955. }
  956. var HEAP;
  957. var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
  958. var STATIC_BASE = 0, STATICTOP = 0, staticSealed = false; // static area
  959. var STACK_BASE = 0, STACKTOP = 0, STACK_MAX = 0; // stack area
  960. var DYNAMIC_BASE = 0, DYNAMICTOP = 0; // dynamic area handled by sbrk
  961. function enlargeMemory() {
  962. abort('Cannot enlarge memory arrays in asm.js. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value ' + TOTAL_MEMORY + ', or (2) set Module.TOTAL_MEMORY before the program runs.');
  963. }
  964. var TOTAL_STACK = Module['TOTAL_STACK'] || 5242880;
  965. var TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 419430400;
  966. var FAST_MEMORY = Module['FAST_MEMORY'] || 2097152;
  967. var totalMemory = 4096;
  968. while (totalMemory < TOTAL_MEMORY || totalMemory < 2*TOTAL_STACK) {
  969. if (totalMemory < 16*1024*1024) {
  970. totalMemory *= 2;
  971. } else {
  972. totalMemory += 16*1024*1024
  973. }
  974. }
  975. if (totalMemory !== TOTAL_MEMORY) {
  976. Module.printErr('increasing TOTAL_MEMORY to ' + totalMemory + ' to be more reasonable');
  977. TOTAL_MEMORY = totalMemory;
  978. }
  979. // Initialize the runtime's memory
  980. // check for full engine support (use string 'subarray' to avoid closure compiler confusion)
  981. assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && !!(new Int32Array(1)['subarray']) && !!(new Int32Array(1)['set']),
  982. 'Cannot fallback to non-typed array case: Code is too specialized');
  983. var buffer = new ArrayBuffer(TOTAL_MEMORY);
  984. HEAP8 = new Int8Array(buffer);
  985. HEAP16 = new Int16Array(buffer);
  986. HEAP32 = new Int32Array(buffer);
  987. HEAPU8 = new Uint8Array(buffer);
  988. HEAPU16 = new Uint16Array(buffer);
  989. HEAPU32 = new Uint32Array(buffer);
  990. HEAPF32 = new Float32Array(buffer);
  991. HEAPF64 = new Float64Array(buffer);
  992. // Endianness check (note: assumes compiler arch was little-endian)
  993. HEAP32[0] = 255;
  994. assert(HEAPU8[0] === 255 && HEAPU8[3] === 0, 'Typed arrays 2 must be run on a little-endian system');
  995. Module['HEAP'] = HEAP;
  996. Module['HEAP8'] = HEAP8;
  997. Module['HEAP16'] = HEAP16;
  998. Module['HEAP32'] = HEAP32;
  999. Module['HEAPU8'] = HEAPU8;
  1000. Module['HEAPU16'] = HEAPU16;
  1001. Module['HEAPU32'] = HEAPU32;
  1002. Module['HEAPF32'] = HEAPF32;
  1003. Module['HEAPF64'] = HEAPF64;
  1004. function callRuntimeCallbacks(callbacks) {
  1005. while(callbacks.length > 0) {
  1006. var callback = callbacks.shift();
  1007. if (typeof callback == 'function') {
  1008. callback();
  1009. continue;
  1010. }
  1011. var func = callback.func;
  1012. if (typeof func === 'number') {
  1013. if (callback.arg === undefined) {
  1014. Runtime.dynCall('v', func);
  1015. } else {
  1016. Runtime.dynCall('vi', func, [callback.arg]);
  1017. }
  1018. } else {
  1019. func(callback.arg === undefined ? null : callback.arg);
  1020. }
  1021. }
  1022. }
  1023. var __ATPRERUN__ = []; // functions called before the runtime is initialized
  1024. var __ATINIT__ = []; // functions called during startup
  1025. var __ATMAIN__ = []; // functions called when main() is to be run
  1026. var __ATEXIT__ = []; // functions called during shutdown
  1027. var __ATPOSTRUN__ = []; // functions called after the runtime has exited
  1028. var runtimeInitialized = false;
  1029. function preRun() {
  1030. // compatibility - merge in anything from Module['preRun'] at this time
  1031. if (Module['preRun']) {
  1032. if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
  1033. while (Module['preRun'].length) {
  1034. addOnPreRun(Module['preRun'].shift());
  1035. }
  1036. }
  1037. callRuntimeCallbacks(__ATPRERUN__);
  1038. }
  1039. function ensureInitRuntime() {
  1040. if (runtimeInitialized) return;
  1041. runtimeInitialized = true;
  1042. callRuntimeCallbacks(__ATINIT__);
  1043. }
  1044. function preMain() {
  1045. callRuntimeCallbacks(__ATMAIN__);
  1046. }
  1047. function exitRuntime() {
  1048. callRuntimeCallbacks(__ATEXIT__);
  1049. }
  1050. function postRun() {
  1051. // compatibility - merge in anything from Module['postRun'] at this time
  1052. if (Module['postRun']) {
  1053. if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
  1054. while (Module['postRun'].length) {
  1055. addOnPostRun(Module['postRun'].shift());
  1056. }
  1057. }
  1058. callRuntimeCallbacks(__ATPOSTRUN__);
  1059. }
  1060. function addOnPreRun(cb) {
  1061. __ATPRERUN__.unshift(cb);
  1062. }
  1063. Module['addOnPreRun'] = Module.addOnPreRun = addOnPreRun;
  1064. function addOnInit(cb) {
  1065. __ATINIT__.unshift(cb);
  1066. }
  1067. Module['addOnInit'] = Module.addOnInit = addOnInit;
  1068. function addOnPreMain(cb) {
  1069. __ATMAIN__.unshift(cb);
  1070. }
  1071. Module['addOnPreMain'] = Module.addOnPreMain = addOnPreMain;
  1072. function addOnExit(cb) {
  1073. __ATEXIT__.unshift(cb);
  1074. }
  1075. Module['addOnExit'] = Module.addOnExit = addOnExit;
  1076. function addOnPostRun(cb) {
  1077. __ATPOSTRUN__.unshift(cb);
  1078. }
  1079. Module['addOnPostRun'] = Module.addOnPostRun = addOnPostRun;
  1080. // Tools
  1081. // This processes a JS string into a C-line array of numbers, 0-terminated.
  1082. // For LLVM-originating strings, see parser.js:parseLLVMString function
  1083. function intArrayFromString(stringy, dontAddNull, length /* optional */) {
  1084. var ret = (new Runtime.UTF8Processor()).processJSString(stringy);
  1085. if (length) {
  1086. ret.length = length;
  1087. }
  1088. if (!dontAddNull) {
  1089. ret.push(0);
  1090. }
  1091. return ret;
  1092. }
  1093. Module['intArrayFromString'] = intArrayFromString;
  1094. function intArrayToString(array) {
  1095. var ret = [];
  1096. for (var i = 0; i < array.length; i++) {
  1097. var chr = array[i];
  1098. if (chr > 0xFF) {
  1099. chr &= 0xFF;
  1100. }
  1101. ret.push(String.fromCharCode(chr));
  1102. }
  1103. return ret.join('');
  1104. }
  1105. Module['intArrayToString'] = intArrayToString;
  1106. // Write a Javascript array to somewhere in the heap
  1107. function writeStringToMemory(string, buffer, dontAddNull) {
  1108. var array = intArrayFromString(string, dontAddNull);
  1109. var i = 0;
  1110. while (i < array.length) {
  1111. var chr = array[i];
  1112. HEAP8[(((buffer)+(i))|0)]=chr;
  1113. i = i + 1;
  1114. }
  1115. }
  1116. Module['writeStringToMemory'] = writeStringToMemory;
  1117. function writeArrayToMemory(array, buffer) {
  1118. for (var i = 0; i < array.length; i++) {
  1119. HEAP8[(((buffer)+(i))|0)]=array[i];
  1120. }
  1121. }
  1122. Module['writeArrayToMemory'] = writeArrayToMemory;
  1123. function writeAsciiToMemory(str, buffer, dontAddNull) {
  1124. for (var i = 0; i < str.length; i++) {
  1125. HEAP8[(((buffer)+(i))|0)]=str.charCodeAt(i);
  1126. }
  1127. if (!dontAddNull) HEAP8[(((buffer)+(str.length))|0)]=0;
  1128. }
  1129. Module['writeAsciiToMemory'] = writeAsciiToMemory;
  1130. function unSign(value, bits, ignore) {
  1131. if (value >= 0) {
  1132. return value;
  1133. }
  1134. 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
  1135. : Math.pow(2, bits) + value;
  1136. }
  1137. function reSign(value, bits, ignore) {
  1138. if (value <= 0) {
  1139. return value;
  1140. }
  1141. var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32
  1142. : Math.pow(2, bits-1);
  1143. 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
  1144. // but, in general there is no perfect solution here. With 64-bit ints, we get rounding and errors
  1145. // TODO: In i64 mode 1, resign the two parts separately and safely
  1146. value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts
  1147. }
  1148. return value;
  1149. }
  1150. // check for imul support, and also for correctness ( https://bugs.webkit.org/show_bug.cgi?id=126345 )
  1151. if (!Math['imul'] || Math['imul'](0xffffffff, 5) !== -5) Math['imul'] = function imul(a, b) {
  1152. var ah = a >>> 16;
  1153. var al = a & 0xffff;
  1154. var bh = b >>> 16;
  1155. var bl = b & 0xffff;
  1156. return (al*bl + ((ah*bl + al*bh) << 16))|0;
  1157. };
  1158. Math.imul = Math['imul'];
  1159. var Math_abs = Math.abs;
  1160. var Math_cos = Math.cos;
  1161. var Math_sin = Math.sin;
  1162. var Math_tan = Math.tan;
  1163. var Math_acos = Math.acos;
  1164. var Math_asin = Math.asin;
  1165. var Math_atan = Math.atan;
  1166. var Math_atan2 = Math.atan2;
  1167. var Math_exp = Math.exp;
  1168. var Math_log = Math.log;
  1169. var Math_sqrt = Math.sqrt;
  1170. var Math_ceil = Math.ceil;
  1171. var Math_floor = Math.floor;
  1172. var Math_pow = Math.pow;
  1173. var Math_imul = Math.imul;
  1174. var Math_fround = Math.fround;
  1175. var Math_min = Math.min;
  1176. // A counter of dependencies for calling run(). If we need to
  1177. // do asynchronous work before running, increment this and
  1178. // decrement it. Incrementing must happen in a place like
  1179. // PRE_RUN_ADDITIONS (used by emcc to add file preloading).
  1180. // Note that you can add dependencies in preRun, even though
  1181. // it happens right before run - run will be postponed until
  1182. // the dependencies are met.
  1183. var runDependencies = 0;
  1184. var runDependencyWatcher = null;
  1185. var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
  1186. function addRunDependency(id) {
  1187. runDependencies++;
  1188. if (Module['monitorRunDependencies']) {
  1189. Module['monitorRunDependencies'](runDependencies);
  1190. }
  1191. }
  1192. Module['addRunDependency'] = addRunDependency;
  1193. function removeRunDependency(id) {
  1194. runDependencies--;
  1195. if (Module['monitorRunDependencies']) {
  1196. Module['monitorRunDependencies'](runDependencies);
  1197. }
  1198. if (runDependencies == 0) {
  1199. if (runDependencyWatcher !== null) {
  1200. clearInterval(runDependencyWatcher);
  1201. runDependencyWatcher = null;
  1202. }
  1203. if (dependenciesFulfilled) {
  1204. var callback = dependenciesFulfilled;
  1205. dependenciesFulfilled = null;
  1206. callback(); // can add another dependenciesFulfilled
  1207. }
  1208. }
  1209. }
  1210. Module['removeRunDependency'] = removeRunDependency;
  1211. Module["preloadedImages"] = {}; // maps url to image data
  1212. Module["preloadedAudios"] = {}; // maps url to audio data
  1213. var memoryInitializer = null;
  1214. // === Body ===
  1215. STATIC_BASE = 8;
  1216. STATICTOP = STATIC_BASE + 28152;
  1217. var _stdout;
  1218. var _stdout=_stdout=allocate(1, "i32*", ALLOC_STATIC);
  1219. var _stdin;
  1220. var _stdin=_stdin=allocate(1, "i32*", ALLOC_STATIC);
  1221. var _stderr;
  1222. var _stderr=_stderr=allocate(1, "i32*", ALLOC_STATIC);
  1223. /* global initializers */ __ATINIT__.push({ func: function() { runPostSets() } },{ func: function() { __GLOBAL__I_a() } });
  1224. var ___dso_handle;
  1225. var ___dso_handle=___dso_handle=allocate(1, "i32*", ALLOC_STATIC);
  1226. var __ZTVN10__cxxabiv120__si_class_type_infoE;
  1227. __ZTVN10__cxxabiv120__si_class_type_infoE=allocate([0,0,0,0,104,89,0,0,16,1,0,0,10,1,0,0,70,0,0,0,166,0,0,0,10,0,0,0,10,0,0,0,2,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0], "i8", ALLOC_STATIC);;
  1228. var __ZTVN10__cxxabiv117__class_type_infoE;
  1229. __ZTVN10__cxxabiv117__class_type_infoE=allocate([0,0,0,0,120,89,0,0,16,1,0,0,90,0,0,0,70,0,0,0,166,0,0,0,10,0,0,0,30,0,0,0,4,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0], "i8", ALLOC_STATIC);;
  1230. var __ZNSt13runtime_errorC1EPKc;
  1231. var __ZNSt13runtime_errorD1Ev;
  1232. var __ZNSt12length_errorD1Ev;
  1233. var __ZNSt3__16localeC1Ev;
  1234. var __ZNSt3__16localeC1ERKS0_;
  1235. var __ZNSt3__16localeD1Ev;
  1236. var __ZNSt8bad_castC1Ev;
  1237. var __ZNSt8bad_castD1Ev;
  1238. var __ZNSt9bad_allocC1Ev;
  1239. var __ZNSt9bad_allocD1Ev;
  1240. /* memory initializer */ allocate([105,110,102,111,58,32,102,97,99,116,111,114,105,122,97,116,105,111,110,32,105,115,32,110,111,116,32,115,117,99,99,101,115,115,102,117,108,0,0,0,78,111,116,32,101,110,111,117,103,104,32,109,101,109,111,114,121,32,116,111,32,112,101,114,102,111,114,109,32,102,97,99,116,111,114,105,122,97,116,105,111,110,46,0,0,0,0,0,101,114,114,111,114,32,111,99,99,117,114,114,101,100,32,105,110,32,116,101,99,104,109,117,108,108,101,114,95,109,97,112,95,119,105,116,104,95,98,111,117,110,100,97,114,121,46,0,100,97,116,97,32,97,114,101,32,110,111,116,32,105,110,32,114,105,103,104,116,32,115,105,122,101,44,32,112,108,101,97,115,101,32,99,104,101,99,107,46,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Large files files are truncated, but you can click here to view the full file