summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 314364f38..6d4689056 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -690,7 +690,31 @@ void WasmBinaryWriter::writeNames() {
}
}
- // TODO: label, type, element and data names
+ // memory names
+ if (wasm->memory.exists) {
+ Index count = 0;
+ for (auto& seg : wasm->memory.segments) {
+ if (seg.name.is()) {
+ count++;
+ }
+ }
+
+ if (count) {
+ auto substart =
+ startSubsection(BinaryConsts::UserSections::Subsection::NameData);
+ o << U32LEB(count);
+ for (Index i = 0; i < wasm->memory.segments.size(); i++) {
+ auto& seg = wasm->memory.segments[i];
+ if (seg.name.is()) {
+ o << U32LEB(i);
+ writeEscapedName(seg.name.str);
+ }
+ }
+ finishSubsection(substart);
+ }
+ }
+
+ // TODO: label, type, and element names
// see: https://github.com/WebAssembly/extended-name-section
finishSection(start);
@@ -2566,6 +2590,20 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
<< std::to_string(index) << std::endl;
}
}
+ } else if (nameType == BinaryConsts::UserSections::Subsection::NameData) {
+ auto num = getU32LEB();
+ for (size_t i = 0; i < num; i++) {
+ auto index = getU32LEB();
+ auto rawName = getInlineString();
+ if (index < wasm.memory.segments.size()) {
+ wasm.memory.segments[i].name = rawName;
+ } else {
+ std::cerr << "warning: memory index out of bounds in name section, "
+ "memory subsection: "
+ << std::string(rawName.str) << " at index "
+ << std::to_string(index) << std::endl;
+ }
+ }
} else if (nameType == BinaryConsts::UserSections::Subsection::NameGlobal) {
auto num = getU32LEB();
std::set<Name> usedNames;