• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // 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 
31 namespace v8 {
32 namespace 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 
37 class Memory {
38  public:
uint8_at(Address addr)39   static uint8_t& uint8_at(Address addr) {
40     return *reinterpret_cast<uint8_t*>(addr);
41   }
42 
uint16_at(Address addr)43   static uint16_t& uint16_at(Address addr)  {
44     return *reinterpret_cast<uint16_t*>(addr);
45   }
46 
uint32_at(Address addr)47   static uint32_t& uint32_at(Address addr)  {
48     return *reinterpret_cast<uint32_t*>(addr);
49   }
50 
int32_at(Address addr)51   static int32_t& int32_at(Address addr)  {
52     return *reinterpret_cast<int32_t*>(addr);
53   }
54 
uint64_at(Address addr)55   static uint64_t& uint64_at(Address addr)  {
56     return *reinterpret_cast<uint64_t*>(addr);
57   }
58 
int_at(Address addr)59   static int& int_at(Address addr)  {
60     return *reinterpret_cast<int*>(addr);
61   }
62 
double_at(Address addr)63   static double& double_at(Address addr)  {
64     return *reinterpret_cast<double*>(addr);
65   }
66 
Address_at(Address addr)67   static Address& Address_at(Address addr)  {
68     return *reinterpret_cast<Address*>(addr);
69   }
70 
Object_at(Address addr)71   static Object*& Object_at(Address addr)  {
72     return *reinterpret_cast<Object**>(addr);
73   }
74 
Object_Handle_at(Address addr)75   static Handle<Object>& Object_Handle_at(Address addr)  {
76     return *reinterpret_cast<Handle<Object>*>(addr);
77   }
78 };
79 
80 } }  // namespace v8::internal
81 
82 #endif  // V8_MEMORY_H_
83