Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef COURGETTE_IMAGE_UTILS_H_ | 5 #ifndef COURGETTE_IMAGE_UTILS_H_ |
| 6 #define COURGETTE_IMAGE_UTILS_H_ | 6 #define COURGETTE_IMAGE_UTILS_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 | 9 |
| 10 // COURGETTE_HISTOGRAM_TARGETS prints out a histogram of how frequently | 10 // COURGETTE_HISTOGRAM_TARGETS prints out a histogram of how frequently |
| 11 // different target addresses are referenced. Purely for debugging. | 11 // different target addresses are referenced. Purely for debugging. |
| 12 #define COURGETTE_HISTOGRAM_TARGETS 0 | 12 #define COURGETTE_HISTOGRAM_TARGETS 0 |
| 13 | 13 |
| 14 namespace courgette { | 14 namespace courgette { |
| 15 | 15 |
| 16 typedef uint32 RVA; | 16 typedef uint32 RVA; |
| 17 | 17 |
| 18 // A Label is a symbolic reference to an address. Unlike a conventional | |
| 19 // assembly language, we always know the address. The address will later be | |
| 20 // stored in a table and the Label will be replaced with the index into the | |
| 21 // table. | |
| 22 // | |
| 23 // TODO(sra): Make fields private and add setters and getters. | |
| 24 class Label { | |
| 25 public: | |
| 26 static const int kNoIndex = -1; | |
|
grt (UTC plus 2)
2015/12/02 19:03:40
nit:
enum : int { kNoIndex = -1 };
as per https:
huangs
2015/12/02 20:51:02
Done.
| |
| 27 Label() : rva_(0), index_(kNoIndex), count_(0) {} | |
| 28 explicit Label(RVA rva) : rva_(rva), index_(kNoIndex), count_(0) {} | |
| 29 | |
| 30 bool operator==(const Label& other) const { | |
| 31 return rva_ == other.rva_ && index_ == other.index_ && | |
| 32 count_ == other.count_; | |
| 33 } | |
| 34 | |
| 35 RVA rva_; // Address referred to by the label. | |
|
grt (UTC plus 2)
2015/12/02 19:03:40
use non-static member initializers here; e.g.:
R
huangs
2015/12/02 20:51:02
Done.
| |
| 36 int index_; // Index of address in address table, kNoIndex until assigned. | |
| 37 int count_; | |
| 38 }; | |
| 39 | |
| 18 // These helper functions avoid the need for casts in the main code. | 40 // These helper functions avoid the need for casts in the main code. |
| 19 inline uint16 ReadU16(const uint8* address, size_t offset) { | 41 inline uint16 ReadU16(const uint8* address, size_t offset) { |
| 20 return *reinterpret_cast<const uint16*>(address + offset); | 42 return *reinterpret_cast<const uint16*>(address + offset); |
| 21 } | 43 } |
| 22 | 44 |
| 23 inline uint32 ReadU32(const uint8* address, size_t offset) { | 45 inline uint32 ReadU32(const uint8* address, size_t offset) { |
| 24 return *reinterpret_cast<const uint32*>(address + offset); | 46 return *reinterpret_cast<const uint32*>(address + offset); |
| 25 } | 47 } |
| 26 | 48 |
| 27 inline uint64 ReadU64(const uint8* address, size_t offset) { | 49 inline uint64 ReadU64(const uint8* address, size_t offset) { |
| 28 return *reinterpret_cast<const uint64*>(address + offset); | 50 return *reinterpret_cast<const uint64*>(address + offset); |
| 29 } | 51 } |
| 30 | 52 |
| 31 inline uint16 Read16LittleEndian(const void* address) { | 53 inline uint16 Read16LittleEndian(const void* address) { |
| 32 return *reinterpret_cast<const uint16*>(address); | 54 return *reinterpret_cast<const uint16*>(address); |
| 33 } | 55 } |
| 34 | 56 |
| 35 inline uint32 Read32LittleEndian(const void* address) { | 57 inline uint32 Read32LittleEndian(const void* address) { |
| 36 return *reinterpret_cast<const uint32*>(address); | 58 return *reinterpret_cast<const uint32*>(address); |
| 37 } | 59 } |
| 38 | 60 |
| 39 inline uint64 Read64LittleEndian(const void* address) { | 61 inline uint64 Read64LittleEndian(const void* address) { |
| 40 return *reinterpret_cast<const uint64*>(address); | 62 return *reinterpret_cast<const uint64*>(address); |
| 41 } | 63 } |
| 42 | 64 |
| 43 } // namespace courgette | 65 } // namespace courgette |
| 44 | 66 |
| 45 #endif // COURGETTE_IMAGE_UTILS_H_ | 67 #endif // COURGETTE_IMAGE_UTILS_H_ |
| OLD | NEW |