summaryrefslogtreecommitdiff
path: root/src/asm2wasm-main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/asm2wasm-main.cpp')
-rw-r--r--src/asm2wasm-main.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/src/asm2wasm-main.cpp b/src/asm2wasm-main.cpp
index 7c4d93052..b2b490965 100644
--- a/src/asm2wasm-main.cpp
+++ b/src/asm2wasm-main.cpp
@@ -7,10 +7,15 @@
using namespace cashew;
using namespace wasm;
+namespace wasm {
+int debug = 0;
+}
+
int main(int argc, char **argv) {
debug = getenv("ASM2WASM_DEBUG") ? getenv("ASM2WASM_DEBUG")[0] - '0' : 0;
char *infile = argv[1];
+ char *mappedGlobals = argc < 3 ? nullptr : argv[2];
if (debug) std::cerr << "loading '" << infile << "'...\n";
FILE *f = fopen(argv[1], "r");
@@ -27,33 +32,17 @@ int main(int argc, char **argv) {
fclose(f);
input[num] = 0;
- // emcc --separate-asm modules look like
- //
- // Module["asm"] = (function(global, env, buffer) {
- // ..
- // });
- //
- // we need to clean that up.
- if (*input == 'M') {
- while (*input != 'f') {
- input++;
- num--;
- }
- char *end = input + num - 1;
- while (*end != '}') {
- *end = 0;
- end--;
- }
- }
+ Asm2WasmPreProcessor pre;
+ input = pre.process(input);
if (debug) std::cerr << "parsing...\n";
cashew::Parser<Ref, DotZeroValueBuilder> builder;
Ref asmjs = builder.parseToplevel(input);
if (debug) std::cerr << "wasming...\n";
- Module wasm;
+ AllocatingModule wasm;
wasm.memory.initial = wasm.memory.max = 16*1024*1024; // we would normally receive this from the compiler
- Asm2WasmBuilder asm2wasm(wasm);
+ Asm2WasmBuilder asm2wasm(wasm, pre.memoryGrowth);
asm2wasm.processAsm(asmjs);
if (debug) std::cerr << "optimizing...\n";
@@ -62,6 +51,11 @@ int main(int argc, char **argv) {
if (debug) std::cerr << "printing...\n";
std::cout << wasm;
+ if (mappedGlobals) {
+ if (debug) std::cerr << "serializing mapped globals...\n";
+ asm2wasm.serializeMappedGlobals(mappedGlobals);
+ }
+
if (debug) std::cerr << "done.\n";
}