]> git.saurik.com Git - apple/javascriptcore.git/blob - bytecode/ResolveOperation.h
JavaScriptCore-1218.0.1.tar.gz
[apple/javascriptcore.git] / bytecode / ResolveOperation.h
1 /*
2 * Copyright (C) 2012 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 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef ResolveOperation_h
27 #define ResolveOperation_h
28
29 #include "PropertyOffset.h"
30 #include "WriteBarrier.h"
31
32 #include <wtf/Vector.h>
33
34 namespace JSC {
35
36 class Structure;
37
38 struct ResolveOperation {
39 typedef enum {
40 Fail,
41 SetBaseToUndefined,
42 ReturnScopeAsBase,
43 SetBaseToScope,
44 SetBaseToGlobal,
45 GetAndReturnScopedVar,
46 GetAndReturnGlobalVar,
47 GetAndReturnGlobalVarWatchable,
48 SkipTopScopeNode,
49 SkipScopes,
50 ReturnGlobalObjectAsBase,
51 GetAndReturnGlobalProperty,
52 CheckForDynamicEntriesBeforeGlobalScope
53 } ResolveOperationType;
54
55 ResolveOperationType m_operation;
56 WriteBarrier<Structure> m_structure;
57 union {
58 PropertyOffset m_offset;
59 WriteBarrier<Unknown>* m_registerAddress;
60 int m_scopesToSkip;
61 int m_activationRegister;
62 };
63 static ResolveOperation getAndReturnScopedVar(PropertyOffset offset)
64 {
65 ResolveOperation op;
66 op.m_operation = GetAndReturnScopedVar;
67 op.m_offset = offset;
68 return op;
69 }
70 static ResolveOperation checkForDynamicEntriesBeforeGlobalScope()
71 {
72 ResolveOperation op;
73 op.m_operation = CheckForDynamicEntriesBeforeGlobalScope;
74 return op;
75 }
76
77 static ResolveOperation getAndReturnGlobalVar(WriteBarrier<Unknown>* registerAddress, bool couldBeWatched)
78 {
79 ResolveOperation op;
80 op.m_operation = couldBeWatched ? GetAndReturnGlobalVarWatchable : GetAndReturnGlobalVar;
81 op.m_registerAddress = registerAddress;
82 return op;
83 }
84 static ResolveOperation getAndReturnGlobalProperty()
85 {
86 ResolveOperation op;
87 op.m_operation = GetAndReturnGlobalProperty;
88 return op;
89 }
90 static ResolveOperation resolveFail()
91 {
92 ResolveOperation op;
93 op.m_operation = Fail;
94 return op;
95 }
96 static ResolveOperation skipTopScopeNode(int activationRegister)
97 {
98 ResolveOperation op;
99 op.m_operation = SkipTopScopeNode;
100 op.m_activationRegister = activationRegister;
101 return op;
102 }
103 static ResolveOperation skipScopes(int scopesToSkip)
104 {
105 ResolveOperation op;
106 op.m_operation = SkipScopes;
107 op.m_scopesToSkip = scopesToSkip;
108 return op;
109 }
110 static ResolveOperation returnGlobalObjectAsBase()
111 {
112 ResolveOperation op;
113 op.m_operation = ReturnGlobalObjectAsBase;
114 return op;
115 }
116 static ResolveOperation setBaseToGlobal()
117 {
118 ResolveOperation op;
119 op.m_operation = SetBaseToGlobal;
120 return op;
121 }
122 static ResolveOperation setBaseToUndefined()
123 {
124 ResolveOperation op;
125 op.m_operation = SetBaseToUndefined;
126 return op;
127 }
128 static ResolveOperation setBaseToScope()
129 {
130 ResolveOperation op;
131 op.m_operation = SetBaseToScope;
132 return op;
133 }
134 static ResolveOperation returnScopeAsBase()
135 {
136 ResolveOperation op;
137 op.m_operation = ReturnScopeAsBase;
138 return op;
139 }
140 };
141
142 typedef Vector<ResolveOperation> ResolveOperations;
143
144 struct PutToBaseOperation {
145 PutToBaseOperation(bool isStrict)
146 : m_kind(Uninitialised)
147 , m_isDynamic(false)
148 , m_isStrict(isStrict)
149 , m_predicatePointer(0)
150 {
151
152 }
153 enum Kind { Uninitialised, Generic, Readonly, GlobalVariablePut, GlobalVariablePutChecked, GlobalPropertyPut, VariablePut };
154 union {
155 Kind m_kind : 8;
156 uint8_t m_kindAsUint8;
157 };
158 bool m_isDynamic : 8;
159 bool m_isStrict : 8;
160 union {
161 bool* m_predicatePointer;
162 unsigned m_scopeDepth;
163 };
164 WriteBarrier<Structure> m_structure;
165 union {
166 // Used for GlobalVariablePut
167 WriteBarrier<Unknown>* m_registerAddress;
168
169 // Used for GlobalPropertyPut and VariablePut
170 struct {
171 PropertyOffset m_offset;
172 int32_t m_offsetInButterfly;
173 };
174 };
175 };
176 }
177
178 #endif // ResolveOperation_h