no bug - Correct some typos in the comments. a=typo-fix
[gecko.git] / third_party / wasm2c / src / binary-reader-logging.cc
blob83a14e9ff766f966bb144313009d29b7034e671a
1 /*
2 * Copyright 2017 WebAssembly Community Group participants
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "wabt/binary-reader-logging.h"
19 #include <cinttypes>
21 #include "wabt/stream.h"
23 namespace wabt {
25 #define INDENT_SIZE 2
27 #define LOGF_NOINDENT(...) stream_->Writef(__VA_ARGS__)
29 #define LOGF(...) \
30 do { \
31 WriteIndent(); \
32 LOGF_NOINDENT(__VA_ARGS__); \
33 } while (0)
35 namespace {
37 void SPrintLimits(char* dst, size_t size, const Limits* limits) {
38 int result;
39 if (limits->has_max) {
40 result = wabt_snprintf(dst, size, "initial: %" PRIu64 ", max: %" PRIu64,
41 limits->initial, limits->max);
42 } else {
43 result = wabt_snprintf(dst, size, "initial: %" PRIu64, limits->initial);
45 WABT_USE(result);
46 assert(static_cast<size_t>(result) < size);
49 } // end anonymous namespace
51 BinaryReaderLogging::BinaryReaderLogging(Stream* stream,
52 BinaryReaderDelegate* forward)
53 : stream_(stream), reader_(forward), indent_(0) {}
55 void BinaryReaderLogging::Indent() {
56 indent_ += INDENT_SIZE;
59 void BinaryReaderLogging::Dedent() {
60 indent_ -= INDENT_SIZE;
61 assert(indent_ >= 0);
64 void BinaryReaderLogging::WriteIndent() {
65 static char s_indent[] =
66 " "
67 " ";
68 static const size_t s_indent_len = sizeof(s_indent) - 1;
69 size_t i = indent_;
70 while (i > s_indent_len) {
71 stream_->WriteData(s_indent, s_indent_len);
72 i -= s_indent_len;
74 if (i > 0) {
75 stream_->WriteData(s_indent, indent_);
79 void BinaryReaderLogging::LogType(Type type) {
80 if (type.IsIndex()) {
81 LOGF_NOINDENT("typeidx[%d]", type.GetIndex());
82 } else {
83 LOGF_NOINDENT("%s", type.GetName().c_str());
87 void BinaryReaderLogging::LogTypes(Index type_count, Type* types) {
88 LOGF_NOINDENT("[");
89 for (Index i = 0; i < type_count; ++i) {
90 LogType(types[i]);
91 if (i != type_count - 1) {
92 LOGF_NOINDENT(", ");
95 LOGF_NOINDENT("]");
98 void BinaryReaderLogging::LogTypes(TypeVector& types) {
99 LogTypes(types.size(), types.data());
102 void BinaryReaderLogging::LogField(TypeMut field) {
103 if (field.mutable_) {
104 LOGF_NOINDENT("(mut ");
106 LogType(field.type);
107 if (field.mutable_) {
108 LOGF_NOINDENT(")");
112 bool BinaryReaderLogging::OnError(const Error& error) {
113 return reader_->OnError(error);
116 void BinaryReaderLogging::OnSetState(const State* s) {
117 BinaryReaderDelegate::OnSetState(s);
118 reader_->OnSetState(s);
121 Result BinaryReaderLogging::BeginModule(uint32_t version) {
122 LOGF("BeginModule(version: %u)\n", version);
123 Indent();
124 return reader_->BeginModule(version);
127 Result BinaryReaderLogging::BeginSection(Index section_index,
128 BinarySection section_type,
129 Offset size) {
130 return reader_->BeginSection(section_index, section_type, size);
133 Result BinaryReaderLogging::BeginCustomSection(Index section_index,
134 Offset size,
135 std::string_view section_name) {
136 LOGF("BeginCustomSection('" PRIstringview "', size: %" PRIzd ")\n",
137 WABT_PRINTF_STRING_VIEW_ARG(section_name), size);
138 Indent();
139 return reader_->BeginCustomSection(section_index, size, section_name);
142 Result BinaryReaderLogging::OnFuncType(Index index,
143 Index param_count,
144 Type* param_types,
145 Index result_count,
146 Type* result_types) {
147 LOGF("OnFuncType(index: %" PRIindex ", params: ", index);
148 LogTypes(param_count, param_types);
149 LOGF_NOINDENT(", results: ");
150 LogTypes(result_count, result_types);
151 LOGF_NOINDENT(")\n");
152 return reader_->OnFuncType(index, param_count, param_types, result_count,
153 result_types);
156 Result BinaryReaderLogging::OnStructType(Index index,
157 Index field_count,
158 TypeMut* fields) {
159 LOGF("OnStructType(index: %" PRIindex ", fields: ", index);
160 LOGF_NOINDENT("[");
161 for (Index i = 0; i < field_count; ++i) {
162 LogField(fields[i]);
163 if (i != field_count - 1) {
164 LOGF_NOINDENT(", ");
167 LOGF_NOINDENT("])\n");
168 return reader_->OnStructType(index, field_count, fields);
171 Result BinaryReaderLogging::OnArrayType(Index index, TypeMut field) {
172 LOGF("OnArrayType(index: %" PRIindex ", field: ", index);
173 LogField(field);
174 LOGF_NOINDENT(")\n");
175 return reader_->OnArrayType(index, field);
178 Result BinaryReaderLogging::OnImport(Index index,
179 ExternalKind kind,
180 std::string_view module_name,
181 std::string_view field_name) {
182 LOGF("OnImport(index: %" PRIindex ", kind: %s, module: \"" PRIstringview
183 "\", field: \"" PRIstringview "\")\n",
184 index, GetKindName(kind), WABT_PRINTF_STRING_VIEW_ARG(module_name),
185 WABT_PRINTF_STRING_VIEW_ARG(field_name));
186 return reader_->OnImport(index, kind, module_name, field_name);
189 Result BinaryReaderLogging::OnImportFunc(Index import_index,
190 std::string_view module_name,
191 std::string_view field_name,
192 Index func_index,
193 Index sig_index) {
194 LOGF("OnImportFunc(import_index: %" PRIindex ", func_index: %" PRIindex
195 ", sig_index: %" PRIindex ")\n",
196 import_index, func_index, sig_index);
197 return reader_->OnImportFunc(import_index, module_name, field_name,
198 func_index, sig_index);
201 Result BinaryReaderLogging::OnImportTable(Index import_index,
202 std::string_view module_name,
203 std::string_view field_name,
204 Index table_index,
205 Type elem_type,
206 const Limits* elem_limits) {
207 char buf[100];
208 SPrintLimits(buf, sizeof(buf), elem_limits);
209 LOGF("OnImportTable(import_index: %" PRIindex ", table_index: %" PRIindex
210 ", elem_type: %s, %s)\n",
211 import_index, table_index, elem_type.GetName().c_str(), buf);
212 return reader_->OnImportTable(import_index, module_name, field_name,
213 table_index, elem_type, elem_limits);
216 Result BinaryReaderLogging::OnImportMemory(Index import_index,
217 std::string_view module_name,
218 std::string_view field_name,
219 Index memory_index,
220 const Limits* page_limits) {
221 char buf[100];
222 SPrintLimits(buf, sizeof(buf), page_limits);
223 LOGF("OnImportMemory(import_index: %" PRIindex ", memory_index: %" PRIindex
224 ", %s)\n",
225 import_index, memory_index, buf);
226 return reader_->OnImportMemory(import_index, module_name, field_name,
227 memory_index, page_limits);
230 Result BinaryReaderLogging::OnImportGlobal(Index import_index,
231 std::string_view module_name,
232 std::string_view field_name,
233 Index global_index,
234 Type type,
235 bool mutable_) {
236 LOGF("OnImportGlobal(import_index: %" PRIindex ", global_index: %" PRIindex
237 ", type: %s, mutable: "
238 "%s)\n",
239 import_index, global_index, type.GetName().c_str(),
240 mutable_ ? "true" : "false");
241 return reader_->OnImportGlobal(import_index, module_name, field_name,
242 global_index, type, mutable_);
245 Result BinaryReaderLogging::OnImportTag(Index import_index,
246 std::string_view module_name,
247 std::string_view field_name,
248 Index tag_index,
249 Index sig_index) {
250 LOGF("OnImportTag(import_index: %" PRIindex ", tag_index: %" PRIindex
251 ", sig_index: %" PRIindex ")\n",
252 import_index, tag_index, sig_index);
253 return reader_->OnImportTag(import_index, module_name, field_name, tag_index,
254 sig_index);
257 Result BinaryReaderLogging::OnTable(Index index,
258 Type elem_type,
259 const Limits* elem_limits) {
260 char buf[100];
261 SPrintLimits(buf, sizeof(buf), elem_limits);
262 LOGF("OnTable(index: %" PRIindex ", elem_type: %s, %s)\n", index,
263 elem_type.GetName().c_str(), buf);
264 return reader_->OnTable(index, elem_type, elem_limits);
267 Result BinaryReaderLogging::OnMemory(Index index, const Limits* page_limits) {
268 char buf[100];
269 SPrintLimits(buf, sizeof(buf), page_limits);
270 LOGF("OnMemory(index: %" PRIindex ", %s)\n", index, buf);
271 return reader_->OnMemory(index, page_limits);
274 Result BinaryReaderLogging::BeginGlobal(Index index, Type type, bool mutable_) {
275 LOGF("BeginGlobal(index: %" PRIindex ", type: %s, mutable: %s)\n", index,
276 type.GetName().c_str(), mutable_ ? "true" : "false");
277 return reader_->BeginGlobal(index, type, mutable_);
280 Result BinaryReaderLogging::OnExport(Index index,
281 ExternalKind kind,
282 Index item_index,
283 std::string_view name) {
284 LOGF("OnExport(index: %" PRIindex ", kind: %s, item_index: %" PRIindex
285 ", name: \"" PRIstringview "\")\n",
286 index, GetKindName(kind), item_index, WABT_PRINTF_STRING_VIEW_ARG(name));
287 return reader_->OnExport(index, kind, item_index, name);
290 Result BinaryReaderLogging::BeginFunctionBody(Index value, Offset size) {
291 LOGF("BeginFunctionBody(%" PRIindex ", size:%" PRIzd ")\n", value, size);
292 return reader_->BeginFunctionBody(value, size);
295 Result BinaryReaderLogging::OnLocalDecl(Index decl_index,
296 Index count,
297 Type type) {
298 LOGF("OnLocalDecl(index: %" PRIindex ", count: %" PRIindex ", type: %s)\n",
299 decl_index, count, type.GetName().c_str());
300 return reader_->OnLocalDecl(decl_index, count, type);
303 Result BinaryReaderLogging::OnBlockExpr(Type sig_type) {
304 LOGF("OnBlockExpr(sig: ");
305 LogType(sig_type);
306 LOGF_NOINDENT(")\n");
307 return reader_->OnBlockExpr(sig_type);
310 Result BinaryReaderLogging::OnBrExpr(Index depth) {
311 LOGF("OnBrExpr(depth: %" PRIindex ")\n", depth);
312 return reader_->OnBrExpr(depth);
315 Result BinaryReaderLogging::OnBrIfExpr(Index depth) {
316 LOGF("OnBrIfExpr(depth: %" PRIindex ")\n", depth);
317 return reader_->OnBrIfExpr(depth);
320 Result BinaryReaderLogging::OnBrTableExpr(Index num_targets,
321 Index* target_depths,
322 Index default_target_depth) {
323 LOGF("OnBrTableExpr(num_targets: %" PRIindex ", depths: [", num_targets);
324 for (Index i = 0; i < num_targets; ++i) {
325 LOGF_NOINDENT("%" PRIindex, target_depths[i]);
326 if (i != num_targets - 1) {
327 LOGF_NOINDENT(", ");
330 LOGF_NOINDENT("], default: %" PRIindex ")\n", default_target_depth);
331 return reader_->OnBrTableExpr(num_targets, target_depths,
332 default_target_depth);
335 Result BinaryReaderLogging::OnF32ConstExpr(uint32_t value_bits) {
336 float value;
337 memcpy(&value, &value_bits, sizeof(value));
338 LOGF("OnF32ConstExpr(%g (0x%08x))\n", value, value_bits);
339 return reader_->OnF32ConstExpr(value_bits);
342 Result BinaryReaderLogging::OnF64ConstExpr(uint64_t value_bits) {
343 double value;
344 memcpy(&value, &value_bits, sizeof(value));
345 LOGF("OnF64ConstExpr(%g (0x%016" PRIx64 "))\n", value, value_bits);
346 return reader_->OnF64ConstExpr(value_bits);
349 Result BinaryReaderLogging::OnV128ConstExpr(v128 value_bits) {
350 LOGF("OnV128ConstExpr(0x%08x 0x%08x 0x%08x 0x%08x)\n", value_bits.u32(0),
351 value_bits.u32(1), value_bits.u32(2), value_bits.u32(3));
352 return reader_->OnV128ConstExpr(value_bits);
355 Result BinaryReaderLogging::OnI32ConstExpr(uint32_t value) {
356 LOGF("OnI32ConstExpr(%u (0x%x))\n", value, value);
357 return reader_->OnI32ConstExpr(value);
360 Result BinaryReaderLogging::OnI64ConstExpr(uint64_t value) {
361 LOGF("OnI64ConstExpr(%" PRIu64 " (0x%" PRIx64 "))\n", value, value);
362 return reader_->OnI64ConstExpr(value);
365 Result BinaryReaderLogging::OnIfExpr(Type sig_type) {
366 LOGF("OnIfExpr(sig: ");
367 LogType(sig_type);
368 LOGF_NOINDENT(")\n");
369 return reader_->OnIfExpr(sig_type);
372 Result BinaryReaderLogging::OnLoopExpr(Type sig_type) {
373 LOGF("OnLoopExpr(sig: ");
374 LogType(sig_type);
375 LOGF_NOINDENT(")\n");
376 return reader_->OnLoopExpr(sig_type);
379 Result BinaryReaderLogging::OnSelectExpr(Index result_count,
380 Type* result_types) {
381 LOGF("OnSelectExpr(return_type: ");
382 LogTypes(result_count, result_types);
383 LOGF_NOINDENT(")\n");
384 return reader_->OnSelectExpr(result_count, result_types);
387 Result BinaryReaderLogging::OnTryExpr(Type sig_type) {
388 LOGF("OnTryExpr(sig: ");
389 LogType(sig_type);
390 LOGF_NOINDENT(")\n");
391 return reader_->OnTryExpr(sig_type);
394 Result BinaryReaderLogging::OnSimdLaneOpExpr(Opcode opcode, uint64_t value) {
395 LOGF("OnSimdLaneOpExpr (lane: %" PRIu64 ")\n", value);
396 return reader_->OnSimdLaneOpExpr(opcode, value);
399 Result BinaryReaderLogging::OnSimdShuffleOpExpr(Opcode opcode, v128 value) {
400 LOGF("OnSimdShuffleOpExpr (lane: 0x%08x %08x %08x %08x)\n", value.u32(0),
401 value.u32(1), value.u32(2), value.u32(3));
402 return reader_->OnSimdShuffleOpExpr(opcode, value);
405 Result BinaryReaderLogging::BeginElemSegment(Index index,
406 Index table_index,
407 uint8_t flags) {
408 LOGF("BeginElemSegment(index: %" PRIindex ", table_index: %" PRIindex
409 ", flags: %d)\n",
410 index, table_index, flags);
411 return reader_->BeginElemSegment(index, table_index, flags);
414 Result BinaryReaderLogging::OnElemSegmentElemType(Index index, Type elem_type) {
415 LOGF("OnElemSegmentElemType(index: %" PRIindex ", type: %s)\n", index,
416 elem_type.GetName().c_str());
417 return reader_->OnElemSegmentElemType(index, elem_type);
420 Result BinaryReaderLogging::OnDataSegmentData(Index index,
421 const void* data,
422 Address size) {
423 LOGF("OnDataSegmentData(index:%" PRIindex ", size:%" PRIaddress ")\n", index,
424 size);
425 return reader_->OnDataSegmentData(index, data, size);
428 Result BinaryReaderLogging::OnModuleNameSubsection(Index index,
429 uint32_t name_type,
430 Offset subsection_size) {
431 LOGF("OnModuleNameSubsection(index:%" PRIindex ", nametype:%u, size:%" PRIzd
432 ")\n",
433 index, name_type, subsection_size);
434 return reader_->OnModuleNameSubsection(index, name_type, subsection_size);
437 Result BinaryReaderLogging::OnModuleName(std::string_view name) {
438 LOGF("OnModuleName(name: \"" PRIstringview "\")\n",
439 WABT_PRINTF_STRING_VIEW_ARG(name));
440 return reader_->OnModuleName(name);
443 Result BinaryReaderLogging::OnFunctionNameSubsection(Index index,
444 uint32_t name_type,
445 Offset subsection_size) {
446 LOGF("OnFunctionNameSubsection(index:%" PRIindex ", nametype:%u, size:%" PRIzd
447 ")\n",
448 index, name_type, subsection_size);
449 return reader_->OnFunctionNameSubsection(index, name_type, subsection_size);
452 Result BinaryReaderLogging::OnFunctionName(Index index, std::string_view name) {
453 LOGF("OnFunctionName(index: %" PRIindex ", name: \"" PRIstringview "\")\n",
454 index, WABT_PRINTF_STRING_VIEW_ARG(name));
455 return reader_->OnFunctionName(index, name);
458 Result BinaryReaderLogging::OnLocalNameSubsection(Index index,
459 uint32_t name_type,
460 Offset subsection_size) {
461 LOGF("OnLocalNameSubsection(index:%" PRIindex ", nametype:%u, size:%" PRIzd
462 ")\n",
463 index, name_type, subsection_size);
464 return reader_->OnLocalNameSubsection(index, name_type, subsection_size);
467 Result BinaryReaderLogging::OnLocalName(Index func_index,
468 Index local_index,
469 std::string_view name) {
470 LOGF("OnLocalName(func_index: %" PRIindex ", local_index: %" PRIindex
471 ", name: \"" PRIstringview "\")\n",
472 func_index, local_index, WABT_PRINTF_STRING_VIEW_ARG(name));
473 return reader_->OnLocalName(func_index, local_index, name);
476 Result BinaryReaderLogging::OnNameSubsection(
477 Index index,
478 NameSectionSubsection subsection_type,
479 Offset subsection_size) {
480 LOGF("OnNameSubsection(index: %" PRIindex ", type: %s, size:%" PRIzd ")\n",
481 index, GetNameSectionSubsectionName(subsection_type), subsection_size);
482 return reader_->OnNameSubsection(index, subsection_type, subsection_size);
485 Result BinaryReaderLogging::OnNameEntry(NameSectionSubsection type,
486 Index index,
487 std::string_view name) {
488 LOGF("OnNameEntry(type: %s, index: %" PRIindex ", name: \"" PRIstringview
489 "\")\n",
490 GetNameSectionSubsectionName(type), index,
491 WABT_PRINTF_STRING_VIEW_ARG(name));
492 return reader_->OnNameEntry(type, index, name);
495 Result BinaryReaderLogging::OnDylinkInfo(uint32_t mem_size,
496 uint32_t mem_align,
497 uint32_t table_size,
498 uint32_t table_align) {
499 LOGF(
500 "OnDylinkInfo(mem_size: %u, mem_align: %u, table_size: %u, table_align: "
501 "%u)\n",
502 mem_size, mem_align, table_size, table_align);
503 return reader_->OnDylinkInfo(mem_size, mem_align, table_size, table_align);
506 Result BinaryReaderLogging::OnDylinkNeeded(std::string_view so_name) {
507 LOGF("OnDylinkNeeded(name: " PRIstringview ")\n",
508 WABT_PRINTF_STRING_VIEW_ARG(so_name));
509 return reader_->OnDylinkNeeded(so_name);
512 Result BinaryReaderLogging::OnDylinkExport(std::string_view name,
513 uint32_t flags) {
514 LOGF("OnDylinkExport(name: " PRIstringview ", flags: 0x%x)\n",
515 WABT_PRINTF_STRING_VIEW_ARG(name), flags);
516 return reader_->OnDylinkExport(name, flags);
519 Result BinaryReaderLogging::OnDylinkImport(std::string_view module,
520 std::string_view name,
521 uint32_t flags) {
522 LOGF("OnDylinkImport(module: " PRIstringview ", name: " PRIstringview
523 ", flags: 0x%x)\n",
524 WABT_PRINTF_STRING_VIEW_ARG(module), WABT_PRINTF_STRING_VIEW_ARG(name),
525 flags);
526 return reader_->OnDylinkImport(module, name, flags);
529 Result BinaryReaderLogging::OnRelocCount(Index count, Index section_index) {
530 LOGF("OnRelocCount(count: %" PRIindex ", section: %" PRIindex ")\n", count,
531 section_index);
532 return reader_->OnRelocCount(count, section_index);
535 Result BinaryReaderLogging::OnReloc(RelocType type,
536 Offset offset,
537 Index index,
538 uint32_t addend) {
539 int32_t signed_addend = static_cast<int32_t>(addend);
540 LOGF("OnReloc(type: %s, offset: %" PRIzd ", index: %" PRIindex
541 ", addend: %d)\n",
542 GetRelocTypeName(type), offset, index, signed_addend);
543 return reader_->OnReloc(type, offset, index, addend);
546 Result BinaryReaderLogging::OnFeature(uint8_t prefix, std::string_view name) {
547 LOGF("OnFeature(prefix: '%c', name: '" PRIstringview "')\n", prefix,
548 WABT_PRINTF_STRING_VIEW_ARG(name));
549 return reader_->OnFeature(prefix, name);
552 Result BinaryReaderLogging::OnDataSymbol(Index index,
553 uint32_t flags,
554 std::string_view name,
555 Index segment,
556 uint32_t offset,
557 uint32_t size) {
558 LOGF("OnDataSymbol(name: " PRIstringview " flags: 0x%x)\n",
559 WABT_PRINTF_STRING_VIEW_ARG(name), flags);
560 return reader_->OnDataSymbol(index, flags, name, segment, offset, size);
563 Result BinaryReaderLogging::OnFunctionSymbol(Index index,
564 uint32_t flags,
565 std::string_view name,
566 Index func_index) {
567 LOGF("OnFunctionSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
568 ")\n",
569 WABT_PRINTF_STRING_VIEW_ARG(name), flags, func_index);
570 return reader_->OnFunctionSymbol(index, flags, name, func_index);
573 Result BinaryReaderLogging::OnGlobalSymbol(Index index,
574 uint32_t flags,
575 std::string_view name,
576 Index global_index) {
577 LOGF("OnGlobalSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
578 ")\n",
579 WABT_PRINTF_STRING_VIEW_ARG(name), flags, global_index);
580 return reader_->OnGlobalSymbol(index, flags, name, global_index);
583 Result BinaryReaderLogging::OnSectionSymbol(Index index,
584 uint32_t flags,
585 Index section_index) {
586 LOGF("OnSectionSymbol(flags: 0x%x index: %" PRIindex ")\n", flags,
587 section_index);
588 return reader_->OnSectionSymbol(index, flags, section_index);
591 Result BinaryReaderLogging::OnTagSymbol(Index index,
592 uint32_t flags,
593 std::string_view name,
594 Index tag_index) {
595 LOGF("OnTagSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
596 ")\n",
597 WABT_PRINTF_STRING_VIEW_ARG(name), flags, tag_index);
598 return reader_->OnTagSymbol(index, flags, name, tag_index);
601 Result BinaryReaderLogging::OnTableSymbol(Index index,
602 uint32_t flags,
603 std::string_view name,
604 Index table_index) {
605 LOGF("OnTableSymbol(name: " PRIstringview " flags: 0x%x index: %" PRIindex
606 ")\n",
607 WABT_PRINTF_STRING_VIEW_ARG(name), flags, table_index);
608 return reader_->OnTableSymbol(index, flags, name, table_index);
611 Result BinaryReaderLogging::OnSegmentInfo(Index index,
612 std::string_view name,
613 Address alignment,
614 uint32_t flags) {
615 LOGF("OnSegmentInfo(%d name: " PRIstringview ", alignment: %" PRIaddress
616 ", flags: 0x%x)\n",
617 index, WABT_PRINTF_STRING_VIEW_ARG(name), alignment, flags);
618 return reader_->OnSegmentInfo(index, name, alignment, flags);
621 Result BinaryReaderLogging::OnInitFunction(uint32_t priority,
622 Index symbol_index) {
623 LOGF("OnInitFunction(%d priority: %d)\n", symbol_index, priority);
624 return reader_->OnInitFunction(priority, symbol_index);
627 Result BinaryReaderLogging::OnComdatBegin(std::string_view name,
628 uint32_t flags,
629 Index count) {
630 LOGF("OnComdatBegin(" PRIstringview ", flags: %d, count: %" PRIindex ")\n",
631 WABT_PRINTF_STRING_VIEW_ARG(name), flags, count);
632 return reader_->OnComdatBegin(name, flags, count);
635 Result BinaryReaderLogging::OnComdatEntry(ComdatType kind, Index index) {
636 LOGF("OnComdatEntry(kind: %d, index: %" PRIindex ")\n",
637 static_cast<int>(kind), index);
638 return reader_->OnComdatEntry(kind, index);
641 Result BinaryReaderLogging::BeginCodeMetadataSection(std::string_view name,
642 Offset size) {
643 LOGF("BeginCodeMetadataSection('" PRIstringview "', size:%" PRIzd ")\n",
644 WABT_PRINTF_STRING_VIEW_ARG(name), size);
645 Indent();
646 return reader_->BeginCodeMetadataSection(name, size);
648 Result BinaryReaderLogging::OnCodeMetadata(Offset code_offset,
649 const void* data,
650 Address size) {
651 std::string_view content(static_cast<const char*>(data), size);
652 LOGF("OnCodeMetadata(offset: %" PRIzd ", data: \"" PRIstringview "\")\n",
653 code_offset, WABT_PRINTF_STRING_VIEW_ARG(content));
654 return reader_->OnCodeMetadata(code_offset, data, size);
657 #define DEFINE_BEGIN(name) \
658 Result BinaryReaderLogging::name(Offset size) { \
659 LOGF(#name "(%" PRIzd ")\n", size); \
660 Indent(); \
661 return reader_->name(size); \
664 #define DEFINE_END(name) \
665 Result BinaryReaderLogging::name() { \
666 Dedent(); \
667 LOGF(#name "\n"); \
668 return reader_->name(); \
671 #define DEFINE_INDEX(name) \
672 Result BinaryReaderLogging::name(Index value) { \
673 LOGF(#name "(%" PRIindex ")\n", value); \
674 return reader_->name(value); \
677 #define DEFINE_TYPE(name) \
678 Result BinaryReaderLogging::name(Type type) { \
679 LOGF(#name "(%s)\n", type.GetName().c_str()); \
680 return reader_->name(type); \
683 #define DEFINE_INDEX_DESC(name, desc) \
684 Result BinaryReaderLogging::name(Index value) { \
685 LOGF(#name "(" desc ": %" PRIindex ")\n", value); \
686 return reader_->name(value); \
689 #define DEFINE_INDEX_TYPE(name) \
690 Result BinaryReaderLogging::name(Index value, Type type) { \
691 LOGF(#name "(index: %" PRIindex ", type: %s)\n", value, \
692 type.GetName().c_str()); \
693 return reader_->name(value, type); \
696 #define DEFINE_INDEX_INDEX(name, desc0, desc1) \
697 Result BinaryReaderLogging::name(Index value0, Index value1) { \
698 LOGF(#name "(" desc0 ": %" PRIindex ", " desc1 ": %" PRIindex ")\n", \
699 value0, value1); \
700 return reader_->name(value0, value1); \
703 #define DEFINE_INDEX_INDEX_U8(name, desc0, desc1, desc2) \
704 Result BinaryReaderLogging::name(Index value0, Index value1, \
705 uint8_t value2) { \
706 LOGF(#name "(" desc0 ": %" PRIindex ", " desc1 ": %" PRIindex ", " desc2 \
707 ": %d)\n", \
708 value0, value1, value2); \
709 return reader_->name(value0, value1, value2); \
712 #define DEFINE_OPCODE(name) \
713 Result BinaryReaderLogging::name(Opcode opcode) { \
714 LOGF(#name "(\"%s\" (%u))\n", opcode.GetName(), opcode.GetCode()); \
715 return reader_->name(opcode); \
718 #define DEFINE_LOAD_STORE_OPCODE(name) \
719 Result BinaryReaderLogging::name(Opcode opcode, Index memidx, \
720 Address alignment_log2, Address offset) { \
721 LOGF(#name "(opcode: \"%s\" (%u), memidx: %" PRIindex \
722 ", align log2: %" PRIaddress ", offset: %" PRIaddress ")\n", \
723 opcode.GetName(), opcode.GetCode(), memidx, alignment_log2, offset); \
724 return reader_->name(opcode, memidx, alignment_log2, offset); \
727 #define DEFINE_SIMD_LOAD_STORE_LANE_OPCODE(name) \
728 Result BinaryReaderLogging::name(Opcode opcode, Index memidx, \
729 Address alignment_log2, Address offset, \
730 uint64_t value) { \
731 LOGF(#name "(opcode: \"%s\" (%u), memidx: %" PRIindex \
732 ", align log2: %" PRIaddress ", offset: %" PRIaddress \
733 ", lane: %" PRIu64 ")\n", \
734 opcode.GetName(), opcode.GetCode(), memidx, alignment_log2, offset, \
735 value); \
736 return reader_->name(opcode, memidx, alignment_log2, offset, value); \
739 #define DEFINE0(name) \
740 Result BinaryReaderLogging::name() { \
741 LOGF(#name "\n"); \
742 return reader_->name(); \
745 DEFINE_END(EndModule)
747 DEFINE_END(EndCustomSection)
749 DEFINE_BEGIN(BeginTypeSection)
750 DEFINE_INDEX(OnTypeCount)
751 DEFINE_END(EndTypeSection)
753 DEFINE_BEGIN(BeginImportSection)
754 DEFINE_INDEX(OnImportCount)
755 DEFINE_END(EndImportSection)
757 DEFINE_BEGIN(BeginFunctionSection)
758 DEFINE_INDEX(OnFunctionCount)
759 DEFINE_INDEX_INDEX(OnFunction, "index", "sig_index")
760 DEFINE_END(EndFunctionSection)
762 DEFINE_BEGIN(BeginTableSection)
763 DEFINE_INDEX(OnTableCount)
764 DEFINE_END(EndTableSection)
766 DEFINE_BEGIN(BeginMemorySection)
767 DEFINE_INDEX(OnMemoryCount)
768 DEFINE_END(EndMemorySection)
770 DEFINE_BEGIN(BeginGlobalSection)
771 DEFINE_INDEX(OnGlobalCount)
772 DEFINE_INDEX(BeginGlobalInitExpr)
773 DEFINE_INDEX(EndGlobalInitExpr)
774 DEFINE_INDEX(EndGlobal)
775 DEFINE_END(EndGlobalSection)
777 DEFINE_BEGIN(BeginExportSection)
778 DEFINE_INDEX(OnExportCount)
779 DEFINE_END(EndExportSection)
781 DEFINE_BEGIN(BeginStartSection)
782 DEFINE_INDEX(OnStartFunction)
783 DEFINE_END(EndStartSection)
785 DEFINE_BEGIN(BeginCodeSection)
786 DEFINE_INDEX(OnFunctionBodyCount)
787 DEFINE_INDEX(EndFunctionBody)
788 DEFINE_INDEX(OnLocalDeclCount)
789 DEFINE_LOAD_STORE_OPCODE(OnAtomicLoadExpr);
790 DEFINE_LOAD_STORE_OPCODE(OnAtomicRmwExpr);
791 DEFINE_LOAD_STORE_OPCODE(OnAtomicRmwCmpxchgExpr);
792 DEFINE_LOAD_STORE_OPCODE(OnAtomicStoreExpr);
793 DEFINE_LOAD_STORE_OPCODE(OnAtomicWaitExpr);
794 DEFINE_INDEX_DESC(OnAtomicFenceExpr, "consistency_model");
795 DEFINE_LOAD_STORE_OPCODE(OnAtomicNotifyExpr);
796 DEFINE_OPCODE(OnBinaryExpr)
797 DEFINE_INDEX_DESC(OnCallExpr, "func_index")
798 DEFINE_INDEX_INDEX(OnCallIndirectExpr, "sig_index", "table_index")
799 DEFINE0(OnCallRefExpr)
800 DEFINE_INDEX_DESC(OnCatchExpr, "tag_index");
801 DEFINE0(OnCatchAllExpr);
802 DEFINE_OPCODE(OnCompareExpr)
803 DEFINE_OPCODE(OnConvertExpr)
804 DEFINE_INDEX_DESC(OnDelegateExpr, "depth");
805 DEFINE0(OnDropExpr)
806 DEFINE0(OnElseExpr)
807 DEFINE0(OnEndExpr)
808 DEFINE_INDEX_DESC(OnGlobalGetExpr, "index")
809 DEFINE_INDEX_DESC(OnGlobalSetExpr, "index")
810 DEFINE_LOAD_STORE_OPCODE(OnLoadExpr);
811 DEFINE_INDEX_DESC(OnLocalGetExpr, "index")
812 DEFINE_INDEX_DESC(OnLocalSetExpr, "index")
813 DEFINE_INDEX_DESC(OnLocalTeeExpr, "index")
814 DEFINE_INDEX_INDEX(OnMemoryCopyExpr, "src_memory_index", "dest_memory_index")
815 DEFINE_INDEX(OnDataDropExpr)
816 DEFINE_INDEX(OnMemoryFillExpr)
817 DEFINE_INDEX(OnMemoryGrowExpr)
818 DEFINE_INDEX_INDEX(OnMemoryInitExpr, "segment_index", "memory_index")
819 DEFINE_INDEX(OnMemorySizeExpr)
820 DEFINE_INDEX_INDEX(OnTableCopyExpr, "dst_index", "src_index")
821 DEFINE_INDEX(OnElemDropExpr)
822 DEFINE_INDEX_INDEX(OnTableInitExpr, "segment_index", "table_index")
823 DEFINE_INDEX(OnTableSetExpr)
824 DEFINE_INDEX(OnTableGetExpr)
825 DEFINE_INDEX(OnTableGrowExpr)
826 DEFINE_INDEX(OnTableSizeExpr)
827 DEFINE_INDEX_DESC(OnTableFillExpr, "table index")
828 DEFINE_INDEX(OnRefFuncExpr)
829 DEFINE_TYPE(OnRefNullExpr)
830 DEFINE0(OnRefIsNullExpr)
831 DEFINE0(OnNopExpr)
832 DEFINE_INDEX_DESC(OnRethrowExpr, "depth");
833 DEFINE_INDEX_DESC(OnReturnCallExpr, "func_index")
835 DEFINE_INDEX_INDEX(OnReturnCallIndirectExpr, "sig_index", "table_index")
836 DEFINE0(OnReturnExpr)
837 DEFINE_LOAD_STORE_OPCODE(OnLoadSplatExpr);
838 DEFINE_LOAD_STORE_OPCODE(OnLoadZeroExpr);
839 DEFINE_LOAD_STORE_OPCODE(OnStoreExpr);
840 DEFINE_INDEX_DESC(OnThrowExpr, "tag_index")
841 DEFINE0(OnUnreachableExpr)
842 DEFINE_OPCODE(OnUnaryExpr)
843 DEFINE_OPCODE(OnTernaryExpr)
844 DEFINE_SIMD_LOAD_STORE_LANE_OPCODE(OnSimdLoadLaneExpr);
845 DEFINE_SIMD_LOAD_STORE_LANE_OPCODE(OnSimdStoreLaneExpr);
846 DEFINE_END(EndCodeSection)
848 DEFINE_BEGIN(BeginElemSection)
849 DEFINE_INDEX(OnElemSegmentCount)
850 DEFINE_INDEX(BeginElemSegmentInitExpr)
851 DEFINE_INDEX(EndElemSegmentInitExpr)
852 DEFINE_INDEX_INDEX(OnElemSegmentElemExprCount, "index", "count")
853 DEFINE_INDEX_TYPE(OnElemSegmentElemExpr_RefNull)
854 DEFINE_INDEX_INDEX(OnElemSegmentElemExpr_RefFunc, "index", "func_index")
855 DEFINE_INDEX(EndElemSegment)
856 DEFINE_END(EndElemSection)
858 DEFINE_BEGIN(BeginDataSection)
859 DEFINE_INDEX(OnDataSegmentCount)
860 DEFINE_INDEX_INDEX_U8(BeginDataSegment, "index", "memory_index", "flags")
861 DEFINE_INDEX(BeginDataSegmentInitExpr)
862 DEFINE_INDEX(EndDataSegmentInitExpr)
863 DEFINE_INDEX(EndDataSegment)
864 DEFINE_END(EndDataSection)
866 DEFINE_BEGIN(BeginDataCountSection)
867 DEFINE_INDEX(OnDataCount)
868 DEFINE_END(EndDataCountSection)
870 DEFINE_BEGIN(BeginNamesSection)
871 DEFINE_INDEX(OnFunctionNamesCount)
872 DEFINE_INDEX(OnLocalNameFunctionCount)
873 DEFINE_INDEX_INDEX(OnLocalNameLocalCount, "index", "count")
874 DEFINE_INDEX(OnNameCount);
875 DEFINE_END(EndNamesSection)
877 DEFINE_BEGIN(BeginRelocSection)
878 DEFINE_END(EndRelocSection)
880 DEFINE_BEGIN(BeginDylinkSection)
881 DEFINE_INDEX(OnDylinkNeededCount)
882 DEFINE_INDEX(OnDylinkExportCount)
883 DEFINE_INDEX(OnDylinkImportCount)
884 DEFINE_END(EndDylinkSection)
886 DEFINE_BEGIN(BeginTargetFeaturesSection)
887 DEFINE_INDEX(OnFeatureCount)
888 DEFINE_END(EndTargetFeaturesSection)
890 DEFINE_BEGIN(BeginLinkingSection)
891 DEFINE_INDEX(OnSymbolCount)
892 DEFINE_INDEX(OnSegmentInfoCount)
893 DEFINE_INDEX(OnInitFunctionCount)
894 DEFINE_INDEX(OnComdatCount)
895 DEFINE_END(EndLinkingSection)
897 DEFINE_BEGIN(BeginTagSection);
898 DEFINE_INDEX(OnTagCount);
899 DEFINE_INDEX_INDEX(OnTagType, "index", "sig_index")
900 DEFINE_END(EndTagSection);
902 DEFINE_INDEX(OnCodeMetadataFuncCount);
903 DEFINE_INDEX_INDEX(OnCodeMetadataCount, "func_index", "count");
904 DEFINE_END(EndCodeMetadataSection);
906 // We don't need to log these (the individual opcodes are logged instead), but
907 // we still need to forward the calls.
908 Result BinaryReaderLogging::OnOpcode(Opcode opcode) {
909 return reader_->OnOpcode(opcode);
912 Result BinaryReaderLogging::OnOpcodeBare() {
913 return reader_->OnOpcodeBare();
916 Result BinaryReaderLogging::OnOpcodeIndex(Index value) {
917 return reader_->OnOpcodeIndex(value);
920 Result BinaryReaderLogging::OnOpcodeIndexIndex(Index value, Index value2) {
921 return reader_->OnOpcodeIndexIndex(value, value2);
924 Result BinaryReaderLogging::OnOpcodeUint32(uint32_t value) {
925 return reader_->OnOpcodeUint32(value);
928 Result BinaryReaderLogging::OnOpcodeUint32Uint32(uint32_t value,
929 uint32_t value2) {
930 return reader_->OnOpcodeUint32Uint32(value, value2);
933 Result BinaryReaderLogging::OnOpcodeUint32Uint32Uint32(uint32_t value,
934 uint32_t value2,
935 uint32_t value3) {
936 return reader_->OnOpcodeUint32Uint32Uint32(value, value2, value3);
939 Result BinaryReaderLogging::OnOpcodeUint32Uint32Uint32Uint32(uint32_t value,
940 uint32_t value2,
941 uint32_t value3,
942 uint32_t value4) {
943 return reader_->OnOpcodeUint32Uint32Uint32Uint32(value, value2, value3,
944 value4);
947 Result BinaryReaderLogging::OnOpcodeUint64(uint64_t value) {
948 return reader_->OnOpcodeUint64(value);
951 Result BinaryReaderLogging::OnOpcodeF32(uint32_t value) {
952 return reader_->OnOpcodeF32(value);
955 Result BinaryReaderLogging::OnOpcodeF64(uint64_t value) {
956 return reader_->OnOpcodeF64(value);
959 Result BinaryReaderLogging::OnOpcodeV128(v128 value) {
960 return reader_->OnOpcodeV128(value);
963 Result BinaryReaderLogging::OnOpcodeBlockSig(Type sig_type) {
964 return reader_->OnOpcodeBlockSig(sig_type);
967 Result BinaryReaderLogging::OnOpcodeType(Type type) {
968 return reader_->OnOpcodeType(type);
971 } // namespace wabt