| 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 <stddef.h> |
| 9 #include <stdint.h> |
| 9 | 10 |
| 10 // COURGETTE_HISTOGRAM_TARGETS prints out a histogram of how frequently | 11 // COURGETTE_HISTOGRAM_TARGETS prints out a histogram of how frequently |
| 11 // different target addresses are referenced. Purely for debugging. | 12 // different target addresses are referenced. Purely for debugging. |
| 12 #define COURGETTE_HISTOGRAM_TARGETS 0 | 13 #define COURGETTE_HISTOGRAM_TARGETS 0 |
| 13 | 14 |
| 14 namespace courgette { | 15 namespace courgette { |
| 15 | 16 |
| 16 typedef uint32 RVA; | 17 typedef uint32_t RVA; |
| 17 | 18 |
| 18 // A Label is a symbolic reference to an address. Unlike a conventional | 19 // 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 // 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 // stored in a table and the Label will be replaced with the index into the |
| 21 // table. | 22 // table. |
| 22 // TODO(huangs): Make this a struct, and remove "_" from member names. | 23 // TODO(huangs): Make this a struct, and remove "_" from member names. |
| 23 class Label { | 24 class Label { |
| 24 public: | 25 public: |
| 25 enum : int { kNoIndex = -1 }; | 26 enum : int { kNoIndex = -1 }; |
| 26 explicit Label(RVA rva) : rva_(rva) {} | 27 explicit Label(RVA rva) : rva_(rva) {} |
| 27 | 28 |
| 28 bool operator==(const Label& other) const { | 29 bool operator==(const Label& other) const { |
| 29 return rva_ == other.rva_ && index_ == other.index_ && | 30 return rva_ == other.rva_ && index_ == other.index_ && |
| 30 count_ == other.count_; | 31 count_ == other.count_; |
| 31 } | 32 } |
| 32 | 33 |
| 33 RVA rva_ = 0; // Address referred to by the label. | 34 RVA rva_ = 0; // Address referred to by the label. |
| 34 int index_ = kNoIndex; // Index of address in address table. | 35 int index_ = kNoIndex; // Index of address in address table. |
| 35 int32 count_ = 0; | 36 int32_t count_ = 0; |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 // 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. |
| 39 inline uint16 ReadU16(const uint8* address, size_t offset) { | 40 inline uint16_t ReadU16(const uint8_t* address, size_t offset) { |
| 40 return *reinterpret_cast<const uint16*>(address + offset); | 41 return *reinterpret_cast<const uint16_t*>(address + offset); |
| 41 } | 42 } |
| 42 | 43 |
| 43 inline uint32 ReadU32(const uint8* address, size_t offset) { | 44 inline uint32_t ReadU32(const uint8_t* address, size_t offset) { |
| 44 return *reinterpret_cast<const uint32*>(address + offset); | 45 return *reinterpret_cast<const uint32_t*>(address + offset); |
| 45 } | 46 } |
| 46 | 47 |
| 47 inline uint64 ReadU64(const uint8* address, size_t offset) { | 48 inline uint64_t ReadU64(const uint8_t* address, size_t offset) { |
| 48 return *reinterpret_cast<const uint64*>(address + offset); | 49 return *reinterpret_cast<const uint64_t*>(address + offset); |
| 49 } | 50 } |
| 50 | 51 |
| 51 inline uint16 Read16LittleEndian(const void* address) { | 52 inline uint16_t Read16LittleEndian(const void* address) { |
| 52 return *reinterpret_cast<const uint16*>(address); | 53 return *reinterpret_cast<const uint16_t*>(address); |
| 53 } | 54 } |
| 54 | 55 |
| 55 inline uint32 Read32LittleEndian(const void* address) { | 56 inline uint32_t Read32LittleEndian(const void* address) { |
| 56 return *reinterpret_cast<const uint32*>(address); | 57 return *reinterpret_cast<const uint32_t*>(address); |
| 57 } | 58 } |
| 58 | 59 |
| 59 inline uint64 Read64LittleEndian(const void* address) { | 60 inline uint64_t Read64LittleEndian(const void* address) { |
| 60 return *reinterpret_cast<const uint64*>(address); | 61 return *reinterpret_cast<const uint64_t*>(address); |
| 61 } | 62 } |
| 62 | 63 |
| 63 } // namespace courgette | 64 } // namespace courgette |
| 64 | 65 |
| 65 #endif // COURGETTE_IMAGE_UTILS_H_ | 66 #endif // COURGETTE_IMAGE_UTILS_H_ |
| OLD | NEW |