summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/binary-writer.cc20
-rw-r--r--test/dump/debug-names.txt42
2 files changed, 33 insertions, 29 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();
diff --git a/test/dump/debug-names.txt b/test/dump/debug-names.txt
index 2d95aaee..ebaa7585 100644
--- a/test/dump/debug-names.txt
+++ b/test/dump/debug-names.txt
@@ -87,7 +87,7 @@
0000040: 00 ; subsection size (guess)
0000041: 03 ; num functions
0000042: 00 ; function index
-0000043: 04 ; num locals
+0000043: 03 ; num locals
0000044: 00 ; local index
0000045: 04 ; string length
0000046: 4631 5030 F1P0 ; local name 0
@@ -97,28 +97,24 @@
0000050: 02 ; local index
0000051: 04 ; string length
0000052: 4631 4c32 F1L2 ; local name 2
-0000056: 03 ; local index
-0000057: 00 ; string length
-0000058: 01 ; function index
-0000059: 01 ; num locals
-000005a: 00 ; local index
-000005b: 04 ; string length
-000005c: 4632 5030 F2P0 ; local name 0
-0000060: 02 ; function index
-0000061: 04 ; num locals
-0000062: 00 ; local index
-0000063: 04 ; string length
-0000064: 4633 5030 F3P0 ; local name 0
-0000068: 01 ; local index
-0000069: 04 ; string length
-000006a: 4633 4c31 F3L1 ; local name 1
-000006e: 02 ; local index
-000006f: 00 ; string length
-0000070: 03 ; local index
-0000071: 04 ; string length
-0000072: 4633 4c33 F3L3 ; local name 3
-0000040: 35 ; FIXUP subsection size
-000002e: 47 ; FIXUP section size
+0000056: 01 ; function index
+0000057: 01 ; num locals
+0000058: 00 ; local index
+0000059: 04 ; string length
+000005a: 4632 5030 F2P0 ; local name 0
+000005e: 02 ; function index
+000005f: 03 ; num locals
+0000060: 00 ; local index
+0000061: 04 ; string length
+0000062: 4633 5030 F3P0 ; local name 0
+0000066: 01 ; local index
+0000067: 04 ; string length
+0000068: 4633 4c31 F3L1 ; local name 1
+000006c: 03 ; local index
+000006d: 04 ; string length
+000006e: 4633 4c33 F3L3 ; local name 3
+0000040: 31 ; FIXUP subsection size
+000002e: 43 ; FIXUP section size
;;; STDERR ;;)
(;; STDOUT ;;;