MCPcopy Create free account
hub / github.com/WebAssembly/wabt / LogOpcode

Method LogOpcode

src/binary-reader-objdump.cc:657–735  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

655}
656
657void BinaryReaderObjdumpDisassemble::LogOpcode(const char* fmt, ...) {
658 // BinaryReaderObjdumpDisassemble is only used to disassembly function bodies
659 // so this should never be called for instructions outside of function bodies
660 // (i.e. init expresions).
661 assert(in_function_body);
662 if (skip_next_opcode_) {
663 skip_next_opcode_ = false;
664 return;
665 }
666 const Offset immediate_len = state->offset - current_opcode_offset;
667 const Offset opcode_size = current_opcode.GetLength();
668 const Offset total_size = opcode_size + immediate_len;
669 // current_opcode_offset has already read past this opcode; rewind it by the
670 // size of this opcode, which may be more than one byte.
671 Offset offset = current_opcode_offset - opcode_size;
672 const Offset offset_end = offset + total_size;
673
674 bool first_line = true;
675 while (offset < offset_end) {
676 // Print bytes, but only display a maximum of IMMEDIATE_OCTET_COUNT on each
677 // line.
678 printf(" %06" PRIzx ":", GetPrintOffset(offset));
679 size_t i;
680 for (i = 0; offset < offset_end && i < IMMEDIATE_OCTET_COUNT;
681 ++i, ++offset) {
682 printf(" %02x", data_[offset]);
683 }
684 // Fill the rest of the remaining space with spaces.
685 for (; i < IMMEDIATE_OCTET_COUNT; ++i) {
686 printf(" ");
687 }
688 printf(" | ");
689
690 if (first_line) {
691 first_line = false;
692
693 // Print disassembly.
694 int indent_level = this->indent_level;
695 switch (current_opcode) {
696 case Opcode::Else:
697 case Opcode::Catch:
698 case Opcode::CatchAll:
699 indent_level--;
700 break;
701 default:
702 break;
703 }
704 for (int j = 0; j < indent_level; j++) {
705 printf(" ");
706 }
707
708 const char* opcode_name = current_opcode.GetName();
709 printf("%s", opcode_name);
710 if (fmt) {
711 printf(" ");
712 va_list args;
713 va_start(args, fmt);
714 vprintf(fmt, args);

Callers

nothing calls this directly

Calls 3

GetLengthMethod · 0.80
GetNameMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected