[Lldb-commits] [PATCH] D50677: Remove manual byte counting from Opcode::Dump
This revision was automatically updated to reflect the committed changes. Closed by commit rL340179: Remove manual byte counting from Opcode::Dump (authored by teemperor, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D50677?vs=160484=161492#toc Repository: rL LLVM https://reviews.llvm.org/D50677 Files: lldb/trunk/source/Core/Opcode.cpp Index: lldb/trunk/source/Core/Opcode.cpp === --- lldb/trunk/source/Core/Opcode.cpp +++ lldb/trunk/source/Core/Opcode.cpp @@ -23,40 +23,41 @@ using namespace lldb_private; int Opcode::Dump(Stream *s, uint32_t min_byte_width) { - int bytes_written = 0; + const uint32_t previous_bytes = s->GetWrittenBytes(); switch (m_type) { case Opcode::eTypeInvalid: -bytes_written = s->PutCString(""); +s->PutCString(""); break; case Opcode::eType8: -bytes_written = s->Printf("0x%2.2x", m_data.inst8); +s->Printf("0x%2.2x", m_data.inst8); break; case Opcode::eType16: -bytes_written = s->Printf("0x%4.4x", m_data.inst16); +s->Printf("0x%4.4x", m_data.inst16); break; case Opcode::eType16_2: case Opcode::eType32: -bytes_written = s->Printf("0x%8.8x", m_data.inst32); +s->Printf("0x%8.8x", m_data.inst32); break; case Opcode::eType64: -bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64); +s->Printf("0x%16.16" PRIx64, m_data.inst64); break; case Opcode::eTypeBytes: for (uint32_t i = 0; i < m_data.inst.length; ++i) { if (i > 0) -bytes_written += s->PutChar(' '); - bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]); +s->PutChar(' '); + s->Printf("%2.2x", m_data.inst.bytes[i]); } break; } - // Add spaces to make sure bytes dispay comes out even in case opcodes aren't - // all the same size - if (static_cast(bytes_written) < min_byte_width) -bytes_written = s->Printf("%*s", min_byte_width - bytes_written, ""); - return bytes_written; + uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes; + // Add spaces to make sure bytes display comes out even in case opcodes aren't + // all the same size. + if (bytes_written_so_far < min_byte_width) +s->Printf("%*s", min_byte_width - bytes_written_so_far, ""); + return s->GetWrittenBytes() - previous_bytes; } lldb::ByteOrder Opcode::GetDataByteOrder() const { Index: lldb/trunk/source/Core/Opcode.cpp === --- lldb/trunk/source/Core/Opcode.cpp +++ lldb/trunk/source/Core/Opcode.cpp @@ -23,40 +23,41 @@ using namespace lldb_private; int Opcode::Dump(Stream *s, uint32_t min_byte_width) { - int bytes_written = 0; + const uint32_t previous_bytes = s->GetWrittenBytes(); switch (m_type) { case Opcode::eTypeInvalid: -bytes_written = s->PutCString(""); +s->PutCString(""); break; case Opcode::eType8: -bytes_written = s->Printf("0x%2.2x", m_data.inst8); +s->Printf("0x%2.2x", m_data.inst8); break; case Opcode::eType16: -bytes_written = s->Printf("0x%4.4x", m_data.inst16); +s->Printf("0x%4.4x", m_data.inst16); break; case Opcode::eType16_2: case Opcode::eType32: -bytes_written = s->Printf("0x%8.8x", m_data.inst32); +s->Printf("0x%8.8x", m_data.inst32); break; case Opcode::eType64: -bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64); +s->Printf("0x%16.16" PRIx64, m_data.inst64); break; case Opcode::eTypeBytes: for (uint32_t i = 0; i < m_data.inst.length; ++i) { if (i > 0) -bytes_written += s->PutChar(' '); - bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]); +s->PutChar(' '); + s->Printf("%2.2x", m_data.inst.bytes[i]); } break; } - // Add spaces to make sure bytes dispay comes out even in case opcodes aren't - // all the same size - if (static_cast(bytes_written) < min_byte_width) -bytes_written = s->Printf("%*s", min_byte_width - bytes_written, ""); - return bytes_written; + uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes; + // Add spaces to make sure bytes display comes out even in case opcodes aren't + // all the same size. + if (bytes_written_so_far < min_byte_width) +s->Printf("%*s", min_byte_width - bytes_written_so_far, ""); + return s->GetWrittenBytes() - previous_bytes; } lldb::ByteOrder Opcode::GetDataByteOrder() const { ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50677: Remove manual byte counting from Opcode::Dump
davide accepted this revision. davide added a comment. This revision is now accepted and ready to land. LGTM. Repository: rLLDB LLDB https://reviews.llvm.org/D50677 ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [PATCH] D50677: Remove manual byte counting from Opcode::Dump
teemperor created this revision. teemperor added a reviewer: clayborg. Stream now has byte-counting functionality, so let's use this instead of manual byte counting. Repository: rLLDB LLDB https://reviews.llvm.org/D50677 Files: source/Core/Opcode.cpp Index: source/Core/Opcode.cpp === --- source/Core/Opcode.cpp +++ source/Core/Opcode.cpp @@ -23,40 +23,41 @@ using namespace lldb_private; int Opcode::Dump(Stream *s, uint32_t min_byte_width) { - int bytes_written = 0; + const uint32_t previous_bytes = s->GetWrittenBytes(); switch (m_type) { case Opcode::eTypeInvalid: -bytes_written = s->PutCString(""); +s->PutCString(""); break; case Opcode::eType8: -bytes_written = s->Printf("0x%2.2x", m_data.inst8); +s->Printf("0x%2.2x", m_data.inst8); break; case Opcode::eType16: -bytes_written = s->Printf("0x%4.4x", m_data.inst16); +s->Printf("0x%4.4x", m_data.inst16); break; case Opcode::eType16_2: case Opcode::eType32: -bytes_written = s->Printf("0x%8.8x", m_data.inst32); +s->Printf("0x%8.8x", m_data.inst32); break; case Opcode::eType64: -bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64); +s->Printf("0x%16.16" PRIx64, m_data.inst64); break; case Opcode::eTypeBytes: for (uint32_t i = 0; i < m_data.inst.length; ++i) { if (i > 0) -bytes_written += s->PutChar(' '); - bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]); +s->PutChar(' '); + s->Printf("%2.2x", m_data.inst.bytes[i]); } break; } - // Add spaces to make sure bytes dispay comes out even in case opcodes aren't - // all the same size - if (static_cast(bytes_written) < min_byte_width) -bytes_written = s->Printf("%*s", min_byte_width - bytes_written, ""); - return bytes_written; + uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes; + // Add spaces to make sure bytes display comes out even in case opcodes aren't + // all the same size. + if (bytes_written_so_far < min_byte_width) +s->Printf("%*s", min_byte_width - bytes_written_so_far, ""); + return s->GetWrittenBytes() - previous_bytes; } lldb::ByteOrder Opcode::GetDataByteOrder() const { Index: source/Core/Opcode.cpp === --- source/Core/Opcode.cpp +++ source/Core/Opcode.cpp @@ -23,40 +23,41 @@ using namespace lldb_private; int Opcode::Dump(Stream *s, uint32_t min_byte_width) { - int bytes_written = 0; + const uint32_t previous_bytes = s->GetWrittenBytes(); switch (m_type) { case Opcode::eTypeInvalid: -bytes_written = s->PutCString(""); +s->PutCString(""); break; case Opcode::eType8: -bytes_written = s->Printf("0x%2.2x", m_data.inst8); +s->Printf("0x%2.2x", m_data.inst8); break; case Opcode::eType16: -bytes_written = s->Printf("0x%4.4x", m_data.inst16); +s->Printf("0x%4.4x", m_data.inst16); break; case Opcode::eType16_2: case Opcode::eType32: -bytes_written = s->Printf("0x%8.8x", m_data.inst32); +s->Printf("0x%8.8x", m_data.inst32); break; case Opcode::eType64: -bytes_written = s->Printf("0x%16.16" PRIx64, m_data.inst64); +s->Printf("0x%16.16" PRIx64, m_data.inst64); break; case Opcode::eTypeBytes: for (uint32_t i = 0; i < m_data.inst.length; ++i) { if (i > 0) -bytes_written += s->PutChar(' '); - bytes_written += s->Printf("%2.2x", m_data.inst.bytes[i]); +s->PutChar(' '); + s->Printf("%2.2x", m_data.inst.bytes[i]); } break; } - // Add spaces to make sure bytes dispay comes out even in case opcodes aren't - // all the same size - if (static_cast(bytes_written) < min_byte_width) -bytes_written = s->Printf("%*s", min_byte_width - bytes_written, ""); - return bytes_written; + uint32_t bytes_written_so_far = s->GetWrittenBytes() - previous_bytes; + // Add spaces to make sure bytes display comes out even in case opcodes aren't + // all the same size. + if (bytes_written_so_far < min_byte_width) +s->Printf("%*s", min_byte_width - bytes_written_so_far, ""); + return s->GetWrittenBytes() - previous_bytes; } lldb::ByteOrder Opcode::GetDataByteOrder() const { ___ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits