summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/BinaryStreamWriter.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2019-04-17 15:38:27 +0000
committerLang Hames <lhames@gmail.com>2019-04-17 15:38:27 +0000
commitc1106c9b1161a120ccc0c44b0dcab0b403860ad2 (patch)
tree9f5874fc27cd96942ad4fa5f933b3570c1a11dae /llvm/lib/Support/BinaryStreamWriter.cpp
parent258a425c69f0f611ae237ad507252ad18048d2ab (diff)
downloadbcm5719-llvm-c1106c9b1161a120ccc0c44b0dcab0b403860ad2.tar.gz
bcm5719-llvm-c1106c9b1161a120ccc0c44b0dcab0b403860ad2.zip
[Support] Add LEB128 support to BinaryStreamReader/Writer.
Summary: This patch adds support for ULEB128 and SLEB128 encoding and decoding to BinaryStreamWriter and BinaryStreamReader respectively. Support for ULEB128/SLEB128 will be used for eh-frame parsing in the JITLink library currently under development (see https://reviews.llvm.org/D58704). Reviewers: zturner, dblaikie Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60810 llvm-svn: 358584
Diffstat (limited to 'llvm/lib/Support/BinaryStreamWriter.cpp')
-rw-r--r--llvm/lib/Support/BinaryStreamWriter.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Support/BinaryStreamWriter.cpp b/llvm/lib/Support/BinaryStreamWriter.cpp
index 929968bf2e4..986e18da281 100644
--- a/llvm/lib/Support/BinaryStreamWriter.cpp
+++ b/llvm/lib/Support/BinaryStreamWriter.cpp
@@ -11,6 +11,7 @@
#include "llvm/Support/BinaryStreamError.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/BinaryStreamRef.h"
+#include "llvm/Support/LEB128.h"
using namespace llvm;
@@ -31,6 +32,18 @@ Error BinaryStreamWriter::writeBytes(ArrayRef<uint8_t> Buffer) {
return Error::success();
}
+Error BinaryStreamWriter::writeULEB128(uint64_t Value) {
+ uint8_t EncodedBytes[10] = {0};
+ unsigned Size = encodeULEB128(Value, &EncodedBytes[0]);
+ return writeBytes({EncodedBytes, Size});
+}
+
+Error BinaryStreamWriter::writeSLEB128(int64_t Value) {
+ uint8_t EncodedBytes[10] = {0};
+ unsigned Size = encodeSLEB128(Value, &EncodedBytes[0]);
+ return writeBytes({EncodedBytes, Size});
+}
+
Error BinaryStreamWriter::writeCString(StringRef Str) {
if (auto EC = writeFixedString(Str))
return EC;
OpenPOWER on IntegriCloud