Skip to content

Instantly share code, notes, and snippets.

@kripken
Created January 31, 2024 17:52
Show Gist options
  • Save kripken/f810d8024c537852e14fec469d9f298c to your computer and use it in GitHub Desktop.
Save kripken/f810d8024c537852e14fec469d9f298c to your computer and use it in GitHub Desktop.
--- a.out.js 2024-01-31 09:42:57.311326787 -0800
+++ b.out.js 2024-01-31 09:43:14.131501278 -0800
@@ -1,40 +1,38 @@
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;
-
var scriptDirectory = "";
function locateFile(path) {
if (Module["locateFile"]) {
return Module["locateFile"](path, scriptDirectory);
}
return scriptDirectory + path;
}
var read_, readAsync, readBinary;
if (ENVIRONMENT_IS_NODE) {
var fs = require("fs");
var nodePath = require("path");
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = nodePath.dirname(scriptDirectory) + "/";
} else {
scriptDirectory = __dirname + "/";
}
read_ = (filename, binary) => {
@@ -135,40 +133,68 @@
/** @suppress{duplicate, const} */ var WebAssembly = {
/** @constructor */ Memory: function(opts) {
this.buffer = new ArrayBuffer(opts["initial"] * 65536);
},
Module: function(binary) {},
/** @constructor */ Instance: function(module, info) {
this.exports = (
// EMSCRIPTEN_START_ASM
function instantiate(info) {
function Table(ret) {
// grow method not included; table is not growable
ret.set = function(i, func) {
this[i] = func;
};
ret.get = function(i) {
return this[i];
};
return ret;
}
+ var bufferView;
+ var base64ReverseLookup = new Uint8Array(123/*'z'+1*/);
+ for (var i = 25; i >= 0; --i) {
+ base64ReverseLookup[48+i] = 52+i; // '0-9'
+ base64ReverseLookup[65+i] = i; // 'A-Z'
+ base64ReverseLookup[97+i] = 26+i; // 'a-z'
+ }
+ base64ReverseLookup[43] = 62; // '+'
+ base64ReverseLookup[47] = 63; // '/'
+ /** @noinline Inlining this function would mean expanding the base64 string 4x times in the source code, which Closure seems to be happy to do. */
+ function base64DecodeToExistingUint8Array(uint8Array, offset, b64) {
+ var b1, b2, i = 0, j = offset, bLength = b64.length, end = offset + (bLength*3>>2) - (b64[bLength-2] == '=') - (b64[bLength-1] == '=');
+ for (; i < bLength; i += 4) {
+ b1 = base64ReverseLookup[b64.charCodeAt(i+1)];
+ b2 = base64ReverseLookup[b64.charCodeAt(i+2)];
+ uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4;
+ if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2;
+ if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)];
+ }
+ }
+function initActiveSegments(imports) {
+ base64DecodeToExistingUint8Array(bufferView, 1024, "aGVsbG8sIHdvcmxkIQ==");
+ base64DecodeToExistingUint8Array(bufferView, 1040, "BQ==");
+ base64DecodeToExistingUint8Array(bufferView, 1052, "AQ==");
+ base64DecodeToExistingUint8Array(bufferView, 1076, "AgAAAAMAAACoBAAAAAQ=");
+ base64DecodeToExistingUint8Array(bufferView, 1100, "AQ==");
+ base64DecodeToExistingUint8Array(bufferView, 1116, "/////wo=");
+}
function asmFunc(imports) {
var buffer = new ArrayBuffer(16777216);
var HEAP8 = new Int8Array(buffer);
var HEAP16 = new Int16Array(buffer);
var HEAP32 = new Int32Array(buffer);
var HEAPU8 = new Uint8Array(buffer);
var HEAPU16 = new Uint16Array(buffer);
var HEAPU32 = new Uint32Array(buffer);
var HEAPF32 = new Float32Array(buffer);
var HEAPF64 = new Float64Array(buffer);
var Math_imul = Math.imul;
var Math_fround = Math.fround;
var Math_abs = Math.abs;
var Math_clz32 = Math.clz32;
var Math_min = Math.min;
var Math_max = Math.max;
var Math_floor = Math.floor;
var Math_ceil = Math.ceil;
var Math_trunc = Math.trunc;
var Math_sqrt = Math.sqrt;
@@ -545,40 +571,42 @@
function __emscripten_stdout_close($0) {
$0 = $0 | 0;
return 0;
}
function stackRestore($0) {
$0 = $0 | 0;
__stack_pointer = $0;
}
function stackSave() {
return __stack_pointer | 0;
}
function __wasm_call_ctors() {}
// EMSCRIPTEN_END_FUNCS
;
+ bufferView = HEAPU8;
+ initActiveSegments(imports);
var FUNCTION_TABLE = Table([null, __emscripten_stdout_close, __stdio_write, __emscripten_stdout_seek]);
function __wasm_memory_size() {
return buffer.byteLength / 65536 | 0;
}
return {
"memory": Object.create(Object.prototype, {
"grow": {
},
"buffer": {
"get": function () {
return buffer;
}
}
}),
"__wasm_call_ctors": __wasm_call_ctors,
"main": main,
"__indirect_function_table": FUNCTION_TABLE,
@@ -598,40 +626,60 @@
},
instantiate: /** @suppress{checkTypes} */ function(binary, info) {
return {
then: function(ok) {
var module = new WebAssembly.Module(binary);
ok({
"instance": new WebAssembly.Instance(module, info)
});
}
};
},
RuntimeError: Error
};
wasmBinary = [];
if (typeof WebAssembly != "object") {
abort("no native wasm support detected");
}
+function intArrayFromBase64(s) {
+ if (typeof ENVIRONMENT_IS_NODE != "undefined" && ENVIRONMENT_IS_NODE) {
+ var buf = Buffer.from(s, "base64");
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
+ }
+ var decoded = atob(s);
+ var bytes = new Uint8Array(decoded.length);
+ for (var i = 0; i < decoded.length; ++i) {
+ bytes[i] = decoded.charCodeAt(i);
+ }
+ return bytes;
+}
+
+function tryParseAsDataURI(filename) {
+ if (!isDataURI(filename)) {
+ return;
+ }
+ return intArrayFromBase64(filename.slice(dataURIPrefix.length));
+}
+
var wasmMemory;
var ABORT = false;
var EXITSTATUS;
var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /** @type {!Float64Array} */ HEAPF64;
function updateMemoryViews() {
var b = wasmMemory.buffer;
Module["HEAP8"] = HEAP8 = new Int8Array(b);
Module["HEAP16"] = HEAP16 = new Int16Array(b);
Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
Module["HEAPU16"] = HEAPU16 = new Uint16Array(b);
Module["HEAP32"] = HEAP32 = new Int32Array(b);
Module["HEAPU32"] = HEAPU32 = new Uint32Array(b);
Module["HEAPF32"] = HEAPF32 = new Float32Array(b);
Module["HEAPF64"] = HEAPF64 = new Float64Array(b);
}
@@ -721,58 +769,62 @@
EXITSTATUS = 1;
what += ". Build with -sASSERTIONS for more info.";
/** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what);
throw e;
}
var dataURIPrefix = "data:application/octet-stream;base64,";
/**
* Indicates whether filename is a base64 data URI.
* @noinline
*/ var isDataURI = filename => filename.startsWith(dataURIPrefix);
/**
* Indicates whether filename is delivered via file protocol (as opposed to http/https)
* @noinline
*/ var isFileURI = filename => filename.startsWith("file://");
var wasmBinaryFile;
-wasmBinaryFile = "a.out.wasm";
+wasmBinaryFile = "b.out.wasm";
if (!isDataURI(wasmBinaryFile)) {
wasmBinaryFile = locateFile(wasmBinaryFile);
}
function getBinarySync(file) {
if (file == wasmBinaryFile && wasmBinary) {
return new Uint8Array(wasmBinary);
}
+ var binary = tryParseAsDataURI(file);
+ if (binary) {
+ return binary;
+ }
if (readBinary) {
return readBinary(file);
}
throw "both async and sync fetching of the wasm failed";
}
function getBinaryPromise(binaryFile) {
- if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
+ if (!wasmBinary && !isDataURI(binaryFile) && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER)) {
if (typeof fetch == "function" && !isFileURI(binaryFile)) {
return fetch(binaryFile, {
credentials: "same-origin"
}).then(response => {
if (!response["ok"]) {
throw `failed to load wasm binary file at '${binaryFile}'`;
}
return response["arrayBuffer"]();
}).catch(() => getBinarySync(binaryFile));
} else if (readAsync) {
return new Promise((resolve, reject) => {
readAsync(binaryFile, response => resolve(new Uint8Array(/** @type{!ArrayBuffer} */ (response))), reject);
});
}
}
return Promise.resolve().then(() => getBinarySync(binaryFile));
}
function instantiateArrayBuffer(binaryFile, imports, receiver) {
return getBinaryPromise(binaryFile).then(binary => WebAssembly.instantiate(binary, imports)).then(instance => instance).then(receiver, reason => {
@@ -789,106 +841,60 @@
/** @suppress {checkTypes} */ var result = WebAssembly.instantiateStreaming(response, imports);
return result.then(callback, function(reason) {
err(`wasm streaming compile failed: ${reason}`);
err("falling back to ArrayBuffer instantiation");
return instantiateArrayBuffer(binaryFile, imports, callback);
});
});
}
return instantiateArrayBuffer(binaryFile, imports, callback);
}
function createWasm() {
var info = {
"env": wasmImports,
"wasi_snapshot_preview1": wasmImports
};
/** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) {
wasmExports = instance.exports;
wasmMemory = wasmExports["memory"];
updateMemoryViews();
- runMemoryInitializer();
addOnInit(wasmExports["__wasm_call_ctors"]);
removeRunDependency("wasm-instantiate");
return wasmExports;
}
addRunDependency("wasm-instantiate");
function receiveInstantiationResult(result) {
receiveInstance(result["instance"]);
}
if (Module["instantiateWasm"]) {
try {
return Module["instantiateWasm"](info, receiveInstance);
} catch (e) {
err(`Module.instantiateWasm callback failed with error: ${e}`);
return false;
}
}
instantiateAsync(wasmBinary, wasmBinaryFile, info, receiveInstantiationResult);
return {};
}
-var memoryInitializer = "a.out.js.mem";
-
-function runMemoryInitializer() {
- if (!isDataURI(memoryInitializer)) {
- memoryInitializer = locateFile(memoryInitializer);
- }
- if (ENVIRONMENT_IS_NODE || ENVIRONMENT_IS_SHELL) {
- var data = readBinary(memoryInitializer);
- HEAPU8.set(data, 1024);
- } else {
- addRunDependency("memory initializer");
- var applyMemoryInitializer = data => {
- if (data.byteLength) data = new Uint8Array(data);
- HEAPU8.set(data, 1024);
- if (Module["memoryInitializerRequest"]) delete Module["memoryInitializerRequest"].response;
- removeRunDependency("memory initializer");
- };
- var doBrowserLoad = () => {
- readAsync(memoryInitializer, applyMemoryInitializer, () => {
- var e = new Error("could not load memory initializer " + memoryInitializer);
- throw e;
- });
- };
- if (Module["memoryInitializerRequest"]) {
- var useRequest = () => {
- var request = Module["memoryInitializerRequest"];
- var response = request.response;
- if (request.status !== 200 && request.status !== 0) {
- console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: " + request.status + ", retrying " + memoryInitializer);
- doBrowserLoad();
- return;
- }
- applyMemoryInitializer(response);
- };
- if (Module["memoryInitializerRequest"].response) {
- setTimeout(useRequest, 0);
- } else {
- Module["memoryInitializerRequest"].addEventListener("load", useRequest);
- }
- } else {
- doBrowserLoad();
- }
- }
-}
-
/** @constructor */ function ExitStatus(status) {
this.name = "ExitStatus";
this.message = `Program terminated with exit(${status})`;
this.status = status;
}
var callRuntimeCallbacks = callbacks => {
while (callbacks.length > 0) {
callbacks.shift()(Module);
}
};
var noExitRuntime = Module["noExitRuntime"] || true;
var _emscripten_memcpy_js = (dest, src, num) => HEAPU8.copyWithin(dest, src, src + num);
var printCharBuffers = [ null, [], [] ];
var UTF8Decoder = typeof TextDecoder != "undefined" ? new TextDecoder("utf8") : undefined;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment