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. | |
|
grt (UTC plus 2)
2015/12/03 15:19:09
i think you can remove this TODO. based on https:/
huangs
2015/12/03 19:29:06
I'd rather hold off the "_" suffix change in a mec
grt (UTC plus 2)
2015/12/04 19:33:41
Acknowledged.
| |
| 24 class Label { | |
| 25 public: | |
| 26 enum : int { kNoIndex = -1 }; | |
| 27 explicit Label(RVA rva) : rva_(rva) {} | |
| 28 | |
| 29 bool operator==(const Label& other) const { | |
| 30 return rva_ == other.rva_ && index_ == other.index_ && | |
| 31 count_ == other.count_; | |
| 32 } | |
| 33 | |
| 34 RVA rva_ = 0; // Address referred to by the label. | |
| 35 int index_ = kNoIndex; // Index of address in address table. | |
| 36 int count_ = 0; | |
| 37 }; | |
| 38 | |
| 18 // These helper functions avoid the need for casts in the main code. | 39 // These helper functions avoid the need for casts in the main code. |
| 19 inline uint16 ReadU16(const uint8* address, size_t offset) { | 40 inline uint16 ReadU16(const uint8* address, size_t offset) { |
| 20 return *reinterpret_cast<const uint16*>(address + offset); | 41 return *reinterpret_cast<const uint16*>(address + offset); |
| 21 } | 42 } |
| 22 | 43 |
| 23 inline uint32 ReadU32(const uint8* address, size_t offset) { | 44 inline uint32 ReadU32(const uint8* address, size_t offset) { |
| 24 return *reinterpret_cast<const uint32*>(address + offset); | 45 return *reinterpret_cast<const uint32*>(address + offset); |
| 25 } | 46 } |
| 26 | 47 |
| 27 inline uint64 ReadU64(const uint8* address, size_t offset) { | 48 inline uint64 ReadU64(const uint8* address, size_t offset) { |
| 28 return *reinterpret_cast<const uint64*>(address + offset); | 49 return *reinterpret_cast<const uint64*>(address + offset); |
| 29 } | 50 } |
| 30 | 51 |
| 31 inline uint16 Read16LittleEndian(const void* address) { | 52 inline uint16 Read16LittleEndian(const void* address) { |
| 32 return *reinterpret_cast<const uint16*>(address); | 53 return *reinterpret_cast<const uint16*>(address); |
| 33 } | 54 } |
| 34 | 55 |
| 35 inline uint32 Read32LittleEndian(const void* address) { | 56 inline uint32 Read32LittleEndian(const void* address) { |
| 36 return *reinterpret_cast<const uint32*>(address); | 57 return *reinterpret_cast<const uint32*>(address); |
| 37 } | 58 } |
| 38 | 59 |
| 39 inline uint64 Read64LittleEndian(const void* address) { | 60 inline uint64 Read64LittleEndian(const void* address) { |
| 40 return *reinterpret_cast<const uint64*>(address); | 61 return *reinterpret_cast<const uint64*>(address); |
| 41 } | 62 } |
| 42 | 63 |
| 43 } // namespace courgette | 64 } // namespace courgette |
| 44 | 65 |
| 45 #endif // COURGETTE_IMAGE_UTILS_H_ | 66 #endif // COURGETTE_IMAGE_UTILS_H_ |
| OLD | NEW |