]> git.saurik.com Git - apple/javascriptcore.git/blob - dfg/DFGOperations.h
JavaScriptCore-1097.13.tar.gz
[apple/javascriptcore.git] / dfg / DFGOperations.h
1 /*
2 * Copyright (C) 2011 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 DFGOperations_h
27 #define DFGOperations_h
28
29 #if ENABLE(DFG_JIT)
30
31 #include "DFGJITCompiler.h"
32 #include "PutKind.h"
33
34 namespace JSC {
35
36 struct GlobalResolveInfo;
37
38 namespace DFG {
39
40 extern "C" {
41
42 #if CALLING_CONVENTION_IS_STDCALL
43 #define DFG_OPERATION CDECL
44 #else
45 #define DFG_OPERATION
46 #endif
47
48 // These typedefs provide typechecking when generating calls out to helper routines;
49 // this helps prevent calling a helper routine with the wrong arguments!
50 /*
51 Key:
52 V: void
53 J: JSValue
54 P: pointer (void*)
55 C: JSCell*
56 A: JSArray*
57 S: size_t
58 Z: int32_t
59 D: double
60 I: Identifier*
61 G: GlobalResolveInfo*
62 */
63 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EA)(ExecState*, JSArray*);
64 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_ECC)(ExecState*, JSCell*, JSCell*);
65 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_ECI)(ExecState*, JSCell*, Identifier*);
66 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_ECJ)(ExecState*, JSCell*, EncodedJSValue);
67 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EGI)(ExecState*, GlobalResolveInfo*, Identifier*);
68 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EI)(ExecState*, Identifier*);
69 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EJ)(ExecState*, EncodedJSValue);
70 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EJA)(ExecState*, EncodedJSValue, JSArray*);
71 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EJI)(ExecState*, EncodedJSValue, Identifier*);
72 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EJJ)(ExecState*, EncodedJSValue, EncodedJSValue);
73 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EJP)(ExecState*, EncodedJSValue, void*);
74 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EP)(ExecState*, void*);
75 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EPP)(ExecState*, void*, void*);
76 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_EPS)(ExecState*, void*, size_t);
77 typedef EncodedJSValue DFG_OPERATION (*J_DFGOperation_ESS)(ExecState*, size_t, size_t);
78 typedef JSCell* DFG_OPERATION (*C_DFGOperation_E)(ExecState*);
79 typedef JSCell* DFG_OPERATION (*C_DFGOperation_EC)(ExecState*, JSCell*);
80 typedef JSCell* DFG_OPERATION (*C_DFGOperation_ECC)(ExecState*, JSCell*, JSCell*);
81 typedef double DFG_OPERATION (*D_DFGOperation_DD)(double, double);
82 typedef double DFG_OPERATION (*D_DFGOperation_ZZ)(int32_t, int32_t);
83 typedef double DFG_OPERATION (*D_DFGOperation_EJ)(ExecState*, EncodedJSValue);
84 typedef int32_t DFG_OPERATION (*Z_DFGOperation_D)(double);
85 typedef size_t DFG_OPERATION (*S_DFGOperation_ECC)(ExecState*, JSCell*, JSCell*);
86 typedef size_t DFG_OPERATION (*S_DFGOperation_EJ)(ExecState*, EncodedJSValue);
87 typedef size_t DFG_OPERATION (*S_DFGOperation_EJJ)(ExecState*, EncodedJSValue, EncodedJSValue);
88 typedef size_t DFG_OPERATION (*S_DFGOperation_J)(EncodedJSValue);
89 typedef void DFG_OPERATION (*V_DFGOperation_EAZJ)(ExecState*, JSArray*, int32_t, EncodedJSValue);
90 typedef void DFG_OPERATION (*V_DFGOperation_ECJJ)(ExecState*, JSCell*, EncodedJSValue, EncodedJSValue);
91 typedef void DFG_OPERATION (*V_DFGOperation_EJCI)(ExecState*, EncodedJSValue, JSCell*, Identifier*);
92 typedef void DFG_OPERATION (*V_DFGOperation_EJJJ)(ExecState*, EncodedJSValue, EncodedJSValue, EncodedJSValue);
93 typedef void DFG_OPERATION (*V_DFGOperation_EJPP)(ExecState*, EncodedJSValue, EncodedJSValue, void*);
94 typedef void DFG_OPERATION (*V_DFGOperation_EPZJ)(ExecState*, void*, int32_t, EncodedJSValue);
95 typedef void DFG_OPERATION (V_DFGOperation_EC)(ExecState*, JSCell*);
96 typedef void* DFG_OPERATION (*P_DFGOperation_E)(ExecState*);
97
98 // These routines are provide callbacks out to C++ implementations of operations too complex to JIT.
99 JSCell* DFG_OPERATION operationNewObject(ExecState*);
100 JSCell* DFG_OPERATION operationCreateThis(ExecState*, JSCell* encodedOp1);
101 JSCell* DFG_OPERATION operationCreateThisInlined(ExecState*, JSCell* encodedOp1, JSCell* constructor);
102 EncodedJSValue DFG_OPERATION operationConvertThis(ExecState*, EncodedJSValue encodedOp1);
103 EncodedJSValue DFG_OPERATION operationValueAdd(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
104 EncodedJSValue DFG_OPERATION operationValueAddNotNumber(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
105 EncodedJSValue DFG_OPERATION operationGetByVal(ExecState*, EncodedJSValue encodedBase, EncodedJSValue encodedProperty);
106 EncodedJSValue DFG_OPERATION operationGetByValCell(ExecState*, JSCell*, EncodedJSValue encodedProperty);
107 EncodedJSValue DFG_OPERATION operationGetById(ExecState*, EncodedJSValue, Identifier*);
108 EncodedJSValue DFG_OPERATION operationGetByIdBuildList(ExecState*, EncodedJSValue, Identifier*);
109 EncodedJSValue DFG_OPERATION operationGetByIdProtoBuildList(ExecState*, EncodedJSValue, Identifier*);
110 EncodedJSValue DFG_OPERATION operationGetByIdOptimize(ExecState*, EncodedJSValue, Identifier*);
111 EncodedJSValue DFG_OPERATION operationCallCustomGetter(ExecState*, JSCell*, PropertySlot::GetValueFunc, Identifier*);
112 EncodedJSValue DFG_OPERATION operationCallGetter(ExecState*, JSCell*, JSCell*);
113 EncodedJSValue DFG_OPERATION operationResolve(ExecState*, Identifier*);
114 EncodedJSValue DFG_OPERATION operationResolveBase(ExecState*, Identifier*);
115 EncodedJSValue DFG_OPERATION operationResolveBaseStrictPut(ExecState*, Identifier*);
116 EncodedJSValue DFG_OPERATION operationResolveGlobal(ExecState*, GlobalResolveInfo*, Identifier*);
117 EncodedJSValue DFG_OPERATION operationToPrimitive(ExecState*, EncodedJSValue);
118 EncodedJSValue DFG_OPERATION operationStrCat(ExecState*, void*, size_t);
119 EncodedJSValue DFG_OPERATION operationNewArray(ExecState*, void*, size_t);
120 EncodedJSValue DFG_OPERATION operationNewArrayBuffer(ExecState*, size_t, size_t);
121 EncodedJSValue DFG_OPERATION operationNewRegexp(ExecState*, void*);
122 void DFG_OPERATION operationPutByValStrict(ExecState*, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue);
123 void DFG_OPERATION operationPutByValNonStrict(ExecState*, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue);
124 void DFG_OPERATION operationPutByValCellStrict(ExecState*, JSCell*, EncodedJSValue encodedProperty, EncodedJSValue encodedValue);
125 void DFG_OPERATION operationPutByValCellNonStrict(ExecState*, JSCell*, EncodedJSValue encodedProperty, EncodedJSValue encodedValue);
126 void DFG_OPERATION operationPutByValBeyondArrayBoundsStrict(ExecState*, JSArray*, int32_t index, EncodedJSValue encodedValue);
127 void DFG_OPERATION operationPutByValBeyondArrayBoundsNonStrict(ExecState*, JSArray*, int32_t index, EncodedJSValue encodedValue);
128 EncodedJSValue DFG_OPERATION operationArrayPush(ExecState*, EncodedJSValue encodedValue, JSArray*);
129 EncodedJSValue DFG_OPERATION operationArrayPop(ExecState*, JSArray*);
130 EncodedJSValue DFG_OPERATION operationRegExpExec(ExecState*, JSCell*, JSCell*);
131 void DFG_OPERATION operationPutByIdStrict(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
132 void DFG_OPERATION operationPutByIdNonStrict(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
133 void DFG_OPERATION operationPutByIdDirectStrict(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
134 void DFG_OPERATION operationPutByIdDirectNonStrict(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
135 void DFG_OPERATION operationPutByIdStrictOptimize(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
136 void DFG_OPERATION operationPutByIdNonStrictOptimize(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
137 void DFG_OPERATION operationPutByIdDirectStrictOptimize(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
138 void DFG_OPERATION operationPutByIdDirectNonStrictOptimize(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
139 void DFG_OPERATION operationPutByIdStrictBuildList(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
140 void DFG_OPERATION operationPutByIdNonStrictBuildList(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
141 void DFG_OPERATION operationPutByIdDirectStrictBuildList(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
142 void DFG_OPERATION operationPutByIdDirectNonStrictBuildList(ExecState*, EncodedJSValue encodedValue, JSCell* base, Identifier*);
143 // These comparisons return a boolean within a size_t such that the value is zero extended to fill the register.
144 size_t DFG_OPERATION operationRegExpTest(ExecState*, JSCell*, JSCell*);
145 size_t DFG_OPERATION operationCompareLess(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
146 size_t DFG_OPERATION operationCompareLessEq(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
147 size_t DFG_OPERATION operationCompareGreater(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
148 size_t DFG_OPERATION operationCompareGreaterEq(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
149 size_t DFG_OPERATION operationCompareEq(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
150 size_t DFG_OPERATION operationCompareStrictEqCell(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
151 size_t DFG_OPERATION operationCompareStrictEq(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
152 void* DFG_OPERATION operationVirtualCall(ExecState*);
153 void* DFG_OPERATION operationLinkCall(ExecState*);
154 void* DFG_OPERATION operationVirtualConstruct(ExecState*);
155 void* DFG_OPERATION operationLinkConstruct(ExecState*);
156 JSCell* DFG_OPERATION operationCreateActivation(ExecState*);
157 void DFG_OPERATION operationTearOffActivation(ExecState*, JSCell*);
158 JSCell* DFG_OPERATION operationNewFunction(ExecState*, JSCell*);
159 JSCell* DFG_OPERATION operationNewFunctionExpression(ExecState*, JSCell*);
160 double DFG_OPERATION operationFModOnInts(int32_t, int32_t);
161 size_t DFG_OPERATION operationIsObject(EncodedJSValue);
162 size_t DFG_OPERATION operationIsFunction(EncodedJSValue);
163
164 // This method is used to lookup an exception hander, keyed by faultLocation, which is
165 // the return location from one of the calls out to one of the helper operations above.
166
167 // According to C++ rules, a type used for the return signature of function with C linkage (i.e.
168 // 'extern "C"') needs to be POD; hence putting any constructors into it could cause either compiler
169 // warnings, or worse, a change in the ABI used to return these types.
170 struct DFGHandler {
171 union Union {
172 struct Struct {
173 ExecState* exec;
174 void* handler;
175 } s;
176 uint64_t encoded;
177 } u;
178 };
179
180 inline DFGHandler createDFGHandler(ExecState* exec, void* handler)
181 {
182 DFGHandler result;
183 result.u.s.exec = exec;
184 result.u.s.handler = handler;
185 return result;
186 }
187
188 #if CPU(X86_64)
189 typedef DFGHandler DFGHandlerEncoded;
190 inline DFGHandlerEncoded dfgHandlerEncoded(ExecState* exec, void* handler)
191 {
192 return createDFGHandler(exec, handler);
193 }
194 #else
195 typedef uint64_t DFGHandlerEncoded;
196 inline DFGHandlerEncoded dfgHandlerEncoded(ExecState* exec, void* handler)
197 {
198 COMPILE_ASSERT(sizeof(DFGHandler::Union) == sizeof(uint64_t), DFGHandler_Union_is_64bit);
199 return createDFGHandler(exec, handler).u.encoded;
200 }
201 #endif
202 DFGHandlerEncoded DFG_OPERATION lookupExceptionHandler(ExecState*, uint32_t);
203 DFGHandlerEncoded DFG_OPERATION lookupExceptionHandlerInStub(ExecState*, StructureStubInfo*);
204
205 // These operations implement the implicitly called ToInt32, ToNumber, and ToBoolean conversions from ES5.
206 double DFG_OPERATION dfgConvertJSValueToNumber(ExecState*, EncodedJSValue);
207 // This conversion returns an int32_t within a size_t such that the value is zero extended to fill the register.
208 size_t DFG_OPERATION dfgConvertJSValueToInt32(ExecState*, EncodedJSValue);
209 size_t DFG_OPERATION dfgConvertJSValueToBoolean(ExecState*, EncodedJSValue);
210
211 #if DFG_ENABLE(VERBOSE_SPECULATION_FAILURE)
212 void DFG_OPERATION debugOperationPrintSpeculationFailure(ExecState*, void*);
213 #endif
214
215 } // extern "C"
216 } } // namespace JSC::DFG
217
218 #endif
219 #endif