v8memory.h 1.71 KB
Newer Older
1
// Copyright 2011 the V8 project authors. All rights reserved.
2 3
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
4 5 6 7

#ifndef V8_MEMORY_H_
#define V8_MEMORY_H_

8 9
namespace v8 {
namespace internal {
10 11 12 13 14 15

// Memory provides an interface to 'raw' memory. It encapsulates the casts
// that typically are needed when incompatible pointer types are used.

class Memory {
 public:
16 17 18 19
  static uint8_t& uint8_at(Address addr) {
    return *reinterpret_cast<uint8_t*>(addr);
  }

20 21 22 23
  static uint16_t& uint16_at(Address addr)  {
    return *reinterpret_cast<uint16_t*>(addr);
  }

24 25 26 27 28 29 30 31
  static uint32_t& uint32_at(Address addr)  {
    return *reinterpret_cast<uint32_t*>(addr);
  }

  static int32_t& int32_at(Address addr)  {
    return *reinterpret_cast<int32_t*>(addr);
  }

32 33 34 35
  static uint64_t& uint64_at(Address addr)  {
    return *reinterpret_cast<uint64_t*>(addr);
  }

36 37 38 39
  static int& int_at(Address addr)  {
    return *reinterpret_cast<int*>(addr);
  }

40 41 42 43
  static unsigned& unsigned_at(Address addr) {
    return *reinterpret_cast<unsigned*>(addr);
  }

44 45 46 47 48 49 50 51
  static intptr_t& intptr_at(Address addr)  {
    return *reinterpret_cast<intptr_t*>(addr);
  }

  static uintptr_t& uintptr_at(Address addr) {
    return *reinterpret_cast<uintptr_t*>(addr);
  }

52 53 54 55
  static double& double_at(Address addr)  {
    return *reinterpret_cast<double*>(addr);
  }

56 57 58 59 60 61 62
  static Address& Address_at(Address addr)  {
    return *reinterpret_cast<Address*>(addr);
  }

  static Object*& Object_at(Address addr)  {
    return *reinterpret_cast<Object**>(addr);
  }
63 64 65 66

  static Handle<Object>& Object_Handle_at(Address addr)  {
    return *reinterpret_cast<Handle<Object>*>(addr);
  }
67 68 69 70 71
};

} }  // namespace v8::internal

#endif  // V8_MEMORY_H_