summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-09-07 11:09:13 -0700
committerGitHub <noreply@github.com>2021-09-07 11:09:13 -0700
commitbf21a66e1b6d68407c941a9534bc1cd76d329bf2 (patch)
tree1a925f8a580cc05bb65639450622088250c317dc
parent0ce4ebc853d89f19b22a8622304725a7bc423661 (diff)
downloadbinaryen-bf21a66e1b6d68407c941a9534bc1cd76d329bf2.tar.gz
binaryen-bf21a66e1b6d68407c941a9534bc1cd76d329bf2.tar.bz2
binaryen-bf21a66e1b6d68407c941a9534bc1cd76d329bf2.zip
wasm-split: Export the memory if it is not already (#4121)
-rw-r--r--src/tools/wasm-split/instrumenter.cpp15
-rw-r--r--test/lit/wasm-split/instrument-funcs.wast5
2 files changed, 18 insertions, 2 deletions
diff --git a/src/tools/wasm-split/instrumenter.cpp b/src/tools/wasm-split/instrumenter.cpp
index 79d6a98a4..36875bfc0 100644
--- a/src/tools/wasm-split/instrumenter.cpp
+++ b/src/tools/wasm-split/instrumenter.cpp
@@ -266,7 +266,20 @@ void Instrumenter::addProfileExport() {
}
}
- // TODO: export the memory if it is not already exported.
+ // Export the memory if it is not already exported.
+ bool memoryExported = false;
+ for (auto& ex : wasm->exports) {
+ if (ex->kind == ExternalKind::Memory) {
+ memoryExported = true;
+ break;
+ }
+ }
+ if (!memoryExported) {
+ wasm->addExport(
+ Builder::makeExport("profile-memory",
+ Names::getValidExportName(*wasm, wasm->memory.name),
+ ExternalKind::Memory));
+ }
}
} // namespace wasm
diff --git a/test/lit/wasm-split/instrument-funcs.wast b/test/lit/wasm-split/instrument-funcs.wast
index 1da68150d..cf3ca4af7 100644
--- a/test/lit/wasm-split/instrument-funcs.wast
+++ b/test/lit/wasm-split/instrument-funcs.wast
@@ -23,9 +23,12 @@
;; Check that a memory has been added
;; CHECK: (memory $0 1 1)
-;; And the profiling function exported
+;; And the profiling function is exported
;; CHECK: (export "__write_profile" (func $__write_profile))
+;; And the memory has been exported
+;; CHECK: (export "profile-memory" (memory $0))
+
;; Check that the function instrumentation is correct
;; CHECK: (func $baz (param $0 i32) (result i32)