diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-10-31 17:09:27 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-10-31 17:12:47 -0700 |
commit | c8eccc4ceb1d538fc394578c23ba87bb50835b3f (patch) | |
tree | d2bab3b3499b32ad03d5229289522efbd4f34424 /src | |
parent | 119564e943fb47f081021d69a5456de8d051fe83 (diff) | |
download | binaryen-c8eccc4ceb1d538fc394578c23ba87bb50835b3f.tar.gz binaryen-c8eccc4ceb1d538fc394578c23ba87bb50835b3f.tar.bz2 binaryen-c8eccc4ceb1d538fc394578c23ba87bb50835b3f.zip |
add a --memory-base options to asm2wasm, to fix the memory base instead of depending on an import
Diffstat (limited to 'src')
-rw-r--r-- | src/tools/asm2wasm.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/tools/asm2wasm.cpp b/src/tools/asm2wasm.cpp index def361066..6761ed28a 100644 --- a/src/tools/asm2wasm.cpp +++ b/src/tools/asm2wasm.cpp @@ -51,6 +51,10 @@ int main(int argc, const char *argv[]) { [](Options *o, const std::string &argument) { o->extra["mem init"] = argument; }) + .add("--mem-base", "-mb", "Set the location to write the memory initialization (--mem-init) file (GLOBAL_BASE in emscripten). If not provided, the memoryBase global import is used.", Options::Arguments::One, + [](Options *o, const std::string &argument) { + o->extra["mem base"] = argument; + }) .add("--total-memory", "-m", "Total memory size", Options::Arguments::One, [](Options *o, const std::string &argument) { o->extra["total memory"] = argument; @@ -104,7 +108,14 @@ int main(int argc, const char *argv[]) { 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); + Expression* init; + const auto &memBase = options.extra.find("mem base"); + if (memBase == options.extra.end()) { + init = Builder(wasm).makeGetGlobal(Name("memoryBase"), i32); + } else { + init = Builder(wasm).makeConst(Literal(int32_t(atoi(memBase->second.c_str())))); + } + wasm.memory.segments.emplace_back(init, data); } if (options.debug) std::cerr << "printing..." << std::endl; |