summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-writer.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index 6dee779d..a633717f 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -1673,17 +1673,25 @@ Result BinaryWriter::WriteModule() {
for (size_t i = 0; i < module_->funcs.size(); ++i) {
const Func* func = module_->funcs[i];
Index num_params_and_locals = func->GetNumParamsAndLocals();
+ MakeTypeBindingReverseMapping(num_params_and_locals, func->bindings,
+ &index_to_name);
+ Index num_named = 0;
+ for (auto s : index_to_name) {
+ if (!s.empty()) {
+ num_named++;
+ }
+ }
WriteU32Leb128(stream_, i, "function index");
- WriteU32Leb128(stream_, num_params_and_locals, "num locals");
+ WriteU32Leb128(stream_, num_named, "num locals");
- MakeTypeBindingReverseMapping(num_params_and_locals, func->bindings,
- &index_to_name);
for (size_t j = 0; j < num_params_and_locals; ++j) {
const std::string& name = index_to_name[j];
- wabt_snprintf(desc, sizeof(desc), "local name %" PRIzd, j);
- WriteU32Leb128(stream_, j, "local index");
- WriteDebugName(stream_, name, desc);
+ if (!name.empty()) {
+ wabt_snprintf(desc, sizeof(desc), "local name %" PRIzd, j);
+ WriteU32Leb128(stream_, j, "local index");
+ WriteDebugName(stream_, name, desc);
+ }
}
}
EndSubsection();