PageRenderTime 60ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 1ms

/test/mjsunit/asm/embenchen/fasta.js

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