diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-08-20 20:50:12 +0000 |
commit | e6d1592492a3a379186bfb02bd0f4eda0669c0d5 (patch) | |
tree | 599ab169a01f1c86eda9adc774edaedde2f2db5b /lib/Support/BinaryStreamReader.cpp | |
parent | 1a56a5ead7a2e84bee8240f5f6b033b5f1707154 (diff) |
Notes
Diffstat (limited to 'lib/Support/BinaryStreamReader.cpp')
-rw-r--r-- | lib/Support/BinaryStreamReader.cpp | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/lib/Support/BinaryStreamReader.cpp b/lib/Support/BinaryStreamReader.cpp index e00527f2519e..b17786593bde 100644 --- a/lib/Support/BinaryStreamReader.cpp +++ b/lib/Support/BinaryStreamReader.cpp @@ -1,9 +1,8 @@ //===- BinaryStreamReader.cpp - Reads objects from a binary stream --------===// // -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// @@ -11,6 +10,7 @@ #include "llvm/Support/BinaryStreamError.h" #include "llvm/Support/BinaryStreamRef.h" +#include "llvm/Support/LEB128.h" using namespace llvm; using endianness = llvm::support::endianness; @@ -41,6 +41,36 @@ Error BinaryStreamReader::readBytes(ArrayRef<uint8_t> &Buffer, uint32_t Size) { return Error::success(); } +Error BinaryStreamReader::readULEB128(uint64_t &Dest) { + SmallVector<uint8_t, 10> EncodedBytes; + ArrayRef<uint8_t> NextByte; + + // Copy the encoded ULEB into the buffer. + do { + if (auto Err = readBytes(NextByte, 1)) + return Err; + EncodedBytes.push_back(NextByte[0]); + } while (NextByte[0] & 0x80); + + Dest = decodeULEB128(EncodedBytes.begin(), nullptr, EncodedBytes.end()); + return Error::success(); +} + +Error BinaryStreamReader::readSLEB128(int64_t &Dest) { + SmallVector<uint8_t, 10> EncodedBytes; + ArrayRef<uint8_t> NextByte; + + // Copy the encoded ULEB into the buffer. + do { + if (auto Err = readBytes(NextByte, 1)) + return Err; + EncodedBytes.push_back(NextByte[0]); + } while (NextByte[0] & 0x80); + + Dest = decodeSLEB128(EncodedBytes.begin(), nullptr, EncodedBytes.end()); + return Error::success(); +} + Error BinaryStreamReader::readCString(StringRef &Dest) { uint32_t OriginalOffset = getOffset(); uint32_t FoundOffset = 0; @@ -146,4 +176,4 @@ BinaryStreamReader::split(uint32_t Off) const { BinaryStreamReader W1{First}; BinaryStreamReader W2{Second}; return std::make_pair(W1, W2); -}
\ No newline at end of file +} |