summaryrefslogtreecommitdiffstats
path: root/courgette/image_utils.h
diff options
context:
space:
mode:
authorhuangs <huangs@chromium.org>2015-12-07 17:27:46 -0800
committerCommit bot <commit-bot@chromium.org>2015-12-08 01:28:46 +0000
commit7a2fea2555a8014c4bdcdbc1119b97f98e057248 (patch)
treec16e6282db8e51c0d6f37adde6b7effc14a20b09 /courgette/image_utils.h
parent56c43a002072a04abe25a77f400a1e3425ab8991 (diff)
downloadchromium_src-7a2fea2555a8014c4bdcdbc1119b97f98e057248.zip
chromium_src-7a2fea2555a8014c4bdcdbc1119b97f98e057248.tar.gz
chromium_src-7a2fea2555a8014c4bdcdbc1119b97f98e057248.tar.bz2
[Courgette] Initial Implementation of LabelManager
This is part of the effort to reduce Courgette's peak memory. Main changes: - Moving Label to image_utils.h, and change Label::count_ from int to int32. - Adding utility class ConsecutiveRangeVisitor, with tests. - Adding LabelManager, with tests. The new code is not yet used in production. Review URL: https://codereview.chromium.org/1491703003 Cr-Commit-Position: refs/heads/master@{#363688}
Diffstat (limited to 'courgette/image_utils.h')
-rw-r--r--courgette/image_utils.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/courgette/image_utils.h b/courgette/image_utils.h
index c016357..47ba4f4 100644
--- a/courgette/image_utils.h
+++ b/courgette/image_utils.h
@@ -15,6 +15,26 @@ namespace courgette {
typedef uint32 RVA;
+// A Label is a symbolic reference to an address. Unlike a conventional
+// assembly language, we always know the address. The address will later be
+// stored in a table and the Label will be replaced with the index into the
+// table.
+// TODO(huangs): Make this a struct, and remove "_" from member names.
+class Label {
+ public:
+ enum : int { kNoIndex = -1 };
+ explicit Label(RVA rva) : rva_(rva) {}
+
+ bool operator==(const Label& other) const {
+ return rva_ == other.rva_ && index_ == other.index_ &&
+ count_ == other.count_;
+ }
+
+ RVA rva_ = 0; // Address referred to by the label.
+ int index_ = kNoIndex; // Index of address in address table.
+ int32 count_ = 0;
+};
+
// These helper functions avoid the need for casts in the main code.
inline uint16 ReadU16(const uint8* address, size_t offset) {
return *reinterpret_cast<const uint16*>(address + offset);