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