diff options
Diffstat (limited to 'src/tools/asm2wasm.cpp')
-rw-r--r-- | src/tools/asm2wasm.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/tools/asm2wasm.cpp b/src/tools/asm2wasm.cpp index 7f1a07d1d..031b1fd23 100644 --- a/src/tools/asm2wasm.cpp +++ b/src/tools/asm2wasm.cpp @@ -21,6 +21,7 @@ #include "support/colors.h" #include "support/command-line.h" #include "support/file.h" +#include "wasm-builder.h" #include "wasm-printing.h" #include "asm2wasm.h" @@ -40,9 +41,13 @@ int main(int argc, const char *argv[]) { o->extra["output"] = argument; Colors::disable(); }) - .add("--mapped-globals", "-m", "Mapped globals", Options::Arguments::One, + .add("--mapped-globals", "-n", "Mapped globals", Options::Arguments::One, [](Options *o, const std::string &argument) { - o->extra["mapped globals"] = argument; + std::cerr << "warning: the --mapped-globals/-m option is deprecated (a mapped globals file is no longer needed as we use wasm globals)" << std::endl; + }) + .add("--mem-init", "-t", "Import a memory initialization file into the output module", Options::Arguments::One, + [](Options *o, const std::string &argument) { + o->extra["mem init"] = argument; }) .add("--total-memory", "-m", "Total memory size", Options::Arguments::One, [](Options *o, const std::string &argument) { @@ -62,10 +67,6 @@ int main(int argc, const char *argv[]) { }); options.parse(argc, argv); - const auto &mg_it = options.extra.find("mapped globals"); - const char *mappedGlobals = - mg_it == options.extra.end() ? nullptr : mg_it->second.c_str(); - const auto &tm_it = options.extra.find("total memory"); size_t totalMemory = tm_it == options.extra.end() ? 16 * 1024 * 1024 : atoi(tm_it->second.c_str()); @@ -95,15 +96,18 @@ int main(int argc, const char *argv[]) { Asm2WasmBuilder asm2wasm(wasm, pre.memoryGrowth, options.debug, imprecise, opts); asm2wasm.processAsm(asmjs); + // import mem init file, if provided + const auto &memInit = options.extra.find("mem init"); + if (memInit != options.extra.end()) { + auto filename = memInit->second.c_str(); + auto data(read_file<std::vector<char>>(filename, Flags::Binary, options.debug ? Flags::Debug : Flags::Release)); + // create the memory segment + wasm.memory.segments.emplace_back(Builder(wasm).makeGetGlobal(Name("memoryBase"), i32), data); + } + if (options.debug) std::cerr << "printing..." << std::endl; Output output(options.extra["output"], Flags::Text, options.debug ? Flags::Debug : Flags::Release); WasmPrinter::printModule(&wasm, output.getStream()); - if (mappedGlobals) { - if (options.debug) - std::cerr << "serializing mapped globals..." << std::endl; - asm2wasm.serializeMappedGlobals(mappedGlobals); - } - if (options.debug) std::cerr << "done." << std::endl; } |