|
1 /* |
|
2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
7 * |
|
8 * 1. Redistributions of source code must retain the above copyright |
|
9 * notice, this list of conditions and the following disclaimer. |
|
10 * 2. Redistributions in binary form must reproduce the above copyright |
|
11 * notice, this list of conditions and the following disclaimer in the |
|
12 * documentation and/or other materials provided with the distribution. |
|
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
|
14 * its contributors may be used to endorse or promote products derived |
|
15 * from this software without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
|
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
|
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
|
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
|
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
|
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
|
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
27 */ |
|
28 |
|
29 #ifndef Register_h |
|
30 #define Register_h |
|
31 |
|
32 #include "JSValue.h" |
|
33 #include <wtf/Assertions.h> |
|
34 #include <wtf/FastAllocBase.h> |
|
35 #include <wtf/VectorTraits.h> |
|
36 |
|
37 namespace JSC { |
|
38 |
|
39 class CodeBlock; |
|
40 class ExecState; |
|
41 class JSActivation; |
|
42 class JSObject; |
|
43 class JSPropertyNameIterator; |
|
44 class ScopeChainNode; |
|
45 |
|
46 struct Instruction; |
|
47 |
|
48 typedef ExecState CallFrame; |
|
49 |
|
50 class Register : public WTF::FastAllocBase { |
|
51 public: |
|
52 Register(); |
|
53 |
|
54 Register(const JSValue&); |
|
55 Register& operator=(const JSValue&); |
|
56 JSValue jsValue() const; |
|
57 |
|
58 Register& operator=(JSActivation*); |
|
59 Register& operator=(CallFrame*); |
|
60 Register& operator=(CodeBlock*); |
|
61 Register& operator=(JSPropertyNameIterator*); |
|
62 Register& operator=(ScopeChainNode*); |
|
63 Register& operator=(Instruction*); |
|
64 |
|
65 int32_t i() const; |
|
66 JSActivation* activation() const; |
|
67 CallFrame* callFrame() const; |
|
68 CodeBlock* codeBlock() const; |
|
69 JSObject* function() const; |
|
70 JSPropertyNameIterator* propertyNameIterator() const; |
|
71 ScopeChainNode* scopeChain() const; |
|
72 Instruction* vPC() const; |
|
73 |
|
74 static Register withInt(int32_t i) |
|
75 { |
|
76 Register r; |
|
77 r.u.i = i; |
|
78 return r; |
|
79 } |
|
80 |
|
81 static Register withCallee(JSObject* callee) |
|
82 { |
|
83 Register r; |
|
84 r.u.function = callee; |
|
85 return r; |
|
86 } |
|
87 |
|
88 private: |
|
89 union { |
|
90 int32_t i; |
|
91 EncodedJSValue value; |
|
92 |
|
93 JSActivation* activation; |
|
94 CallFrame* callFrame; |
|
95 CodeBlock* codeBlock; |
|
96 JSObject* function; |
|
97 JSPropertyNameIterator* propertyNameIterator; |
|
98 ScopeChainNode* scopeChain; |
|
99 Instruction* vPC; |
|
100 } u; |
|
101 }; |
|
102 |
|
103 ALWAYS_INLINE Register::Register() |
|
104 { |
|
105 #ifndef NDEBUG |
|
106 *this = JSValue(); |
|
107 #endif |
|
108 } |
|
109 |
|
110 ALWAYS_INLINE Register::Register(const JSValue& v) |
|
111 { |
|
112 #if ENABLE(JSC_ZOMBIES) |
|
113 ASSERT(!v.isZombie()); |
|
114 #endif |
|
115 u.value = JSValue::encode(v); |
|
116 } |
|
117 |
|
118 ALWAYS_INLINE Register& Register::operator=(const JSValue& v) |
|
119 { |
|
120 #if ENABLE(JSC_ZOMBIES) |
|
121 ASSERT(!v.isZombie()); |
|
122 #endif |
|
123 u.value = JSValue::encode(v); |
|
124 return *this; |
|
125 } |
|
126 |
|
127 ALWAYS_INLINE JSValue Register::jsValue() const |
|
128 { |
|
129 return JSValue::decode(u.value); |
|
130 } |
|
131 |
|
132 // Interpreter functions |
|
133 |
|
134 ALWAYS_INLINE Register& Register::operator=(JSActivation* activation) |
|
135 { |
|
136 u.activation = activation; |
|
137 return *this; |
|
138 } |
|
139 |
|
140 ALWAYS_INLINE Register& Register::operator=(CallFrame* callFrame) |
|
141 { |
|
142 u.callFrame = callFrame; |
|
143 return *this; |
|
144 } |
|
145 |
|
146 ALWAYS_INLINE Register& Register::operator=(CodeBlock* codeBlock) |
|
147 { |
|
148 u.codeBlock = codeBlock; |
|
149 return *this; |
|
150 } |
|
151 |
|
152 ALWAYS_INLINE Register& Register::operator=(Instruction* vPC) |
|
153 { |
|
154 u.vPC = vPC; |
|
155 return *this; |
|
156 } |
|
157 |
|
158 ALWAYS_INLINE Register& Register::operator=(ScopeChainNode* scopeChain) |
|
159 { |
|
160 u.scopeChain = scopeChain; |
|
161 return *this; |
|
162 } |
|
163 |
|
164 ALWAYS_INLINE Register& Register::operator=(JSPropertyNameIterator* propertyNameIterator) |
|
165 { |
|
166 u.propertyNameIterator = propertyNameIterator; |
|
167 return *this; |
|
168 } |
|
169 |
|
170 ALWAYS_INLINE int32_t Register::i() const |
|
171 { |
|
172 return u.i; |
|
173 } |
|
174 |
|
175 ALWAYS_INLINE JSActivation* Register::activation() const |
|
176 { |
|
177 return u.activation; |
|
178 } |
|
179 |
|
180 ALWAYS_INLINE CallFrame* Register::callFrame() const |
|
181 { |
|
182 return u.callFrame; |
|
183 } |
|
184 |
|
185 ALWAYS_INLINE CodeBlock* Register::codeBlock() const |
|
186 { |
|
187 return u.codeBlock; |
|
188 } |
|
189 |
|
190 ALWAYS_INLINE JSObject* Register::function() const |
|
191 { |
|
192 return u.function; |
|
193 } |
|
194 |
|
195 ALWAYS_INLINE JSPropertyNameIterator* Register::propertyNameIterator() const |
|
196 { |
|
197 return u.propertyNameIterator; |
|
198 } |
|
199 |
|
200 ALWAYS_INLINE ScopeChainNode* Register::scopeChain() const |
|
201 { |
|
202 return u.scopeChain; |
|
203 } |
|
204 |
|
205 ALWAYS_INLINE Instruction* Register::vPC() const |
|
206 { |
|
207 return u.vPC; |
|
208 } |
|
209 |
|
210 } // namespace JSC |
|
211 |
|
212 namespace WTF { |
|
213 |
|
214 template<> struct VectorTraits<JSC::Register> : VectorTraitsBase<true, JSC::Register> { }; |
|
215 |
|
216 } // namespace WTF |
|
217 |
|
218 #endif // Register_h |