blob: 901e78d2960a967ea59bcc628d77716ede0056ae [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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
kasperl@chromium.org71affb52009-05-26 05:44:31 +000031namespace v8 {
32namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000033
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:
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +000039 static uint8_t& uint8_at(Address addr) {
40 return *reinterpret_cast<uint8_t*>(addr);
41 }
42
ager@chromium.orge2902be2009-06-08 12:21:35 +000043 static uint16_t& uint16_at(Address addr) {
44 return *reinterpret_cast<uint16_t*>(addr);
45 }
46
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000047 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
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +000055 static uint64_t& uint64_at(Address addr) {
56 return *reinterpret_cast<uint64_t*>(addr);
57 }
58
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000059 static int& int_at(Address addr) {
60 return *reinterpret_cast<int*>(addr);
61 }
62
kasperl@chromium.orga5551262010-12-07 12:49:48 +000063 static double& double_at(Address addr) {
64 return *reinterpret_cast<double*>(addr);
65 }
66
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000067 static Address& Address_at(Address addr) {
68 return *reinterpret_cast<Address*>(addr);
69 }
70
71 static Object*& Object_at(Address addr) {
72 return *reinterpret_cast<Object**>(addr);
73 }
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +000074
75 static Handle<Object>& Object_Handle_at(Address addr) {
76 return *reinterpret_cast<Handle<Object>*>(addr);
77 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000078};
79
80} } // namespace v8::internal
81
82#endif // V8_MEMORY_H_