diff options
author | Raphael Isemann <teemperor@gmail.com> | 2018-08-03 20:51:31 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2018-08-03 20:51:31 +0000 |
commit | 79e9921ce2ecdb269953deec084c68a80ebc9f4f (patch) | |
tree | 096cd23021e331411969138b9e5b51bb11be9d78 /lldb/source/Utility/Stream.cpp | |
parent | b411cf327528a561b94f247aab7f1a520e1685ed (diff) | |
download | bcm5719-llvm-79e9921ce2ecdb269953deec084c68a80ebc9f4f.tar.gz bcm5719-llvm-79e9921ce2ecdb269953deec084c68a80ebc9f4f.zip |
Replace LLDB's LEB128 implementation with the one from LLVM
Reviewers: davide, labath
Reviewed By: labath
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D50162
llvm-svn: 338920
Diffstat (limited to 'lldb/source/Utility/Stream.cpp')
-rw-r--r-- | lldb/source/Utility/Stream.cpp | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp index 02a4b836dd8..8af8c19f210 100644 --- a/lldb/source/Utility/Stream.cpp +++ b/lldb/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 @@ void Stream::Offset(uint32_t uval, const char *format) { Printf(format, uval); } // 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_forwarder); + 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_forwarder); + else + return Printf("0x%" PRIx64, uval); } //------------------------------------------------------------------ |