Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 // LEB128 encoder and decoder for packed R_ARM_RELATIVE relocations. | |
| 6 // | |
| 7 // Run-length encoded R_ARM_RELATIVE relocations consist of a large number | |
| 8 // of pairs of relatively small positive integer values. Encoding these as | |
| 9 // LEB128 saves space. | |
| 10 // | |
| 11 // For more on LEB128 see http://en.wikipedia.org/wiki/LEB128. | |
| 12 | |
| 13 #ifndef RELOCATION_PACKER_LEB128_H | |
| 14 #define RELOCATION_PACKER_LEB128_H | |
| 15 | |
| 16 #include <stdint.h> | |
| 17 #include <unistd.h> | |
| 18 #include <vector> | |
| 19 | |
| 20 namespace relocation_packer { | |
| 21 | |
| 22 // Encode packed words as a LEB128 byte stream. | |
| 23 class Leb128Encoder { | |
| 24 public: | |
| 25 // Add a value or a vector of values to the encoding stream. | |
| 26 // |value| is the unsigned int to add. | |
| 27 void Enqueue(uint32_t value); | |
| 28 // |values| is the vector of unsigned ints to add. | |
| 29 void Enqueue(const std::vector<uint32_t>& values); | |
| 30 | |
| 31 // Retrieve the encoded representation of the values. | |
| 32 // |encoding| is the returned vector of encoded data. | |
| 33 void GetEncoding(std::vector<uint8_t>* encoding) { *encoding = encoding_; } | |
|
rmcilroy
2014/06/02 15:16:35
nit - just return the pointer rather than having a
simonb (inactive)
2014/06/04 16:40:35
More awkward for the current client code.
| |
| 34 | |
| 35 private: | |
| 36 // Growable vector holding the encoded LEB128 stream. | |
| 37 std::vector<uint8_t> encoding_; | |
| 38 }; | |
| 39 | |
| 40 // Decode a LEB128 byte stream to produce packed words. | |
| 41 class Leb128Decoder { | |
| 42 public: | |
| 43 // Create a new decoder for the given encoded stream. | |
| 44 // |encoding| is the vector of encoded data. | |
| 45 Leb128Decoder(const std::vector<uint8_t>& encoding) | |
| 46 : encoding_(encoding), cursor_(0) { } | |
| 47 | |
| 48 // Retrieve the next value from the encoded stream. | |
| 49 uint32_t Dequeue(); | |
| 50 | |
| 51 // Retrieve all remaining values from the encoded stream. | |
| 52 // |values| is the vector of decoded data. | |
| 53 void Dequeue(std::vector<uint32_t>* values); | |
|
rmcilroy
2014/06/02 15:16:35
DequeueAll (and maybe EnqueueAll above) to make it
simonb (inactive)
2014/06/04 16:40:35
Done.
| |
| 54 | |
| 55 private: | |
| 56 // Encoded LEB128 stream. | |
| 57 std::vector<uint8_t> encoding_; | |
| 58 | |
| 59 // Cursor indicating the current stream retrieval point. | |
| 60 size_t cursor_; | |
| 61 }; | |
| 62 | |
| 63 } // namespace relocation_packer | |
| 64 | |
| 65 #endif // RELOCATION_PACKER_LEB128_H | |
| OLD | NEW |