Chromium Code Reviews| Index: tools/relocation_packer/src/relocation_packer_leb128.h |
| diff --git a/tools/relocation_packer/src/relocation_packer_leb128.h b/tools/relocation_packer/src/relocation_packer_leb128.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1299cf41c464a8ab1c3f4308dc4b4f12e3d0beaa |
| --- /dev/null |
| +++ b/tools/relocation_packer/src/relocation_packer_leb128.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// LEB128 encoder and decoder for packed R_ARM_RELATIVE relocations. |
| +// |
| +// Run-length encoded R_ARM_RELATIVE relocations consist of a large number |
| +// of pairs of relatively small positive integer values. Encoding these as |
| +// LEB128 saves space. |
| +// |
| +// For more on LEB128 see http://en.wikipedia.org/wiki/LEB128. |
| + |
| +#ifndef RELOCATION_PACKER_LEB128_H |
| +#define RELOCATION_PACKER_LEB128_H |
| + |
| +#include <stdint.h> |
| +#include <unistd.h> |
| +#include <vector> |
| + |
| +namespace relocation_packer { |
| + |
| +// Encode packed words as a LEB128 byte stream. |
| +class Leb128Encoder { |
| + public: |
| + // Add a value or a vector of values to the encoding stream. |
| + // |value| is the unsigned int to add. |
| + void Enqueue(uint32_t value); |
| + // |values| is the vector of unsigned ints to add. |
| + void Enqueue(const std::vector<uint32_t>& values); |
| + |
| + // Retrieve the encoded representation of the values. |
| + // |encoding| is the returned vector of encoded data. |
| + 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.
|
| + |
| + private: |
| + // Growable vector holding the encoded LEB128 stream. |
| + std::vector<uint8_t> encoding_; |
| +}; |
| + |
| +// Decode a LEB128 byte stream to produce packed words. |
| +class Leb128Decoder { |
| + public: |
| + // Create a new decoder for the given encoded stream. |
| + // |encoding| is the vector of encoded data. |
| + Leb128Decoder(const std::vector<uint8_t>& encoding) |
| + : encoding_(encoding), cursor_(0) { } |
| + |
| + // Retrieve the next value from the encoded stream. |
| + uint32_t Dequeue(); |
| + |
| + // Retrieve all remaining values from the encoded stream. |
| + // |values| is the vector of decoded data. |
| + 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.
|
| + |
| + private: |
| + // Encoded LEB128 stream. |
| + std::vector<uint8_t> encoding_; |
| + |
| + // Cursor indicating the current stream retrieval point. |
| + size_t cursor_; |
| +}; |
| + |
| +} // namespace relocation_packer |
| + |
| +#endif // RELOCATION_PACKER_LEB128_H |