blob: 8c76f8a16b5f2ed5538fc7366de394ee07eaaea6 [file] [log] [blame]
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001// 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.org7be3c992009-03-12 07:19:55 +000032
33namespace 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
47class FrameElement BASE_EMBEDDED {
48 public:
49 enum SyncFlag {
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +000050 NOT_SYNCED,
51 SYNCED
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000052 };
53
54 // The default constructor creates an invalid frame element.
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +000055 FrameElement()
56 : static_type_(), type_(INVALID), copied_(false), synced_(false) {
57 data_.reg_ = no_reg;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000058 }
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.orgbb29dc92009-03-24 13:25:23 +000068 FrameElement result(MEMORY, no_reg, SYNCED);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000069 return result;
70 }
71
72 // Factory function to construct an in-register frame element.
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +000073 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.org7be3c992009-03-12 07:19:55 +000077 }
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.orgbb29dc92009-03-24 13:25:23 +000083 FrameElement result(value, is_synced);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000084 return result;
85 }
86
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +000087 bool is_synced() const { return synced_; }
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000088
89 void set_sync() {
90 ASSERT(type() != MEMORY);
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +000091 synced_ = true;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000092 }
93
94 void clear_sync() {
95 ASSERT(type() != MEMORY);
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +000096 synced_ = false;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000097 }
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.org8ccb0be2009-04-07 07:21:39 +0000105 bool is_copied() const { return copied_; }
106 void set_copied() { copied_ = true; }
107 void clear_copied() { copied_ = false; }
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000108
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000109 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.org8ccb0be2009-04-07 07:21:39 +0000126 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.org7be3c992009-03-12 07:19:55 +0000134 private:
135 enum Type {
136 INVALID,
137 MEMORY,
138 REGISTER,
139 CONSTANT,
140 COPY
141 };
142
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000143 Type type() const { return static_cast<Type>(type_); }
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000144
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000145 StaticType static_type_;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000146
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000147 // 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.org7be3c992009-03-12 07:19:55 +0000153 // for non-memory elements to indicate that the element agrees with
154 // the value in memory in the actual frame.
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000155 bool synced_;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000156
157 union {
158 Register reg_;
159 Object** handle_;
160 int index_;
161 } data_;
162
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000163 // Used to construct memory and register elements.
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000164 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.orgbb29dc92009-03-24 13:25:23 +0000178 }
179
180 // Used to construct constant elements.
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000181 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.orgbb29dc92009-03-24 13:25:23 +0000188
189 void set_index(int new_index) {
190 ASSERT(is_copy());
191 data_.index_ = new_index;
192 }
193
ager@chromium.org5ec48922009-05-05 07:25:34 +0000194 void set_reg(Register new_reg) {
195 ASSERT(is_register());
196 data_.reg_ = new_reg;
197 }
198
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000199 friend class VirtualFrame;
200};
201
202
203} } // namespace v8::internal
204
ager@chromium.org5ec48922009-05-05 07:25:34 +0000205#ifdef V8_ARCH_ARM
ager@chromium.org3a37e9b2009-04-27 09:26:21 +0000206#include "arm/virtual-frame-arm.h"
ager@chromium.org5ec48922009-05-05 07:25:34 +0000207#endif
208
209#ifdef V8_ARCH_X64
210#include "x64/virtual-frame-x64.h"
211#endif
212
213#ifdef V8_ARCH_IA32
ager@chromium.org3a37e9b2009-04-27 09:26:21 +0000214#include "ia32/virtual-frame-ia32.h"
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000215#endif
216
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000217#endif // V8_VIRTUAL_FRAME_H_