[PATCH] D50162: Replace LLDB's LEB128 implementation with the one from LLVM

Raphael Isemann via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 3 13:52:13 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL338920: Replace LLDB's LEB128 implementation with the one from LLVM (authored by teemperor, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50162?vs=158930&id=159082#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50162

Files:
  lldb/trunk/source/Utility/Stream.cpp


Index: lldb/trunk/source/Utility/Stream.cpp
===================================================================
--- lldb/trunk/source/Utility/Stream.cpp
+++ lldb/trunk/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_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);
 }
 
 //------------------------------------------------------------------


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50162.159082.patch
Type: text/x-patch
Size: 2111 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180803/386f63de/attachment.bin>


More information about the llvm-commits mailing list