diff options
author | jgravelle-google <jgravelle@google.com> | 2016-09-09 10:41:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-09 10:41:00 -0700 |
commit | ac078dcb1c677f83527693536cb1c06157095447 (patch) | |
tree | 0e007d41a98322bbbf28b3a270558d98692a7e1a /src/tools/s2wasm.cpp | |
parent | 87f65f1623983bfc516ff4b222a3bb2537971837 (diff) | |
download | binaryen-ac078dcb1c677f83527693536cb1c06157095447.tar.gz binaryen-ac078dcb1c677f83527693536cb1c06157095447.tar.bz2 binaryen-ac078dcb1c677f83527693536cb1c06157095447.zip |
Add flag to s2wasm to export __growWasmMemory function (#696)
* Add a flag to s2wasm to export grow_memory
Binaryen's wasm.js-post.js calls back in to wasm in order to grow the
linear memory, via a function that asm2wasm exports called
__growWasmMemory.
This changes exposes that method through s2wasm when invoked with a
flag.
* Move AsmConstWalker from wasm-linker to wasm-emscripten
* Add test for memory growth in s2wasm
* Move makeDynCallThunks into wasm-emscripten module
* Move mutation in getTableSegment into a separate method
* Move emscripten metadata generation into wasm-emscripten
Also make AsmConstWalker internal to the wasm-emscripten module, as it's only used for the metadata pass.
Diffstat (limited to 'src/tools/s2wasm.cpp')
-rw-r--r-- | src/tools/s2wasm.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/tools/s2wasm.cpp b/src/tools/s2wasm.cpp index 2ee094af4..8c36a0d58 100644 --- a/src/tools/s2wasm.cpp +++ b/src/tools/s2wasm.cpp @@ -22,6 +22,7 @@ #include "support/command-line.h" #include "support/file.h" #include "s2wasm.h" +#include "wasm-emscripten.h" #include "wasm-linker.h" #include "wasm-printing.h" #include "wasm-validator.h" @@ -32,6 +33,7 @@ using namespace wasm; int main(int argc, const char *argv[]) { bool ignoreUnknownSymbols = false; bool generateEmscriptenGlue = false; + bool allowMemoryGrowth = false; std::string startFunction; std::vector<std::string> archiveLibraries; Options options("s2wasm", "Link .s file into .wast"); @@ -73,6 +75,11 @@ int main(int argc, const char *argv[]) { [](Options *o, const std::string &argument) { o->extra["max-memory"] = argument; }) + .add("--allow-memory-growth", "", "Allow linear memory to grow at runtime", + Options::Arguments::Zero, + [&allowMemoryGrowth](Options *, const std::string &) { + allowMemoryGrowth = true; + }) .add("--emscripten-glue", "-e", "Generate emscripten glue", Options::Arguments::Zero, [&generateEmscriptenGlue](Options *, const std::string &) { @@ -98,6 +105,11 @@ int main(int argc, const char *argv[]) { }); options.parse(argc, argv); + if (allowMemoryGrowth && !generateEmscriptenGlue) { + Fatal() << "Error: adding memory growth code without Emscripten glue. " + "This doesn't do anything.\n"; + } + auto debugFlag = options.debug ? Flags::Debug : Flags::Release; auto input(read_file<std::string>(options.extra["infile"], Flags::Text, debugFlag)); @@ -138,6 +150,10 @@ int main(int argc, const char *argv[]) { std::stringstream meta; if (generateEmscriptenGlue) { if (options.debug) std::cerr << "Emscripten gluing..." << std::endl; + if (allowMemoryGrowth) { + emscripten::generateMemoryGrowthFunction(linker.getOutput().wasm); + } + // dyncall thunks linker.emscriptenGlue(meta); } |