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

Unified Diff: tools/relocation_packer/src/leb128.cc

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: Remove binary test data files, dcommit separately. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/relocation_packer/src/leb128.h ('k') | tools/relocation_packer/src/leb128_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/relocation_packer/src/leb128.cc
diff --git a/tools/relocation_packer/src/leb128.cc b/tools/relocation_packer/src/leb128.cc
new file mode 100644
index 0000000000000000000000000000000000000000..40b0133d7d387010207ee9e698112760ed98a866
--- /dev/null
+++ b/tools/relocation_packer/src/leb128.cc
@@ -0,0 +1,55 @@
+// 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.
+
+// TODO(simonb): Extend for 64-bit target libraries.
+
+#include "leb128.h"
+
+#include <stdint.h>
+#include <vector>
+
+namespace relocation_packer {
+
+// Add a single value to the encoding. Values are encoded with variable
+// length. The least significant 7 bits of each byte hold 7 bits of data,
+// and the most significant bit is set on each byte except the last.
+void Leb128Encoder::Enqueue(uint32_t value) {
+ while (value > 127) {
+ encoding_.push_back((1 << 7) | (value & 127));
+ value >>= 7;
+ }
+ encoding_.push_back(value);
+}
+
+// Add a vector of values to the encoding.
+void Leb128Encoder::EnqueueAll(const std::vector<uint32_t>& values) {
+ for (size_t i = 0; i < values.size(); ++i)
+ Enqueue(values[i]);
+}
+
+// Decode and retrieve a single value from the encoding. Read forwards until
+// a byte without its most significant bit is found, then read the 7 bit
+// fields of the bytes spanned to re-form the value.
+uint32_t Leb128Decoder::Dequeue() {
+ size_t extent = cursor_;
+ while (encoding_[extent] >> 7)
+ extent++;
+
+ uint32_t value = 0;
+ for (size_t i = extent; i > cursor_; --i) {
+ value = (value << 7) | (encoding_[i] & 127);
+ }
+ value = (value << 7) | (encoding_[cursor_] & 127);
+
+ cursor_ = extent + 1;
+ return value;
+}
+
+// Decode and retrieve all remaining values from the encoding.
+void Leb128Decoder::DequeueAll(std::vector<uint32_t>* values) {
+ while (cursor_ < encoding_.size())
+ values->push_back(Dequeue());
+}
+
+} // namespace relocation_packer
« no previous file with comments | « tools/relocation_packer/src/leb128.h ('k') | tools/relocation_packer/src/leb128_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698