summaryrefslogtreecommitdiff
path: root/src/wasm
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-02-25 21:15:41 +0000
committerGitHub <noreply@github.com>2021-02-25 13:15:41 -0800
commit04c1515acb354714af3d07fe2a3b65b2bb0398ab (patch)
treee73935d0407777fe1ae2742717f00ebc4f336928 /src/wasm
parentc64a50d46cd3b5d5c19411b3ac4d8f0ba10c2efd (diff)
downloadbinaryen-04c1515acb354714af3d07fe2a3b65b2bb0398ab.tar.gz
binaryen-04c1515acb354714af3d07fe2a3b65b2bb0398ab.tar.bz2
binaryen-04c1515acb354714af3d07fe2a3b65b2bb0398ab.zip
Support Type names in the Names section (#3615)
Diffstat (limited to 'src/wasm')
-rw-r--r--src/wasm/wasm-binary.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 0ddc11320..0f5a03117 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -685,6 +685,27 @@ void WasmBinaryWriter::writeNames() {
}
}
+ // type names
+ {
+ std::vector<HeapType> namedTypes;
+ for (auto& kv : typeIndices) {
+ auto type = kv.first;
+ if (wasm->typeNames.count(type)) {
+ namedTypes.push_back(type);
+ }
+ }
+ if (!namedTypes.empty()) {
+ auto substart =
+ startSubsection(BinaryConsts::UserSections::Subsection::NameType);
+ o << U32LEB(namedTypes.size());
+ for (auto type : namedTypes) {
+ o << U32LEB(typeIndices[type]);
+ writeEscapedName(wasm->typeNames[type].name.str);
+ }
+ finishSubsection(substart);
+ }
+ }
+
// table names
{
std::vector<std::pair<Index, Table*>> tablesWithNames;
@@ -2805,6 +2826,22 @@ void WasmBinaryBuilder::readNames(size_t payloadLen) {
}
}
}
+ } else if (nameType == BinaryConsts::UserSections::Subsection::NameType) {
+ auto num = getU32LEB();
+ NameProcessor processor;
+ for (size_t i = 0; i < num; i++) {
+ auto index = getU32LEB();
+ auto rawName = getInlineString();
+ auto name = processor.process(rawName);
+ if (index < types.size()) {
+ wasm.typeNames[types[index]].name = name;
+ } else {
+ std::cerr << "warning: type index out of bounds in name section, "
+ "type subsection: "
+ << std::string(rawName.str) << " at index "
+ << std::to_string(index) << std::endl;
+ }
+ }
} else if (nameType == BinaryConsts::UserSections::Subsection::NameTable) {
auto num = getU32LEB();
NameProcessor processor;