1 // Copyright 2011 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_MEMORY_H_ 6 #define V8_MEMORY_H_ 7 8 namespace v8 { 9 namespace internal { 10 11 // Memory provides an interface to 'raw' memory. It encapsulates the casts 12 // that typically are needed when incompatible pointer types are used. 13 14 class Memory { 15 public: uint8_at(Address addr)16 static uint8_t& uint8_at(Address addr) { 17 return *reinterpret_cast<uint8_t*>(addr); 18 } 19 uint16_at(Address addr)20 static uint16_t& uint16_at(Address addr) { 21 return *reinterpret_cast<uint16_t*>(addr); 22 } 23 uint32_at(Address addr)24 static uint32_t& uint32_at(Address addr) { 25 return *reinterpret_cast<uint32_t*>(addr); 26 } 27 int32_at(Address addr)28 static int32_t& int32_at(Address addr) { 29 return *reinterpret_cast<int32_t*>(addr); 30 } 31 uint64_at(Address addr)32 static uint64_t& uint64_at(Address addr) { 33 return *reinterpret_cast<uint64_t*>(addr); 34 } 35 int_at(Address addr)36 static int& int_at(Address addr) { 37 return *reinterpret_cast<int*>(addr); 38 } 39 unsigned_at(Address addr)40 static unsigned& unsigned_at(Address addr) { 41 return *reinterpret_cast<unsigned*>(addr); 42 } 43 intptr_at(Address addr)44 static intptr_t& intptr_at(Address addr) { 45 return *reinterpret_cast<intptr_t*>(addr); 46 } 47 uintptr_at(Address addr)48 static uintptr_t& uintptr_at(Address addr) { 49 return *reinterpret_cast<uintptr_t*>(addr); 50 } 51 double_at(Address addr)52 static double& double_at(Address addr) { 53 return *reinterpret_cast<double*>(addr); 54 } 55 Address_at(Address addr)56 static Address& Address_at(Address addr) { 57 return *reinterpret_cast<Address*>(addr); 58 } 59 Object_at(Address addr)60 static Object*& Object_at(Address addr) { 61 return *reinterpret_cast<Object**>(addr); 62 } 63 Object_Handle_at(Address addr)64 static Handle<Object>& Object_Handle_at(Address addr) { 65 return *reinterpret_cast<Handle<Object>*>(addr); 66 } 67 }; 68 69 } } // namespace v8::internal 70 71 #endif // V8_MEMORY_H_ 72