jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 31 | namespace v8 { |
| 32 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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: |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 39 | static uint8_t& uint8_at(Address addr) { |
| 40 | return *reinterpret_cast<uint8_t*>(addr); |
| 41 | } |
| 42 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 43 | static uint16_t& uint16_at(Address addr) { |
| 44 | return *reinterpret_cast<uint16_t*>(addr); |
| 45 | } |
| 46 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 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 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 55 | static uint64_t& uint64_at(Address addr) { |
| 56 | return *reinterpret_cast<uint64_t*>(addr); |
| 57 | } |
| 58 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 59 | static int& int_at(Address addr) { |
| 60 | return *reinterpret_cast<int*>(addr); |
| 61 | } |
| 62 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 63 | static unsigned& unsigned_at(Address addr) { |
| 64 | return *reinterpret_cast<unsigned*>(addr); |
| 65 | } |
| 66 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 67 | static double& double_at(Address addr) { |
| 68 | return *reinterpret_cast<double*>(addr); |
| 69 | } |
| 70 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | 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 | } |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 78 | |
| 79 | static Handle<Object>& Object_Handle_at(Address addr) { |
| 80 | return *reinterpret_cast<Handle<Object>*>(addr); |
| 81 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } } // namespace v8::internal |
| 85 | |
| 86 | #endif // V8_MEMORY_H_ |