summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)