-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathzarrosim.js
More file actions
5780 lines (5195 loc) · 188 KB
/
zarrosim.js
File metadata and controls
5780 lines (5195 loc) · 188 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var Module = typeof Module != "undefined" ? Module : {};
var moduleOverrides = Object.assign({}, Module);
var arguments_ = [];
var thisProgram = "./this.program";
var quit_ = (status, toThrow) => {
throw toThrow;
};
var ENVIRONMENT_IS_WEB = typeof window == "object";
var ENVIRONMENT_IS_WORKER = typeof importScripts == "function";
var ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process.versions == "object" && typeof process.versions.node == "string";
var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
if (Module["ENVIRONMENT"]) {
throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)");
}
var scriptDirectory = "";
function locateFile(path) {
if (Module["locateFile"]) {
return Module["locateFile"](path, scriptDirectory);
}
return scriptDirectory + path;
}
var read_, readAsync, readBinary, setWindowTitle;
function logExceptionOnExit(e) {
if (e instanceof ExitStatus) return;
let toLog = e;
if (e && typeof e == "object" && e.stack) {
toLog = [ e, e.stack ];
}
err("exiting due to exception: " + toLog);
}
var fs;
var nodePath;
var requireNodeFS;
if (ENVIRONMENT_IS_NODE) {
if (!(typeof process == "object" && typeof require == "function")) throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require("path").dirname(scriptDirectory) + "/";
} else {
scriptDirectory = __dirname + "/";
}
requireNodeFS = (() => {
if (!nodePath) {
fs = require("fs");
nodePath = require("path");
}
});
read_ = function shell_read(filename, binary) {
requireNodeFS();
filename = nodePath["normalize"](filename);
return fs.readFileSync(filename, binary ? undefined : "utf8");
};
readBinary = (filename => {
var ret = read_(filename, true);
if (!ret.buffer) {
ret = new Uint8Array(ret);
}
assert(ret.buffer);
return ret;
});
readAsync = ((filename, onload, onerror) => {
requireNodeFS();
filename = nodePath["normalize"](filename);
fs.readFile(filename, function(err, data) {
if (err) onerror(err); else onload(data.buffer);
});
});
if (process["argv"].length > 1) {
thisProgram = process["argv"][1].replace(/\\/g, "/");
}
arguments_ = process["argv"].slice(2);
if (typeof module != "undefined") {
module["exports"] = Module;
}
process["on"]("uncaughtException", function(ex) {
if (!(ex instanceof ExitStatus)) {
throw ex;
}
});
process["on"]("unhandledRejection", function(reason) {
throw reason;
});
quit_ = ((status, toThrow) => {
if (keepRuntimeAlive()) {
process["exitCode"] = status;
throw toThrow;
}
logExceptionOnExit(toThrow);
process["exit"](status);
});
Module["inspect"] = function() {
return "[Emscripten Module object]";
};
} else if (ENVIRONMENT_IS_SHELL) {
if (typeof process == "object" && typeof require === "function" || typeof window == "object" || typeof importScripts == "function") throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");
if (typeof read != "undefined") {
read_ = function shell_read(f) {
return read(f);
};
}
readBinary = function readBinary(f) {
let data;
if (typeof readbuffer == "function") {
return new Uint8Array(readbuffer(f));
}
data = read(f, "binary");
assert(typeof data == "object");
return data;
};
readAsync = function readAsync(f, onload, onerror) {
setTimeout(() => onload(readBinary(f)), 0);
};
if (typeof scriptArgs != "undefined") {
arguments_ = scriptArgs;
} else if (typeof arguments != "undefined") {
arguments_ = arguments;
}
if (typeof quit == "function") {
quit_ = ((status, toThrow) => {
logExceptionOnExit(toThrow);
quit(status);
});
}
if (typeof print != "undefined") {
if (typeof console == "undefined") console = {};
console.log = print;
console.warn = console.error = typeof printErr != "undefined" ? printErr : print;
}
} else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = self.location.href;
} else if (typeof document != "undefined" && document.currentScript) {
scriptDirectory = document.currentScript.src;
}
if (scriptDirectory.indexOf("blob:") !== 0) {
scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, "").lastIndexOf("/") + 1);
} else {
scriptDirectory = "";
}
if (!(typeof window == "object" || typeof importScripts == "function")) throw new Error("not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)");
{
read_ = (url => {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.send(null);
return xhr.responseText;
});
if (ENVIRONMENT_IS_WORKER) {
readBinary = (url => {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.responseType = "arraybuffer";
xhr.send(null);
return new Uint8Array(xhr.response);
});
}
readAsync = ((url, onload, onerror) => {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "arraybuffer";
xhr.onload = (() => {
if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
onload(xhr.response);
return;
}
onerror();
});
xhr.onerror = onerror;
xhr.send(null);
});
}
setWindowTitle = (title => document.title = title);
} else {
throw new Error("environment detection error");
}
var out = Module["print"] || console.log.bind(console);
var err = Module["printErr"] || console.warn.bind(console);
Object.assign(Module, moduleOverrides);
moduleOverrides = null;
if (Module["arguments"]) arguments_ = Module["arguments"];
if (!Object.getOwnPropertyDescriptor(Module, "arguments")) {
Object.defineProperty(Module, "arguments", {
configurable: true,
get: function() {
abort("Module.arguments has been replaced with plain arguments_ (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
if (!Object.getOwnPropertyDescriptor(Module, "thisProgram")) {
Object.defineProperty(Module, "thisProgram", {
configurable: true,
get: function() {
abort("Module.thisProgram has been replaced with plain thisProgram (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
if (Module["quit"]) quit_ = Module["quit"];
if (!Object.getOwnPropertyDescriptor(Module, "quit")) {
Object.defineProperty(Module, "quit", {
configurable: true,
get: function() {
abort("Module.quit has been replaced with plain quit_ (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
assert(typeof Module["memoryInitializerPrefixURL"] == "undefined", "Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead");
assert(typeof Module["pthreadMainPrefixURL"] == "undefined", "Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead");
assert(typeof Module["cdInitializerPrefixURL"] == "undefined", "Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead");
assert(typeof Module["filePackagePrefixURL"] == "undefined", "Module.filePackagePrefixURL option was removed, use Module.locateFile instead");
assert(typeof Module["read"] == "undefined", "Module.read option was removed (modify read_ in JS)");
assert(typeof Module["readAsync"] == "undefined", "Module.readAsync option was removed (modify readAsync in JS)");
assert(typeof Module["readBinary"] == "undefined", "Module.readBinary option was removed (modify readBinary in JS)");
assert(typeof Module["setWindowTitle"] == "undefined", "Module.setWindowTitle option was removed (modify setWindowTitle in JS)");
assert(typeof Module["TOTAL_MEMORY"] == "undefined", "Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY");
if (!Object.getOwnPropertyDescriptor(Module, "read")) {
Object.defineProperty(Module, "read", {
configurable: true,
get: function() {
abort("Module.read has been replaced with plain read_ (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
if (!Object.getOwnPropertyDescriptor(Module, "readAsync")) {
Object.defineProperty(Module, "readAsync", {
configurable: true,
get: function() {
abort("Module.readAsync has been replaced with plain readAsync (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
if (!Object.getOwnPropertyDescriptor(Module, "readBinary")) {
Object.defineProperty(Module, "readBinary", {
configurable: true,
get: function() {
abort("Module.readBinary has been replaced with plain readBinary (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
if (!Object.getOwnPropertyDescriptor(Module, "setWindowTitle")) {
Object.defineProperty(Module, "setWindowTitle", {
configurable: true,
get: function() {
abort("Module.setWindowTitle has been replaced with plain setWindowTitle (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
var IDBFS = "IDBFS is no longer included by default; build with -lidbfs.js";
var PROXYFS = "PROXYFS is no longer included by default; build with -lproxyfs.js";
var WORKERFS = "WORKERFS is no longer included by default; build with -lworkerfs.js";
var NODEFS = "NODEFS is no longer included by default; build with -lnodefs.js";
assert(!ENVIRONMENT_IS_SHELL, "shell environment detected but not enabled at build time. Add 'shell' to `-s ENVIRONMENT` to enable.");
var STACK_ALIGN = 16;
var POINTER_SIZE = 4;
function getNativeTypeSize(type) {
switch (type) {
case "i1":
case "i8":
return 1;
case "i16":
return 2;
case "i32":
return 4;
case "i64":
return 8;
case "float":
return 4;
case "double":
return 8;
default:
{
if (type[type.length - 1] === "*") {
return POINTER_SIZE;
} else if (type[0] === "i") {
const bits = Number(type.substr(1));
assert(bits % 8 === 0, "getNativeTypeSize invalid bits " + bits + ", type " + type);
return bits / 8;
} else {
return 0;
}
}
}
}
function warnOnce(text) {
if (!warnOnce.shown) warnOnce.shown = {};
if (!warnOnce.shown[text]) {
warnOnce.shown[text] = 1;
err(text);
}
}
function convertJsFunctionToWasm(func, sig) {
if (typeof WebAssembly.Function == "function") {
var typeNames = {
"i": "i32",
"j": "i64",
"f": "f32",
"d": "f64"
};
var type = {
parameters: [],
results: sig[0] == "v" ? [] : [ typeNames[sig[0]] ]
};
for (var i = 1; i < sig.length; ++i) {
type.parameters.push(typeNames[sig[i]]);
}
return new WebAssembly.Function(type, func);
}
var typeSection = [ 1, 0, 1, 96 ];
var sigRet = sig.slice(0, 1);
var sigParam = sig.slice(1);
var typeCodes = {
"i": 127,
"j": 126,
"f": 125,
"d": 124
};
typeSection.push(sigParam.length);
for (var i = 0; i < sigParam.length; ++i) {
typeSection.push(typeCodes[sigParam[i]]);
}
if (sigRet == "v") {
typeSection.push(0);
} else {
typeSection = typeSection.concat([ 1, typeCodes[sigRet] ]);
}
typeSection[1] = typeSection.length - 2;
var bytes = new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0 ].concat(typeSection, [ 2, 7, 1, 1, 101, 1, 102, 0, 0, 7, 5, 1, 1, 102, 0, 0 ]));
var module = new WebAssembly.Module(bytes);
var instance = new WebAssembly.Instance(module, {
"e": {
"f": func
}
});
var wrappedFunc = instance.exports["f"];
return wrappedFunc;
}
var freeTableIndexes = [];
var functionsInTableMap;
function getEmptyTableSlot() {
if (freeTableIndexes.length) {
return freeTableIndexes.pop();
}
try {
wasmTable.grow(1);
} catch (err) {
if (!(err instanceof RangeError)) {
throw err;
}
throw "Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.";
}
return wasmTable.length - 1;
}
function updateTableMap(offset, count) {
for (var i = offset; i < offset + count; i++) {
var item = getWasmTableEntry(i);
if (item) {
functionsInTableMap.set(item, i);
}
}
}
function addFunction(func, sig) {
assert(typeof func != "undefined");
if (!functionsInTableMap) {
functionsInTableMap = new WeakMap();
updateTableMap(0, wasmTable.length);
}
if (functionsInTableMap.has(func)) {
return functionsInTableMap.get(func);
}
for (var i = 0; i < wasmTable.length; i++) {
assert(getWasmTableEntry(i) != func, "function in Table but not functionsInTableMap");
}
var ret = getEmptyTableSlot();
try {
setWasmTableEntry(ret, func);
} catch (err) {
if (!(err instanceof TypeError)) {
throw err;
}
assert(typeof sig != "undefined", "Missing signature argument to addFunction: " + func);
var wrapped = convertJsFunctionToWasm(func, sig);
setWasmTableEntry(ret, wrapped);
}
functionsInTableMap.set(func, ret);
return ret;
}
function removeFunction(index) {
functionsInTableMap.delete(getWasmTableEntry(index));
freeTableIndexes.push(index);
}
var tempRet0 = 0;
var setTempRet0 = value => {
tempRet0 = value;
};
var getTempRet0 = () => tempRet0;
var wasmBinary;
if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
if (!Object.getOwnPropertyDescriptor(Module, "wasmBinary")) {
Object.defineProperty(Module, "wasmBinary", {
configurable: true,
get: function() {
abort("Module.wasmBinary has been replaced with plain wasmBinary (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
var noExitRuntime = Module["noExitRuntime"] || true;
if (!Object.getOwnPropertyDescriptor(Module, "noExitRuntime")) {
Object.defineProperty(Module, "noExitRuntime", {
configurable: true,
get: function() {
abort("Module.noExitRuntime has been replaced with plain noExitRuntime (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)");
}
});
}
if (typeof WebAssembly != "object") {
abort("no native wasm support detected");
}
function setValue(ptr, value, type = "i8", noSafe) {
if (type.charAt(type.length - 1) === "*") type = "i32";
if (noSafe) {
switch (type) {
case "i1":
HEAP8[ptr >> 0] = value;
break;
case "i8":
HEAP8[ptr >> 0] = value;
break;
case "i16":
HEAP16[ptr >> 1] = value;
break;
case "i32":
HEAP32[ptr >> 2] = value;
break;
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;
case "float":
HEAPF32[ptr >> 2] = value;
break;
case "double":
HEAPF64[ptr >> 3] = value;
break;
default:
abort("invalid type for setValue: " + type);
}
} else {
switch (type) {
case "i1":
SAFE_HEAP_STORE(ptr | 0, value | 0, 1);
break;
case "i8":
SAFE_HEAP_STORE(ptr | 0, value | 0, 1);
break;
case "i16":
SAFE_HEAP_STORE(ptr | 0, value | 0, 2);
break;
case "i32":
SAFE_HEAP_STORE(ptr | 0, value | 0, 4);
break;
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) ],
SAFE_HEAP_STORE(ptr | 0, tempI64[0] | 0, 4), SAFE_HEAP_STORE(ptr + 4 | 0, tempI64[1] | 0, 4);
break;
case "float":
SAFE_HEAP_STORE_D(ptr | 0, Math.fround(value), 4);
break;
case "double":
SAFE_HEAP_STORE_D(ptr | 0, +value, 8);
break;
default:
abort("invalid type for setValue: " + type);
}
}
}
function getValue(ptr, type = "i8", noSafe) {
if (type.charAt(type.length - 1) === "*") type = "i32";
if (noSafe) {
switch (type) {
case "i1":
return HEAP8[ptr >> 0];
case "i8":
return HEAP8[ptr >> 0];
case "i16":
return HEAP16[ptr >> 1];
case "i32":
return HEAP32[ptr >> 2];
case "i64":
return HEAP32[ptr >> 2];
case "float":
return HEAPF32[ptr >> 2];
case "double":
return Number(HEAPF64[ptr >> 3]);
default:
abort("invalid type for getValue: " + type);
}
} else {
switch (type) {
case "i1":
return SAFE_HEAP_LOAD(ptr | 0, 1, 0) | 0;
case "i8":
return SAFE_HEAP_LOAD(ptr | 0, 1, 0) | 0;
case "i16":
return SAFE_HEAP_LOAD(ptr | 0, 2, 0) | 0;
case "i32":
return SAFE_HEAP_LOAD(ptr | 0, 4, 0) | 0;
case "i64":
return SAFE_HEAP_LOAD(ptr | 0, 8, 0) | 0;
case "float":
return Math.fround(SAFE_HEAP_LOAD_D(ptr | 0, 4, 0));
case "double":
return +SAFE_HEAP_LOAD_D(ptr | 0, 8, 0);
default:
abort("invalid type for getValue: " + type);
}
}
return null;
}
function getSafeHeapType(bytes, isFloat) {
switch (bytes) {
case 1:
return "i8";
case 2:
return "i16";
case 4:
return isFloat ? "float" : "i32";
case 8:
return isFloat ? "double" : "i64";
default:
assert(0);
}
}
function SAFE_HEAP_STORE(dest, value, bytes, isFloat) {
if (dest <= 0) abort("segmentation fault storing " + bytes + " bytes to address " + dest);
if (dest % bytes !== 0) abort("alignment error storing to address " + dest + ", which was expected to be aligned to a multiple of " + bytes);
if (runtimeInitialized && !runtimeExited) {
var brk = _sbrk() >>> 0;
if (dest + bytes > brk) abort("segmentation fault, exceeded the top of the available dynamic heap when storing " + bytes + " bytes to address " + dest + ". DYNAMICTOP=" + brk);
assert(brk >= _emscripten_stack_get_base());
assert(brk <= HEAP8.length);
}
setValue(dest, value, getSafeHeapType(bytes, isFloat), 1);
return value;
}
function SAFE_HEAP_STORE_D(dest, value, bytes) {
return SAFE_HEAP_STORE(dest, value, bytes, true);
}
function SAFE_HEAP_LOAD(dest, bytes, unsigned, isFloat) {
if (dest <= 0) abort("segmentation fault loading " + bytes + " bytes from address " + dest);
if (dest % bytes !== 0) abort("alignment error loading from address " + dest + ", which was expected to be aligned to a multiple of " + bytes);
if (runtimeInitialized && !runtimeExited) {
var brk = _sbrk() >>> 0;
if (dest + bytes > brk) abort("segmentation fault, exceeded the top of the available dynamic heap when loading " + bytes + " bytes from address " + dest + ". DYNAMICTOP=" + brk);
assert(brk >= _emscripten_stack_get_base());
assert(brk <= HEAP8.length);
}
var type = getSafeHeapType(bytes, isFloat);
var ret = getValue(dest, type, 1);
if (unsigned) ret = unSign(ret, parseInt(type.substr(1), 10));
return ret;
}
function SAFE_HEAP_LOAD_D(dest, bytes, unsigned) {
return SAFE_HEAP_LOAD(dest, bytes, unsigned, true);
}
function SAFE_FT_MASK(value, mask) {
var ret = value & mask;
if (ret !== value) {
abort("Function table mask error: function pointer is " + value + " which is masked by " + mask + ", the likely cause of this is that the function pointer is being called by the wrong type.");
}
return ret;
}
function segfault() {
abort("segmentation fault");
}
function alignfault() {
abort("alignment fault");
}
var wasmMemory;
var ABORT = false;
var EXITSTATUS;
function assert(condition, text) {
if (!condition) {
abort("Assertion failed" + (text ? ": " + text : ""));
}
}
function getCFunc(ident) {
var func = Module["_" + ident];
assert(func, "Cannot call unknown function " + ident + ", make sure it is exported");
return func;
}
function ccall(ident, returnType, argTypes, args, opts) {
var toC = {
"string": function(str) {
var ret = 0;
if (str !== null && str !== undefined && str !== 0) {
var len = (str.length << 2) + 1;
ret = stackAlloc(len);
stringToUTF8(str, ret, len);
}
return ret;
},
"array": function(arr) {
var ret = stackAlloc(arr.length);
writeArrayToMemory(arr, ret);
return ret;
}
};
function convertReturnValue(ret) {
if (returnType === "string") return UTF8ToString(ret);
if (returnType === "boolean") return Boolean(ret);
return ret;
}
var func = getCFunc(ident);
var cArgs = [];
var stack = 0;
assert(returnType !== "array", 'Return type should not be "array".');
if (args) {
for (var i = 0; i < args.length; i++) {
var converter = toC[argTypes[i]];
if (converter) {
if (stack === 0) stack = stackSave();
cArgs[i] = converter(args[i]);
} else {
cArgs[i] = args[i];
}
}
}
var ret = func.apply(null, cArgs);
function onDone(ret) {
runtimeKeepalivePop();
if (stack !== 0) stackRestore(stack);
return convertReturnValue(ret);
}
runtimeKeepalivePush();
var asyncMode = opts && opts.async;
if (Asyncify.currData) {
assert(asyncMode, "The call to " + ident + " is running asynchronously. If this was intended, add the async option to the ccall/cwrap call.");
return Asyncify.whenDone().then(onDone);
}
ret = onDone(ret);
if (asyncMode) return Promise.resolve(ret);
return ret;
}
function cwrap(ident, returnType, argTypes, opts) {
return function() {
return ccall(ident, returnType, argTypes, arguments, opts);
};
}
var ALLOC_NORMAL = 0;
var ALLOC_STACK = 1;
function allocate(slab, allocator) {
var ret;
assert(typeof allocator == "number", "allocate no longer takes a type argument");
assert(typeof slab != "number", "allocate no longer takes a number as arg0");
if (allocator == ALLOC_STACK) {
ret = stackAlloc(slab.length);
} else {
ret = _malloc(slab.length);
}
if (!slab.subarray && !slab.slice) {
slab = new Uint8Array(slab);
}
HEAPU8.set(slab, ret);
return ret;
}
var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : undefined;
function UTF8ArrayToString(heap, idx, maxBytesToRead) {
var endIdx = idx + maxBytesToRead;
var endPtr = idx;
while (heap[endPtr] && !(endPtr >= endIdx)) ++endPtr;
if (endPtr - idx > 16 && heap.subarray && UTF8Decoder) {
return UTF8Decoder.decode(heap.subarray(idx, endPtr));
} else {
var str = "";
while (idx < endPtr) {
var u0 = heap[idx++];
if (!(u0 & 128)) {
str += String.fromCharCode(u0);
continue;
}
var u1 = heap[idx++] & 63;
if ((u0 & 224) == 192) {
str += String.fromCharCode((u0 & 31) << 6 | u1);
continue;
}
var u2 = heap[idx++] & 63;
if ((u0 & 240) == 224) {
u0 = (u0 & 15) << 12 | u1 << 6 | u2;
} else {
if ((u0 & 248) != 240) warnOnce("Invalid UTF-8 leading byte 0x" + u0.toString(16) + " encountered when deserializing a UTF-8 string in wasm memory to a JS string!");
u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heap[idx++] & 63;
}
if (u0 < 65536) {
str += String.fromCharCode(u0);
} else {
var ch = u0 - 65536;
str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
}
}
}
return str;
}
function UTF8ToString(ptr, maxBytesToRead) {
return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : "";
}
function stringToUTF8Array(str, heap, outIdx, maxBytesToWrite) {
if (!(maxBytesToWrite > 0)) return 0;
var startIdx = outIdx;
var endIdx = outIdx + maxBytesToWrite - 1;
for (var i = 0; i < str.length; ++i) {
var u = str.charCodeAt(i);
if (u >= 55296 && u <= 57343) {
var u1 = str.charCodeAt(++i);
u = 65536 + ((u & 1023) << 10) | u1 & 1023;
}
if (u <= 127) {
if (outIdx >= endIdx) break;
heap[outIdx++] = u;
} else if (u <= 2047) {
if (outIdx + 1 >= endIdx) break;
heap[outIdx++] = 192 | u >> 6;
heap[outIdx++] = 128 | u & 63;
} else if (u <= 65535) {
if (outIdx + 2 >= endIdx) break;
heap[outIdx++] = 224 | u >> 12;
heap[outIdx++] = 128 | u >> 6 & 63;
heap[outIdx++] = 128 | u & 63;
} else {
if (outIdx + 3 >= endIdx) break;
if (u > 1114111) warnOnce("Invalid Unicode code point 0x" + u.toString(16) + " encountered when serializing a JS string to a UTF-8 string in wasm memory! (Valid unicode code points should be in range 0-0x10FFFF).");
heap[outIdx++] = 240 | u >> 18;
heap[outIdx++] = 128 | u >> 12 & 63;
heap[outIdx++] = 128 | u >> 6 & 63;
heap[outIdx++] = 128 | u & 63;
}
}
heap[outIdx] = 0;
return outIdx - startIdx;
}
function stringToUTF8(str, outPtr, maxBytesToWrite) {
assert(typeof maxBytesToWrite == "number", "stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!");
return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
}
function lengthBytesUTF8(str) {
var len = 0;
for (var i = 0; i < str.length; ++i) {
var u = str.charCodeAt(i);
if (u >= 55296 && u <= 57343) u = 65536 + ((u & 1023) << 10) | str.charCodeAt(++i) & 1023;
if (u <= 127) ++len; else if (u <= 2047) len += 2; else if (u <= 65535) len += 3; else len += 4;
}
return len;
}
function AsciiToString(ptr) {
var str = "";
while (1) {
var ch = SAFE_HEAP_LOAD(ptr++ | 0, 1, 1) >>> 0;
if (!ch) return str;
str += String.fromCharCode(ch);
}
}
function stringToAscii(str, outPtr) {
return writeAsciiToMemory(str, outPtr, false);
}
var UTF16Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf-16le") : undefined;
function UTF16ToString(ptr, maxBytesToRead) {
assert(ptr % 2 == 0, "Pointer passed to UTF16ToString must be aligned to two bytes!");
var endPtr = ptr;
var idx = endPtr >> 1;
var maxIdx = idx + maxBytesToRead / 2;
while (!(idx >= maxIdx) && SAFE_HEAP_LOAD(idx * 2, 2, 1)) ++idx;
endPtr = idx << 1;
if (endPtr - ptr > 32 && UTF16Decoder) {
return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr));
} else {
var str = "";
for (var i = 0; !(i >= maxBytesToRead / 2); ++i) {
var codeUnit = SAFE_HEAP_LOAD(ptr + i * 2 | 0, 2, 0) | 0;
if (codeUnit == 0) break;
str += String.fromCharCode(codeUnit);
}
return str;
}
}
function stringToUTF16(str, outPtr, maxBytesToWrite) {
assert(outPtr % 2 == 0, "Pointer passed to stringToUTF16 must be aligned to two bytes!");
assert(typeof maxBytesToWrite == "number", "stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!");
if (maxBytesToWrite === undefined) {
maxBytesToWrite = 2147483647;
}
if (maxBytesToWrite < 2) return 0;
maxBytesToWrite -= 2;
var startPtr = outPtr;
var numCharsToWrite = maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length;
for (var i = 0; i < numCharsToWrite; ++i) {
var codeUnit = str.charCodeAt(i);
SAFE_HEAP_STORE(outPtr | 0, codeUnit | 0, 2);
outPtr += 2;
}
SAFE_HEAP_STORE(outPtr | 0, 0 | 0, 2);
return outPtr - startPtr;
}
function lengthBytesUTF16(str) {
return str.length * 2;
}
function UTF32ToString(ptr, maxBytesToRead) {
assert(ptr % 4 == 0, "Pointer passed to UTF32ToString must be aligned to four bytes!");
var i = 0;
var str = "";
while (!(i >= maxBytesToRead / 4)) {
var utf32 = SAFE_HEAP_LOAD(ptr + i * 4 | 0, 4, 0) | 0;
if (utf32 == 0) break;
++i;
if (utf32 >= 65536) {
var ch = utf32 - 65536;
str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
} else {
str += String.fromCharCode(utf32);
}
}
return str;
}
function stringToUTF32(str, outPtr, maxBytesToWrite) {
assert(outPtr % 4 == 0, "Pointer passed to stringToUTF32 must be aligned to four bytes!");
assert(typeof maxBytesToWrite == "number", "stringToUTF32(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!");
if (maxBytesToWrite === undefined) {
maxBytesToWrite = 2147483647;
}
if (maxBytesToWrite < 4) return 0;
var startPtr = outPtr;
var endPtr = startPtr + maxBytesToWrite - 4;
for (var i = 0; i < str.length; ++i) {
var codeUnit = str.charCodeAt(i);
if (codeUnit >= 55296 && codeUnit <= 57343) {
var trailSurrogate = str.charCodeAt(++i);
codeUnit = 65536 + ((codeUnit & 1023) << 10) | trailSurrogate & 1023;
}
SAFE_HEAP_STORE(outPtr | 0, codeUnit | 0, 4);
outPtr += 4;
if (outPtr + 4 > endPtr) break;
}
SAFE_HEAP_STORE(outPtr | 0, 0 | 0, 4);
return outPtr - startPtr;
}
function lengthBytesUTF32(str) {
var len = 0;
for (var i = 0; i < str.length; ++i) {
var codeUnit = str.charCodeAt(i);
if (codeUnit >= 55296 && codeUnit <= 57343) ++i;
len += 4;
}
return len;
}
function allocateUTF8(str) {
var size = lengthBytesUTF8(str) + 1;
var ret = _malloc(size);
if (ret) stringToUTF8Array(str, HEAP8, ret, size);
return ret;
}
function allocateUTF8OnStack(str) {
var size = lengthBytesUTF8(str) + 1;
var ret = stackAlloc(size);