]>
Commit | Line | Data |
---|---|---|
9dae56ea | 1 | /* |
f9bf01c6 | 2 | * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
9dae56ea A |
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. | |
81345200 | 13 | * 3. Neither the name of Apple Inc. ("Apple") nor the names of |
9dae56ea A |
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 | ||
93a37866 | 32 | #include "JSCJSValue.h" |
ba379fdc | 33 | #include <wtf/Assertions.h> |
9dae56ea A |
34 | #include <wtf/VectorTraits.h> |
35 | ||
36 | namespace JSC { | |
37 | ||
9dae56ea A |
38 | class CodeBlock; |
39 | class ExecState; | |
40 | class JSActivation; | |
14957cd0 | 41 | class JSObject; |
9dae56ea | 42 | class JSPropertyNameIterator; |
93a37866 | 43 | class JSScope; |
9dae56ea | 44 | |
9dae56ea A |
45 | typedef ExecState CallFrame; |
46 | ||
14957cd0 A |
47 | class Register { |
48 | WTF_MAKE_FAST_ALLOCATED; | |
9dae56ea A |
49 | public: |
50 | Register(); | |
9dae56ea | 51 | |
ba379fdc A |
52 | Register(const JSValue&); |
53 | Register& operator=(const JSValue&); | |
54 | JSValue jsValue() const; | |
14957cd0 | 55 | EncodedJSValue encodedJSValue() const; |
9dae56ea | 56 | |
ba379fdc A |
57 | Register& operator=(CallFrame*); |
58 | Register& operator=(CodeBlock*); | |
93a37866 | 59 | Register& operator=(JSScope*); |
ba379fdc A |
60 | |
61 | int32_t i() const; | |
9dae56ea | 62 | JSActivation* activation() const; |
9dae56ea A |
63 | CallFrame* callFrame() const; |
64 | CodeBlock* codeBlock() const; | |
14957cd0 | 65 | JSObject* function() const; |
9dae56ea | 66 | JSPropertyNameIterator* propertyNameIterator() const; |
93a37866 | 67 | JSScope* scope() const; |
6fe7ccc8 | 68 | int32_t unboxedInt32() const; |
81345200 A |
69 | int64_t unboxedInt52() const; |
70 | int64_t unboxedStrictInt52() const; | |
6fe7ccc8 | 71 | bool unboxedBoolean() const; |
81345200 | 72 | double unboxedDouble() const; |
6fe7ccc8 A |
73 | JSCell* unboxedCell() const; |
74 | int32_t payload() const; | |
75 | int32_t tag() const; | |
76 | int32_t& payload(); | |
77 | int32_t& tag(); | |
9dae56ea | 78 | |
ba379fdc A |
79 | static Register withInt(int32_t i) |
80 | { | |
14957cd0 | 81 | Register r = jsNumber(i); |
ba379fdc A |
82 | return r; |
83 | } | |
84 | ||
6fe7ccc8 | 85 | static Register withCallee(JSObject* callee); |
14957cd0 | 86 | |
ba379fdc | 87 | private: |
9dae56ea | 88 | union { |
ba379fdc | 89 | EncodedJSValue value; |
9dae56ea A |
90 | CallFrame* callFrame; |
91 | CodeBlock* codeBlock; | |
6fe7ccc8 | 92 | EncodedValueDescriptor encodedValue; |
81345200 A |
93 | double number; |
94 | int64_t integer; | |
9dae56ea | 95 | } u; |
9dae56ea A |
96 | }; |
97 | ||
9dae56ea A |
98 | ALWAYS_INLINE Register::Register() |
99 | { | |
100 | #ifndef NDEBUG | |
ba379fdc | 101 | *this = JSValue(); |
9dae56ea A |
102 | #endif |
103 | } | |
104 | ||
ba379fdc | 105 | ALWAYS_INLINE Register::Register(const JSValue& v) |
9dae56ea | 106 | { |
ba379fdc | 107 | u.value = JSValue::encode(v); |
9dae56ea A |
108 | } |
109 | ||
ba379fdc | 110 | ALWAYS_INLINE Register& Register::operator=(const JSValue& v) |
9dae56ea | 111 | { |
ba379fdc A |
112 | u.value = JSValue::encode(v); |
113 | return *this; | |
9dae56ea | 114 | } |
ba379fdc A |
115 | |
116 | ALWAYS_INLINE JSValue Register::jsValue() const | |
9dae56ea | 117 | { |
ba379fdc | 118 | return JSValue::decode(u.value); |
9dae56ea | 119 | } |
9dae56ea | 120 | |
14957cd0 | 121 | ALWAYS_INLINE EncodedJSValue Register::encodedJSValue() const |
9dae56ea | 122 | { |
14957cd0 | 123 | return u.value; |
9dae56ea A |
124 | } |
125 | ||
14957cd0 A |
126 | // Interpreter functions |
127 | ||
ba379fdc | 128 | ALWAYS_INLINE Register& Register::operator=(CallFrame* callFrame) |
9dae56ea | 129 | { |
9dae56ea | 130 | u.callFrame = callFrame; |
ba379fdc | 131 | return *this; |
9dae56ea A |
132 | } |
133 | ||
ba379fdc | 134 | ALWAYS_INLINE Register& Register::operator=(CodeBlock* codeBlock) |
9dae56ea | 135 | { |
9dae56ea | 136 | u.codeBlock = codeBlock; |
ba379fdc | 137 | return *this; |
9dae56ea A |
138 | } |
139 | ||
ba379fdc | 140 | ALWAYS_INLINE int32_t Register::i() const |
9dae56ea | 141 | { |
14957cd0 | 142 | return jsValue().asInt32(); |
9dae56ea | 143 | } |
14957cd0 | 144 | |
9dae56ea A |
145 | ALWAYS_INLINE CallFrame* Register::callFrame() const |
146 | { | |
9dae56ea A |
147 | return u.callFrame; |
148 | } | |
149 | ||
150 | ALWAYS_INLINE CodeBlock* Register::codeBlock() const | |
151 | { | |
9dae56ea A |
152 | return u.codeBlock; |
153 | } | |
14957cd0 | 154 | |
81345200 | 155 | ALWAYS_INLINE int32_t Register::unboxedInt32() const |
9dae56ea | 156 | { |
81345200 | 157 | return payload(); |
9dae56ea A |
158 | } |
159 | ||
81345200 | 160 | ALWAYS_INLINE int64_t Register::unboxedInt52() const |
6fe7ccc8 | 161 | { |
81345200 | 162 | return u.integer >> JSValue::int52ShiftAmount; |
6fe7ccc8 | 163 | } |
81345200 A |
164 | |
165 | ALWAYS_INLINE int64_t Register::unboxedStrictInt52() const | |
6fe7ccc8 | 166 | { |
81345200 | 167 | return u.integer; |
6fe7ccc8 A |
168 | } |
169 | ||
170 | ALWAYS_INLINE bool Register::unboxedBoolean() const | |
171 | { | |
172 | return !!payload(); | |
173 | } | |
174 | ||
81345200 A |
175 | ALWAYS_INLINE double Register::unboxedDouble() const |
176 | { | |
177 | return u.number; | |
178 | } | |
179 | ||
6fe7ccc8 A |
180 | ALWAYS_INLINE JSCell* Register::unboxedCell() const |
181 | { | |
182 | #if USE(JSVALUE64) | |
183 | return u.encodedValue.ptr; | |
184 | #else | |
185 | return bitwise_cast<JSCell*>(payload()); | |
186 | #endif | |
187 | } | |
188 | ||
189 | ALWAYS_INLINE int32_t Register::payload() const | |
190 | { | |
191 | return u.encodedValue.asBits.payload; | |
192 | } | |
193 | ||
194 | ALWAYS_INLINE int32_t Register::tag() const | |
195 | { | |
196 | return u.encodedValue.asBits.tag; | |
197 | } | |
198 | ||
199 | ALWAYS_INLINE int32_t& Register::payload() | |
200 | { | |
201 | return u.encodedValue.asBits.payload; | |
202 | } | |
203 | ||
204 | ALWAYS_INLINE int32_t& Register::tag() | |
205 | { | |
206 | return u.encodedValue.asBits.tag; | |
207 | } | |
208 | ||
9dae56ea A |
209 | } // namespace JSC |
210 | ||
211 | namespace WTF { | |
212 | ||
213 | template<> struct VectorTraits<JSC::Register> : VectorTraitsBase<true, JSC::Register> { }; | |
214 | ||
215 | } // namespace WTF | |
216 | ||
217 | #endif // Register_h |