summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xauto_update_tests.py2
-rwxr-xr-xcheck.py2
-rw-r--r--src/tools/asm2wasm.cpp13
-rw-r--r--test/emcc_O2_hello_world.fromasm2
-rw-r--r--test/emcc_hello_world.fromasm2
-rw-r--r--test/empty.fromasm2
6 files changed, 19 insertions, 4 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py
index 63590f6cc..f3671b5ce 100755
--- a/auto_update_tests.py
+++ b/auto_update_tests.py
@@ -25,6 +25,8 @@ for asm in sorted(os.listdir('test')):
# test mem init importing
open('a.mem', 'wb').write(asm)
cmd += ['--mem-init=a.mem']
+ if asm[0] == 'e':
+ cmd += ['--mem-base=1024']
if 'i64' in asm or 'wasm-only' in asm:
cmd += ['--wasm-only']
print '..', asm, wasm
diff --git a/check.py b/check.py
index df9633de8..67adea9ef 100755
--- a/check.py
+++ b/check.py
@@ -370,6 +370,8 @@ for asm in tests:
# test mem init importing
open('a.mem', 'wb').write(asm)
cmd += ['--mem-init=a.mem']
+ if asm[0] == 'e':
+ cmd += ['--mem-base=1024']
if 'i64' in asm or 'wasm-only' in asm:
cmd += ['--wasm-only']
wasm = os.path.join(options.binaryen_test, wasm)
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;
diff --git a/test/emcc_O2_hello_world.fromasm b/test/emcc_O2_hello_world.fromasm
index 9646d4d62..70ff7a09e 100644
--- a/test/emcc_O2_hello_world.fromasm
+++ b/test/emcc_O2_hello_world.fromasm
@@ -33,7 +33,7 @@
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
(elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $b1 $___stdio_write $b1 $b1 $b2 $b2 $b2 $b2 $_cleanup_418 $b2 $b2 $b2)
- (data (get_global $memoryBase) "emcc_O2_hello_world.asm.js")
+ (data (i32.const 1024) "emcc_O2_hello_world.asm.js")
(global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import))
(global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import))
(global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import))
diff --git a/test/emcc_hello_world.fromasm b/test/emcc_hello_world.fromasm
index 01a30d8eb..043ad0d96 100644
--- a/test/emcc_hello_world.fromasm
+++ b/test/emcc_hello_world.fromasm
@@ -42,7 +42,7 @@
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
(elem (i32.const 0) $b0 $___stdio_close $b1 $b1 $___stdout_write $___stdio_seek $___stdio_write $b1 $b1 $b1 $b2 $b2 $b2 $b2 $b2 $_cleanup $b2 $b2)
- (data (get_global $memoryBase) "emcc_hello_world.asm.js")
+ (data (i32.const 1024) "emcc_hello_world.asm.js")
(global $STACKTOP (mut i32) (get_global $STACKTOP$asm2wasm$import))
(global $STACK_MAX (mut i32) (get_global $STACK_MAX$asm2wasm$import))
(global $tempDoublePtr (mut i32) (get_global $tempDoublePtr$asm2wasm$import))
diff --git a/test/empty.fromasm b/test/empty.fromasm
index a8d289e29..a88b44007 100644
--- a/test/empty.fromasm
+++ b/test/empty.fromasm
@@ -3,5 +3,5 @@
(import "env" "table" (table 0 0 anyfunc))
(import "env" "memoryBase" (global $memoryBase i32))
(import "env" "tableBase" (global $tableBase i32))
- (data (get_global $memoryBase) "empty.asm.js")
+ (data (i32.const 1024) "empty.asm.js")
)