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

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

Issue 404553003: Create builds configured for ARM and AARCH64. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename DT tags to DT_ANDROID_REL_XXX Created 6 years, 5 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
« no previous file with comments | « tools/relocation_packer/src/elf_traits.h ('k') | tools/relocation_packer/src/leb128.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // LEB128 encoder and decoder for packed R_ARM_RELATIVE relocations. 5 // LEB128 encoder and decoder for packed ARM relative relocations.
6 // 6 //
7 // Run-length encoded R_ARM_RELATIVE relocations consist of a large number 7 // Run-length encoded ARM relative relocations consist of a large number
8 // of pairs of relatively small positive integer values. Encoding these as 8 // of pairs of relatively small positive integer values. Encoding these as
9 // LEB128 saves space. 9 // LEB128 saves space.
10 // 10 //
11 // For more on LEB128 see http://en.wikipedia.org/wiki/LEB128. 11 // For more on LEB128 see http://en.wikipedia.org/wiki/LEB128.
12 12
13 #ifndef TOOLS_RELOCATION_PACKER_SRC_LEB128_H_ 13 #ifndef TOOLS_RELOCATION_PACKER_SRC_LEB128_H_
14 #define TOOLS_RELOCATION_PACKER_SRC_LEB128_H_ 14 #define TOOLS_RELOCATION_PACKER_SRC_LEB128_H_
15 15
16 #include <stdint.h> 16 #include <stdint.h>
17 #include <unistd.h>
18 #include <vector> 17 #include <vector>
19 18
19 #include "elf_traits.h"
20
20 namespace relocation_packer { 21 namespace relocation_packer {
21 22
22 // Encode packed words as a LEB128 byte stream. 23 // Encode packed words as a LEB128 byte stream.
23 class Leb128Encoder { 24 class Leb128Encoder {
24 public: 25 public:
25 // Explicit (but empty) constructor and destructor, for chromium-style. 26 // Explicit (but empty) constructor and destructor, for chromium-style.
26 Leb128Encoder(); 27 Leb128Encoder();
27 ~Leb128Encoder(); 28 ~Leb128Encoder();
28 29
29 // Add a value to the encoding stream. 30 // Add a value to the encoding stream.
30 // |value| is the unsigned int to add. 31 // |value| is the unsigned int to add.
31 void Enqueue(uint32_t value); 32 void Enqueue(ELF::Xword value);
32 33
33 // Add a vector of values to the encoding stream. 34 // Add a vector of values to the encoding stream.
34 // |values| is the vector of unsigned ints to add. 35 // |values| is the vector of unsigned ints to add.
35 void EnqueueAll(const std::vector<uint32_t>& values); 36 void EnqueueAll(const std::vector<ELF::Xword>& values);
36 37
37 // Retrieve the encoded representation of the values. 38 // Retrieve the encoded representation of the values.
38 // |encoding| is the returned vector of encoded data. 39 // |encoding| is the returned vector of encoded data.
39 void GetEncoding(std::vector<uint8_t>* encoding) { *encoding = encoding_; } 40 void GetEncoding(std::vector<uint8_t>* encoding) { *encoding = encoding_; }
40 41
41 private: 42 private:
42 // Growable vector holding the encoded LEB128 stream. 43 // Growable vector holding the encoded LEB128 stream.
43 std::vector<uint8_t> encoding_; 44 std::vector<uint8_t> encoding_;
44 }; 45 };
45 46
46 // Decode a LEB128 byte stream to produce packed words. 47 // Decode a LEB128 byte stream to produce packed words.
47 class Leb128Decoder { 48 class Leb128Decoder {
48 public: 49 public:
49 // Create a new decoder for the given encoded stream. 50 // Create a new decoder for the given encoded stream.
50 // |encoding| is the vector of encoded data. 51 // |encoding| is the vector of encoded data.
51 explicit Leb128Decoder(const std::vector<uint8_t>& encoding); 52 explicit Leb128Decoder(const std::vector<uint8_t>& encoding);
52 53
53 // Explicit (but empty) destructor, for chromium-style. 54 // Explicit (but empty) destructor, for chromium-style.
54 ~Leb128Decoder(); 55 ~Leb128Decoder();
55 56
56 // Retrieve the next value from the encoded stream. 57 // Retrieve the next value from the encoded stream.
57 uint32_t Dequeue(); 58 ELF::Xword Dequeue();
58 59
59 // Retrieve all remaining values from the encoded stream. 60 // Retrieve all remaining values from the encoded stream.
60 // |values| is the vector of decoded data. 61 // |values| is the vector of decoded data.
61 void DequeueAll(std::vector<uint32_t>* values); 62 void DequeueAll(std::vector<ELF::Xword>* values);
62 63
63 private: 64 private:
64 // Encoded LEB128 stream. 65 // Encoded LEB128 stream.
65 std::vector<uint8_t> encoding_; 66 std::vector<uint8_t> encoding_;
66 67
67 // Cursor indicating the current stream retrieval point. 68 // Cursor indicating the current stream retrieval point.
68 size_t cursor_; 69 size_t cursor_;
69 }; 70 };
70 71
71 } // namespace relocation_packer 72 } // namespace relocation_packer
72 73
73 #endif // TOOLS_RELOCATION_PACKER_SRC_LEB128_H_ 74 #endif // TOOLS_RELOCATION_PACKER_SRC_LEB128_H_
OLDNEW
« no previous file with comments | « tools/relocation_packer/src/elf_traits.h ('k') | tools/relocation_packer/src/leb128.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698