PageRenderTime 88ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 3ms

/test/mjsunit/asm/embenchen/box2d.js

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