summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/webkit/JavaScriptCore/interpreter/Register.h
blob: 9ad1815a2e31c5f8254b37c85f5d7c939f5235cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
 * Copyright (C) 2008 Apple Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef Register_h
#define Register_h

#include "JSValue.h"
#include <wtf/VectorTraits.h>

namespace JSC {

    class Arguments;
    class CodeBlock;
    class ExecState;
    class JSActivation;
    class JSFunction;
    class JSPropertyNameIterator;
    class ScopeChainNode;

    struct Instruction;

    typedef ExecState CallFrame;

    class Register {
    public:
        Register();
        Register(JSValuePtr);

        JSValuePtr jsValue(CallFrame*) const;
        JSValuePtr getJSValue() const;

        bool marked() const;
        void mark();
        
    private:
        friend class ExecState;
        friend class Interpreter;

        // Only CallFrame and Interpreter should use these functions.

        Register(intptr_t);

        Register(JSActivation*);
        Register(Arguments*);
        Register(CallFrame*);
        Register(CodeBlock*);
        Register(JSFunction*);
        Register(JSPropertyNameIterator*);
        Register(ScopeChainNode*);
        Register(Instruction*);

        intptr_t i() const;
        void* v() const;

        JSActivation* activation() const;
        Arguments* arguments() const;
        CallFrame* callFrame() const;
        CodeBlock* codeBlock() const;
        JSFunction* function() const;
        JSPropertyNameIterator* propertyNameIterator() const;
        ScopeChainNode* scopeChain() const;
        Instruction* vPC() const;

        union {
            intptr_t i;
            void* v;
            JSValueEncodedAsPointer* value;

            JSActivation* activation;
            Arguments* arguments;
            CallFrame* callFrame;
            CodeBlock* codeBlock;
            JSFunction* function;
            JSPropertyNameIterator* propertyNameIterator;
            ScopeChainNode* scopeChain;
            Instruction* vPC;
        } u;

#ifndef NDEBUG
        enum {
            EmptyType,

            IntType,
            ValueType,

            ActivationType,
            ArgumentsType,
            CallFrameType,
            CodeBlockType,
            FunctionType,
            InstructionType,
            PropertyNameIteratorType,
            RegisterType,
            ScopeChainNodeType
        } m_type;
#endif
    };

#ifndef NDEBUG
    #define SET_TYPE(type) m_type = (type)
    // FIXME: The CTI code to put value into registers doesn't set m_type.
    // Once it does, we can turn this assertion back on.
    #define ASSERT_TYPE(type)
#else
    #define SET_TYPE(type)
    #define ASSERT_TYPE(type)
#endif

    ALWAYS_INLINE Register::Register()
    {
#ifndef NDEBUG
        SET_TYPE(EmptyType);
        u.value = JSValuePtr::encode(noValue());
#endif
    }

    ALWAYS_INLINE Register::Register(JSValuePtr v)
    {
        SET_TYPE(ValueType);
        u.value = JSValuePtr::encode(v);
    }

    // This function is scaffolding for legacy clients. It will eventually go away.
    ALWAYS_INLINE JSValuePtr Register::jsValue(CallFrame*) const
    {
        // Once registers hold doubles, this function will allocate a JSValue*
        // if the register doesn't hold one already. 
        ASSERT_TYPE(ValueType);
        return JSValuePtr::decode(u.value);
    }
    
    ALWAYS_INLINE JSValuePtr Register::getJSValue() const
    {
        ASSERT_TYPE(JSValueType);
        return JSValuePtr::decode(u.value);
    }
    
    ALWAYS_INLINE bool Register::marked() const
    {
        return getJSValue()->marked();
    }

    ALWAYS_INLINE void Register::mark()
    {
        getJSValue()->mark();
    }
    
    // Interpreter functions

    ALWAYS_INLINE Register::Register(Arguments* arguments)
    {
        SET_TYPE(ArgumentsType);
        u.arguments = arguments;
    }

    ALWAYS_INLINE Register::Register(JSActivation* activation)
    {
        SET_TYPE(ActivationType);
        u.activation = activation;
    }

    ALWAYS_INLINE Register::Register(CallFrame* callFrame)
    {
        SET_TYPE(CallFrameType);
        u.callFrame = callFrame;
    }

    ALWAYS_INLINE Register::Register(CodeBlock* codeBlock)
    {
        SET_TYPE(CodeBlockType);
        u.codeBlock = codeBlock;
    }

    ALWAYS_INLINE Register::Register(JSFunction* function)
    {
        SET_TYPE(FunctionType);
        u.function = function;
    }

    ALWAYS_INLINE Register::Register(Instruction* vPC)
    {
        SET_TYPE(InstructionType);
        u.vPC = vPC;
    }

    ALWAYS_INLINE Register::Register(ScopeChainNode* scopeChain)
    {
        SET_TYPE(ScopeChainNodeType);
        u.scopeChain = scopeChain;
    }

    ALWAYS_INLINE Register::Register(JSPropertyNameIterator* propertyNameIterator)
    {
        SET_TYPE(PropertyNameIteratorType);
        u.propertyNameIterator = propertyNameIterator;
    }

    ALWAYS_INLINE Register::Register(intptr_t i)
    {
        SET_TYPE(IntType);
        u.i = i;
    }

    ALWAYS_INLINE intptr_t Register::i() const
    {
        ASSERT_TYPE(IntType);
        return u.i;
    }
    
    ALWAYS_INLINE void* Register::v() const
    {
        return u.v;
    }

    ALWAYS_INLINE JSActivation* Register::activation() const
    {
        ASSERT_TYPE(ActivationType);
        return u.activation;
    }
    
    ALWAYS_INLINE Arguments* Register::arguments() const
    {
        ASSERT_TYPE(ArgumentsType);
        return u.arguments;
    }
    
    ALWAYS_INLINE CallFrame* Register::callFrame() const
    {
        ASSERT_TYPE(CallFrameType);
        return u.callFrame;
    }
    
    ALWAYS_INLINE CodeBlock* Register::codeBlock() const
    {
        ASSERT_TYPE(CodeBlockType);
        return u.codeBlock;
    }
    
    ALWAYS_INLINE JSFunction* Register::function() const
    {
        ASSERT_TYPE(FunctionType);
        return u.function;
    }
    
    ALWAYS_INLINE JSPropertyNameIterator* Register::propertyNameIterator() const
    {
        ASSERT_TYPE(PropertyNameIteratorType);
        return u.propertyNameIterator;
    }
    
    ALWAYS_INLINE ScopeChainNode* Register::scopeChain() const
    {
        ASSERT_TYPE(ScopeChainNodeType);
        return u.scopeChain;
    }
    
    ALWAYS_INLINE Instruction* Register::vPC() const
    {
        ASSERT_TYPE(InstructionType);
        return u.vPC;
    }

    #undef SET_TYPE
    #undef ASSERT_TYPE

} // namespace JSC

namespace WTF {

    template<> struct VectorTraits<JSC::Register> : VectorTraitsBase<true, JSC::Register> { };

} // namespace WTF

#endif // Register_h