Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(652)

Side by Side Diff: tools/relocation_packer/src/leb128.h

Issue 310483003: Add a host tool to pack R_ARM_RELATIVE relocations in libchrome.<ver>.so. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Small readability and test data changes. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 TOOLS_RELOCATION_PACKER_SRC_LEB128_H_
14 #define TOOLS_RELOCATION_PACKER_SRC_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);
rmcilroy 2014/06/07 11:49:07 Newline
simonb (inactive) 2014/06/09 14:39:19 Done.
28 // |values| is the vector of unsigned ints to add.
29 void EnqueueAll(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_; }
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 explicit 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 DequeueAll(std::vector<uint32_t>* values);
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 // TOOLS_RELOCATION_PACKER_SRC_LEB128_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698