PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 2ms

/test/mjsunit/asm/embenchen/fannkuch.js

http://v8.googlecode.com/
JavaScript | 8439 lines | 7501 code | 441 blank | 497 comment | 2057 complexity | 4fea9a8e8b90ac81b8a16314f78f35d0 MD5 | raw file
Possible License(s): BSD-3-Clause

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

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

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