[Lldb-commits] [PATCH] D50162: Replace LLDB's LEB128 implementation with the one from LLVM
Raphael Isemann via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Wed Aug 1 15:12:00 PDT 2018
teemperor created this revision.
https://reviews.llvm.org/D50162
Files:
source/Utility/Stream.cpp
Index: source/Utility/Stream.cpp
===================================================================
--- source/Utility/Stream.cpp
+++ source/Utility/Stream.cpp
@@ -12,6 +12,7 @@
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/VASPrintf.h"
#include "llvm/ADT/SmallString.h" // for SmallString
+#include "llvm/Support/LEB128.h"
#include <string>
@@ -49,47 +50,20 @@
// Put an SLEB128 "uval" out to the stream using the printf format in "format".
//------------------------------------------------------------------
size_t Stream::PutSLEB128(int64_t sval) {
- size_t bytes_written = 0;
- if (m_flags.Test(eBinary)) {
- bool more = true;
- while (more) {
- uint8_t byte = sval & 0x7fu;
- sval >>= 7;
- /* sign bit of byte is 2nd high order bit (0x40) */
- if ((sval == 0 && !(byte & 0x40)) || (sval == -1 && (byte & 0x40)))
- more = false;
- else
- // more bytes to come
- byte |= 0x80u;
- bytes_written += Write(&byte, 1);
- }
- } else {
- bytes_written = Printf("0x%" PRIi64, sval);
- }
-
- return bytes_written;
+ if (m_flags.Test(eBinary))
+ return llvm::encodeSLEB128(sval, m_forward);
+ else
+ return Printf("0x%" PRIi64, sval);
}
//------------------------------------------------------------------
// Put an ULEB128 "uval" out to the stream using the printf format in "format".
//------------------------------------------------------------------
size_t Stream::PutULEB128(uint64_t uval) {
- size_t bytes_written = 0;
- if (m_flags.Test(eBinary)) {
- do {
-
- uint8_t byte = uval & 0x7fu;
- uval >>= 7;
- if (uval != 0) {
- // more bytes to come
- byte |= 0x80u;
- }
- bytes_written += Write(&byte, 1);
- } while (uval != 0);
- } else {
- bytes_written = Printf("0x%" PRIx64, uval);
- }
- return bytes_written;
+ if (m_flags.Test(eBinary))
+ return llvm::encodeULEB128(uval, m_forward);
+ else
+ return Printf("0x%" PRIx64, uval);
}
//------------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50162.158648.patch
Type: text/x-patch
Size: 2074 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20180801/b186e535/attachment.bin>
More information about the lldb-commits
mailing list