summaryrefslogtreecommitdiff
path: root/src/wasm-js.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm-js.cpp')
-rw-r--r--src/wasm-js.cpp47
1 files changed, 4 insertions, 43 deletions
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index bd0ee51a7..fbd3031ee 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -36,47 +36,8 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm(char *input) {
wasmJSDebug = EM_ASM_INT_V({ return !!Module['outside']['WASM_JS_DEBUG'] }); // Set WASM_JS_DEBUG on the outside Module to get debugging
#endif
- // emcc --separate-asm modules look like
- //
- // Module["asm"] = (function(global, env, buffer) {
- // ..
- // });
- //
- // we need to clean that up.
- size_t num = strlen(input);
- assert(*input == 'M');
- while (*input != 'f') {
- input++;
- num--;
- }
- char *end = input + num - 1;
- while (*end != '}') {
- *end = 0;
- end--;
- }
-
- // asm.js memory growth uses a quite elaborate pattern. Instead of parsing and
- // matching it, we do a simpler detection on emscripten's asm.js output format
- bool memoryGrowth = false;
- const char* START_FUNCS = "// EMSCRIPTEN_START_FUNCS";
- char *marker = strstr(input, START_FUNCS);
- assert(marker && "must have '// EMSCRIPTEN_START_FUNCS' marker (for now)");
- *marker = 0; // look for memory growth code just up to here
- char *growthSign = strstr(input, "return true;"); // this can only show up in growth code, as normal asm.js lacks "true"
- if (growthSign) {
- memoryGrowth = true;
- // clean out this function, we don't need it
- char *growthFuncStart = strstr(input, "function ");
- assert(strstr(growthFuncStart + 1, "function ") == 0); // should be only this one function in this area, so no confusion for us
- char *growthFuncEnd = strchr(growthSign, '}');
- assert(growthFuncEnd > growthFuncStart + 5);
- growthFuncStart[0] = '/';
- growthFuncStart[1] = '*';
- growthFuncEnd--;
- growthFuncEnd[0] = '*';
- growthFuncEnd[1] = '/';
- }
- *marker = START_FUNCS[0];
+ Asm2WasmPreProcessor pre;
+ input = pre.process(input);
// proceed to parse and wasmify
if (wasmJSDebug) std::cerr << "parsing...\n";
@@ -88,13 +49,13 @@ extern "C" void EMSCRIPTEN_KEEPALIVE load_asm(char *input) {
module->memory.initial = EM_ASM_INT_V({
return Module['providedTotalMemory']; // we receive the size of memory from emscripten
});
- module->memory.max = memoryGrowth ? -1 : module->memory.initial;
+ module->memory.max = pre.memoryGrowth ? -1 : module->memory.initial;
if (wasmJSDebug) std::cerr << "wasming...\n";
asm2wasm = new Asm2WasmBuilder(*module);
asm2wasm->processAsm(asmjs);
- if (memoryGrowth) {
+ if (pre.memoryGrowth) {
// create and export a function that just calls memory growth
auto growWasmMemory = new Function();
growWasmMemory->name = GROW_WASM_MEMORY;