1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CRAZY_LINKER_LEB128_H
6 #define CRAZY_LINKER_LEB128_H
10 // Helper classes for decoding LEB128, used in packed relocation data.
11 // http://en.wikipedia.org/wiki/LEB128
17 explicit Leb128Decoder(const uint8_t* encoding)
18 : encoding_(encoding), cursor_(0) { }
27 byte = encoding_[cursor_++];
28 value |= static_cast<uint32_t>(byte & 127) << shift;
36 const uint8_t* encoding_;
40 class Sleb128Decoder {
42 explicit Sleb128Decoder(const uint8_t* encoding)
43 : encoding_(encoding), cursor_(0) { }
47 static const size_t size = CHAR_BIT * sizeof(value);
53 byte = encoding_[cursor_++];
54 value |= (static_cast<ssize_t>(byte & 127) << shift);
58 if (shift < size && (byte & 64))
59 value |= -(static_cast<ssize_t>(1) << shift);
65 const uint8_t* encoding_;
71 #endif // CRAZY_LINKER_LEB128_H