summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-08-28 11:17:36 -0700
committerAlon Zakai <alonzakai@gmail.com>2016-09-07 09:55:57 -0700
commitfd0160dafa25699404c1603adfcf965c75115854 (patch)
tree0a4e0d26d6821637df1885a13ed32b6a6b9fd510 /src
parent28767f631cfdae86ff16ca112bc5b1855b1368c4 (diff)
downloadbinaryen-fd0160dafa25699404c1603adfcf965c75115854.tar.gz
binaryen-fd0160dafa25699404c1603adfcf965c75115854.tar.bz2
binaryen-fd0160dafa25699404c1603adfcf965c75115854.zip
import memoryBase and tableBase
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h23
-rw-r--r--src/js/wasm.js-post.js7
-rw-r--r--src/tools/asm2wasm.cpp10
3 files changed, 29 insertions, 11 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index e27c5d9e2..0cb9b8dbe 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -840,6 +840,29 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
tableImport->base = TABLE;
tableImport->kind = Import::Table;
wasm.addImport(tableImport.release());
+
+ // Import memory offset
+ {
+ auto* import = new Import;
+ import->name = Name("memoryBase");
+ import->module = Name("env");
+ import->base = Name("memoryBase");
+ import->kind = Import::Global;
+ import->globalType = i32;
+ wasm.addImport(import);
+ }
+
+ // Import table offset
+ {
+ auto* import = new Import;
+ import->name = Name("tableBase");
+ import->module = Name("env");
+ import->base = Name("tableBase");
+ import->kind = Import::Global;
+ import->globalType = i32;
+ wasm.addImport(import);
+ }
+
#endif
#if 0 // enable asm2wasm i64 optimizations when browsers have consistent i64 support in wasm
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js
index d691c22f2..1c5e6b0b1 100644
--- a/src/js/wasm.js-post.js
+++ b/src/js/wasm.js-post.js
@@ -212,8 +212,11 @@ function integrateWasmJS(Module) {
info.global = global;
info.env = env;
- if (!('memInitBase' in env)) {
- env['memInitBase'] = STATIC_BASE; // tell the memory segments where to place themselves
+ if (!('memoryBase' in env)) {
+ env['memoryBase'] = STATIC_BASE; // tell the memory segments where to place themselves
+ }
+ if (!('tableBase' in env)) {
+ env['tableBase'] = 0; // tell the memory segments where to place themselves
}
wasmJS['providedTotalMemory'] = Module['buffer'].byteLength;
diff --git a/src/tools/asm2wasm.cpp b/src/tools/asm2wasm.cpp
index af2cf6f5a..031b1fd23 100644
--- a/src/tools/asm2wasm.cpp
+++ b/src/tools/asm2wasm.cpp
@@ -101,16 +101,8 @@ int main(int argc, const char *argv[]) {
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));
- // the mem init's base is imported
- auto* import = new Import;
- import->name = Name("memInitBase");
- import->module = Name("env");
- import->base = Name("memInitBase");
- import->kind = Import::Global;
- import->globalType = i32;
- wasm.addImport(import);
// create the memory segment
- wasm.memory.segments.emplace_back(Builder(wasm).makeGetGlobal(import->name, import->globalType), data);
+ wasm.memory.segments.emplace_back(Builder(wasm).makeGetGlobal(Name("memoryBase"), i32), data);
}
if (options.debug) std::cerr << "printing..." << std::endl;