blob: f71de82072ec4b72700f5d3e9563e79da45e52ae [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_MEMORY_H_
29#define V8_MEMORY_H_
30
31namespace v8 {
32namespace internal {
33
34// Memory provides an interface to 'raw' memory. It encapsulates the casts
35// that typically are needed when incompatible pointer types are used.
36
37class Memory {
38 public:
Kristian Monsen80d68ea2010-09-08 11:05:35 +010039 static uint8_t& uint8_at(Address addr) {
40 return *reinterpret_cast<uint8_t*>(addr);
41 }
42
Steve Blocka7e24c12009-10-30 11:49:00 +000043 static uint16_t& uint16_at(Address addr) {
44 return *reinterpret_cast<uint16_t*>(addr);
45 }
46
47 static uint32_t& uint32_at(Address addr) {
48 return *reinterpret_cast<uint32_t*>(addr);
49 }
50
51 static int32_t& int32_at(Address addr) {
52 return *reinterpret_cast<int32_t*>(addr);
53 }
54
55 static uint64_t& uint64_at(Address addr) {
56 return *reinterpret_cast<uint64_t*>(addr);
57 }
58
59 static int& int_at(Address addr) {
60 return *reinterpret_cast<int*>(addr);
61 }
62
Ben Murdoch3ef787d2012-04-12 10:51:47 +010063 static unsigned& unsigned_at(Address addr) {
64 return *reinterpret_cast<unsigned*>(addr);
65 }
66
Ben Murdochb0fe1622011-05-05 13:52:32 +010067 static double& double_at(Address addr) {
68 return *reinterpret_cast<double*>(addr);
69 }
70
Steve Blocka7e24c12009-10-30 11:49:00 +000071 static Address& Address_at(Address addr) {
72 return *reinterpret_cast<Address*>(addr);
73 }
74
75 static Object*& Object_at(Address addr) {
76 return *reinterpret_cast<Object**>(addr);
77 }
Steve Block3ce2e202009-11-05 08:53:23 +000078
79 static Handle<Object>& Object_Handle_at(Address addr) {
80 return *reinterpret_cast<Handle<Object>*>(addr);
81 }
Steve Blocka7e24c12009-10-30 11:49:00 +000082};
83
84} } // namespace v8::internal
85
86#endif // V8_MEMORY_H_