kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1 | // Copyright 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_VIRTUAL_FRAME_H_ |
| 29 | #define V8_VIRTUAL_FRAME_H_ |
| 30 | |
| 31 | #include "macro-assembler.h" |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 32 | |
| 33 | namespace v8 { namespace internal { |
| 34 | |
| 35 | // ------------------------------------------------------------------------- |
| 36 | // Virtual frame elements |
| 37 | // |
| 38 | // The internal elements of the virtual frames. There are several kinds of |
| 39 | // elements: |
| 40 | // * Invalid: elements that are uninitialized or not actually part |
| 41 | // of the virtual frame. They should not be read. |
| 42 | // * Memory: an element that resides in the actual frame. Its address is |
| 43 | // given by its position in the virtual frame. |
| 44 | // * Register: an element that resides in a register. |
| 45 | // * Constant: an element whose value is known at compile time. |
| 46 | |
| 47 | class FrameElement BASE_EMBEDDED { |
| 48 | public: |
| 49 | enum SyncFlag { |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 50 | NOT_SYNCED, |
| 51 | SYNCED |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | // The default constructor creates an invalid frame element. |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 55 | FrameElement() |
| 56 | : static_type_(), type_(INVALID), copied_(false), synced_(false) { |
| 57 | data_.reg_ = no_reg; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | // Factory function to construct an invalid frame element. |
| 61 | static FrameElement InvalidElement() { |
| 62 | FrameElement result; |
| 63 | return result; |
| 64 | } |
| 65 | |
| 66 | // Factory function to construct an in-memory frame element. |
| 67 | static FrameElement MemoryElement() { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 68 | FrameElement result(MEMORY, no_reg, SYNCED); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 69 | return result; |
| 70 | } |
| 71 | |
| 72 | // Factory function to construct an in-register frame element. |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 73 | static FrameElement RegisterElement(Register reg, |
| 74 | SyncFlag is_synced, |
| 75 | StaticType static_type = StaticType()) { |
| 76 | return FrameElement(REGISTER, reg, is_synced, static_type); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | // Factory function to construct a frame element whose value is known at |
| 80 | // compile time. |
| 81 | static FrameElement ConstantElement(Handle<Object> value, |
| 82 | SyncFlag is_synced) { |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 83 | FrameElement result(value, is_synced); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 84 | return result; |
| 85 | } |
| 86 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 87 | bool is_synced() const { return synced_; } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 88 | |
| 89 | void set_sync() { |
| 90 | ASSERT(type() != MEMORY); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 91 | synced_ = true; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void clear_sync() { |
| 95 | ASSERT(type() != MEMORY); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 96 | synced_ = false; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | bool is_valid() const { return type() != INVALID; } |
| 100 | bool is_memory() const { return type() == MEMORY; } |
| 101 | bool is_register() const { return type() == REGISTER; } |
| 102 | bool is_constant() const { return type() == CONSTANT; } |
| 103 | bool is_copy() const { return type() == COPY; } |
| 104 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 105 | bool is_copied() const { return copied_; } |
| 106 | void set_copied() { copied_ = true; } |
| 107 | void clear_copied() { copied_ = false; } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 108 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 109 | Register reg() const { |
| 110 | ASSERT(is_register()); |
| 111 | return data_.reg_; |
| 112 | } |
| 113 | |
| 114 | Handle<Object> handle() const { |
| 115 | ASSERT(is_constant()); |
| 116 | return Handle<Object>(data_.handle_); |
| 117 | } |
| 118 | |
| 119 | int index() const { |
| 120 | ASSERT(is_copy()); |
| 121 | return data_.index_; |
| 122 | } |
| 123 | |
| 124 | bool Equals(FrameElement other); |
| 125 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 126 | StaticType static_type() { return static_type_; } |
| 127 | |
| 128 | void set_static_type(StaticType static_type) { |
| 129 | // TODO(lrn): If it's s copy, it would be better to update the real one, |
| 130 | // but we can't from here. The caller must handle this. |
| 131 | static_type_ = static_type; |
| 132 | } |
| 133 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 134 | private: |
| 135 | enum Type { |
| 136 | INVALID, |
| 137 | MEMORY, |
| 138 | REGISTER, |
| 139 | CONSTANT, |
| 140 | COPY |
| 141 | }; |
| 142 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 143 | Type type() const { return static_cast<Type>(type_); } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 144 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 145 | StaticType static_type_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 146 | |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 147 | // The element's type. |
| 148 | byte type_; |
| 149 | |
| 150 | bool copied_; |
| 151 | |
| 152 | // The element's dirty-bit. The dirty bit can be cleared |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 153 | // for non-memory elements to indicate that the element agrees with |
| 154 | // the value in memory in the actual frame. |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 155 | bool synced_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 156 | |
| 157 | union { |
| 158 | Register reg_; |
| 159 | Object** handle_; |
| 160 | int index_; |
| 161 | } data_; |
| 162 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 163 | // Used to construct memory and register elements. |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 164 | FrameElement(Type type, Register reg, SyncFlag is_synced) |
| 165 | : static_type_(), |
| 166 | type_(type), |
| 167 | copied_(false), |
| 168 | synced_(is_synced != NOT_SYNCED) { |
| 169 | data_.reg_ = reg; |
| 170 | } |
| 171 | |
| 172 | FrameElement(Type type, Register reg, SyncFlag is_synced, StaticType stype) |
| 173 | : static_type_(stype), |
| 174 | type_(type), |
| 175 | copied_(false), |
| 176 | synced_(is_synced != NOT_SYNCED) { |
| 177 | data_.reg_ = reg; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | // Used to construct constant elements. |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 181 | FrameElement(Handle<Object> value, SyncFlag is_synced) |
| 182 | : static_type_(StaticType::TypeOf(*value)), |
| 183 | type_(CONSTANT), |
| 184 | copied_(false), |
| 185 | synced_(is_synced != NOT_SYNCED) { |
| 186 | data_.handle_ = value.location(); |
| 187 | } |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 188 | |
| 189 | void set_index(int new_index) { |
| 190 | ASSERT(is_copy()); |
| 191 | data_.index_ = new_index; |
| 192 | } |
| 193 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame^] | 194 | void set_reg(Register new_reg) { |
| 195 | ASSERT(is_register()); |
| 196 | data_.reg_ = new_reg; |
| 197 | } |
| 198 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 199 | friend class VirtualFrame; |
| 200 | }; |
| 201 | |
| 202 | |
| 203 | } } // namespace v8::internal |
| 204 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame^] | 205 | #ifdef V8_ARCH_ARM |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 206 | #include "arm/virtual-frame-arm.h" |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame^] | 207 | #endif |
| 208 | |
| 209 | #ifdef V8_ARCH_X64 |
| 210 | #include "x64/virtual-frame-x64.h" |
| 211 | #endif |
| 212 | |
| 213 | #ifdef V8_ARCH_IA32 |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 214 | #include "ia32/virtual-frame-ia32.h" |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 215 | #endif |
| 216 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 217 | #endif // V8_VIRTUAL_FRAME_H_ |