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
37namespace JSC {
38
39 class Arguments;
40 class CodeBlock;
41 class ExecState;
42 class JSActivation;
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=(JSObject*);
62 Register& operator=(JSPropertyNameIterator*);
63 Register& operator=(ScopeChainNode*);
64 Register& operator=(Instruction*);
65
66 int32_t i() const;
67 JSActivation* activation() const;
68 Arguments* arguments() const;
69 CallFrame* callFrame() const;
70 CodeBlock* codeBlock() const;
71 JSObject* object() const;
72 JSPropertyNameIterator* propertyNameIterator() const;
73 ScopeChainNode* scopeChain() const;
74 Instruction* vPC() const;
75
76 static Register withInt(int32_t i)
77 {
78 Register r;
79 r.u.i = i;
80 return r;
81 }
82
83 private:
84 union {
85 int32_t i;
86 EncodedJSValue value;
87
88 JSActivation* activation;
89 CallFrame* callFrame;
90 CodeBlock* codeBlock;
91 JSObject* object;
92 JSPropertyNameIterator* propertyNameIterator;
93 ScopeChainNode* scopeChain;
94 Instruction* vPC;
95 } u;
96 };
97
98 ALWAYS_INLINE Register::Register()
99 {
100#ifndef NDEBUG
101 *this = JSValue();
102#endif
103 }
104
105 ALWAYS_INLINE Register::Register(const JSValue& v)
106 {
107#if ENABLE(JSC_ZOMBIES)
108 ASSERT(!v.isZombie());
109#endif
110 u.value = JSValue::encode(value: v);
111 }
112
113 ALWAYS_INLINE Register& Register::operator=(const JSValue& v)
114 {
115#if ENABLE(JSC_ZOMBIES)
116 ASSERT(!v.isZombie());
117#endif
118 u.value = JSValue::encode(value: v);
119 return *this;
120 }
121
122 ALWAYS_INLINE JSValue Register::jsValue() const
123 {
124 return JSValue::decode(ptr: u.value);
125 }
126
127 // Interpreter functions
128
129 ALWAYS_INLINE Register& Register::operator=(JSActivation* activation)
130 {
131 u.activation = activation;
132 return *this;
133 }
134
135 ALWAYS_INLINE Register& Register::operator=(CallFrame* callFrame)
136 {
137 u.callFrame = callFrame;
138 return *this;
139 }
140
141 ALWAYS_INLINE Register& Register::operator=(CodeBlock* codeBlock)
142 {
143 u.codeBlock = codeBlock;
144 return *this;
145 }
146
147 ALWAYS_INLINE Register& Register::operator=(JSObject* object)
148 {
149 u.object = object;
150 return *this;
151 }
152
153 ALWAYS_INLINE Register& Register::operator=(Instruction* vPC)
154 {
155 u.vPC = vPC;
156 return *this;
157 }
158
159 ALWAYS_INLINE Register& Register::operator=(ScopeChainNode* scopeChain)
160 {
161 u.scopeChain = scopeChain;
162 return *this;
163 }
164
165 ALWAYS_INLINE Register& Register::operator=(JSPropertyNameIterator* propertyNameIterator)
166 {
167 u.propertyNameIterator = propertyNameIterator;
168 return *this;
169 }
170
171 ALWAYS_INLINE int32_t Register::i() const
172 {
173 return u.i;
174 }
175
176 ALWAYS_INLINE JSActivation* Register::activation() const
177 {
178 return u.activation;
179 }
180
181 ALWAYS_INLINE CallFrame* Register::callFrame() const
182 {
183 return u.callFrame;
184 }
185
186 ALWAYS_INLINE CodeBlock* Register::codeBlock() const
187 {
188 return u.codeBlock;
189 }
190
191 ALWAYS_INLINE JSObject* Register::object() const
192 {
193 return u.object;
194 }
195
196 ALWAYS_INLINE JSPropertyNameIterator* Register::propertyNameIterator() const
197 {
198 return u.propertyNameIterator;
199 }
200
201 ALWAYS_INLINE ScopeChainNode* Register::scopeChain() const
202 {
203 return u.scopeChain;
204 }
205
206 ALWAYS_INLINE Instruction* Register::vPC() const
207 {
208 return u.vPC;
209 }
210
211} // namespace JSC
212
213namespace WTF {
214
215 template<> struct VectorTraits<JSC::Register> : VectorTraitsBase<true, JSC::Register> { };
216
217} // namespace WTF
218
219#endif // Register_h
220

source code of qtscript/src/3rdparty/javascriptcore/JavaScriptCore/interpreter/Register.h