2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
33 #include <wtf/VectorTraits.h>
42 class JSPropertyNameIterator
;
47 typedef ExecState CallFrame
;
54 JSValuePtr
jsValue(CallFrame
*) const;
55 JSValuePtr
getJSValue() const;
61 friend class ExecState
;
62 friend class Interpreter
;
64 // Only CallFrame and Interpreter should use these functions.
68 Register(JSActivation
*);
72 Register(JSFunction
*);
73 Register(JSPropertyNameIterator
*);
74 Register(ScopeChainNode
*);
75 Register(Instruction
*);
80 JSActivation
* activation() const;
81 Arguments
* arguments() const;
82 CallFrame
* callFrame() const;
83 CodeBlock
* codeBlock() const;
84 JSFunction
* function() const;
85 JSPropertyNameIterator
* propertyNameIterator() const;
86 ScopeChainNode
* scopeChain() const;
87 Instruction
* vPC() const;
92 JSValueEncodedAsPointer
* value
;
94 JSActivation
* activation
;
99 JSPropertyNameIterator
* propertyNameIterator
;
100 ScopeChainNode
* scopeChain
;
117 PropertyNameIteratorType
,
125 #define SET_TYPE(type) m_type = (type)
126 // FIXME: The CTI code to put value into registers doesn't set m_type.
127 // Once it does, we can turn this assertion back on.
128 #define ASSERT_TYPE(type)
130 #define SET_TYPE(type)
131 #define ASSERT_TYPE(type)
134 ALWAYS_INLINE
Register::Register()
138 u
.value
= JSValuePtr::encode(noValue());
142 ALWAYS_INLINE
Register::Register(JSValuePtr v
)
145 u
.value
= JSValuePtr::encode(v
);
148 // This function is scaffolding for legacy clients. It will eventually go away.
149 ALWAYS_INLINE JSValuePtr
Register::jsValue(CallFrame
*) const
151 // Once registers hold doubles, this function will allocate a JSValue*
152 // if the register doesn't hold one already.
153 ASSERT_TYPE(ValueType
);
154 return JSValuePtr::decode(u
.value
);
157 ALWAYS_INLINE JSValuePtr
Register::getJSValue() const
159 ASSERT_TYPE(JSValueType
);
160 return JSValuePtr::decode(u
.value
);
163 ALWAYS_INLINE
bool Register::marked() const
165 return getJSValue().marked();
168 ALWAYS_INLINE
void Register::mark()
173 // Interpreter functions
175 ALWAYS_INLINE
Register::Register(Arguments
* arguments
)
177 SET_TYPE(ArgumentsType
);
178 u
.arguments
= arguments
;
181 ALWAYS_INLINE
Register::Register(JSActivation
* activation
)
183 SET_TYPE(ActivationType
);
184 u
.activation
= activation
;
187 ALWAYS_INLINE
Register::Register(CallFrame
* callFrame
)
189 SET_TYPE(CallFrameType
);
190 u
.callFrame
= callFrame
;
193 ALWAYS_INLINE
Register::Register(CodeBlock
* codeBlock
)
195 SET_TYPE(CodeBlockType
);
196 u
.codeBlock
= codeBlock
;
199 ALWAYS_INLINE
Register::Register(JSFunction
* function
)
201 SET_TYPE(FunctionType
);
202 u
.function
= function
;
205 ALWAYS_INLINE
Register::Register(Instruction
* vPC
)
207 SET_TYPE(InstructionType
);
211 ALWAYS_INLINE
Register::Register(ScopeChainNode
* scopeChain
)
213 SET_TYPE(ScopeChainNodeType
);
214 u
.scopeChain
= scopeChain
;
217 ALWAYS_INLINE
Register::Register(JSPropertyNameIterator
* propertyNameIterator
)
219 SET_TYPE(PropertyNameIteratorType
);
220 u
.propertyNameIterator
= propertyNameIterator
;
223 ALWAYS_INLINE
Register::Register(intptr_t i
)
229 ALWAYS_INLINE
intptr_t Register::i() const
231 ASSERT_TYPE(IntType
);
235 ALWAYS_INLINE
void* Register::v() const
240 ALWAYS_INLINE JSActivation
* Register::activation() const
242 ASSERT_TYPE(ActivationType
);
246 ALWAYS_INLINE Arguments
* Register::arguments() const
248 ASSERT_TYPE(ArgumentsType
);
252 ALWAYS_INLINE CallFrame
* Register::callFrame() const
254 ASSERT_TYPE(CallFrameType
);
258 ALWAYS_INLINE CodeBlock
* Register::codeBlock() const
260 ASSERT_TYPE(CodeBlockType
);
264 ALWAYS_INLINE JSFunction
* Register::function() const
266 ASSERT_TYPE(FunctionType
);
270 ALWAYS_INLINE JSPropertyNameIterator
* Register::propertyNameIterator() const
272 ASSERT_TYPE(PropertyNameIteratorType
);
273 return u
.propertyNameIterator
;
276 ALWAYS_INLINE ScopeChainNode
* Register::scopeChain() const
278 ASSERT_TYPE(ScopeChainNodeType
);
282 ALWAYS_INLINE Instruction
* Register::vPC() const
284 ASSERT_TYPE(InstructionType
);
295 template<> struct VectorTraits
<JSC::Register
> : VectorTraitsBase
<true, JSC::Register
> { };