DFG JIT cannot compile op_new_object, op_new_array,
[WebKit.git] / Source / JavaScriptCore / 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 <dfg/DFGJITCompiler.h>
32
33 namespace JSC {
34
35 struct GlobalResolveInfo;
36
37 namespace DFG {
38
39 enum PutKind { Direct, NotDirect };
40
41 typedef intptr_t RegisterSizedBoolean;
42
43 extern "C" {
44
45 // These typedefs provide typechecking when generating calls out to helper routines;
46 // this helps prevent calling a helper routine with the wrong arguments!
47 typedef EncodedJSValue (*J_DFGOperation_EJJ)(ExecState*, EncodedJSValue, EncodedJSValue);
48 typedef EncodedJSValue (*J_DFGOperation_EJ)(ExecState*, EncodedJSValue);
49 typedef EncodedJSValue (*J_DFGOperation_EJP)(ExecState*, EncodedJSValue, void*);
50 typedef EncodedJSValue (*J_DFGOperation_EJI)(ExecState*, EncodedJSValue, Identifier*);
51 typedef EncodedJSValue (*J_DFGOperation_EP)(ExecState*, void*);
52 typedef EncodedJSValue (*J_DFGOperation_EPS)(ExecState*, void*, size_t);
53 typedef EncodedJSValue (*J_DFGOperation_ESS)(ExecState*, size_t, size_t);
54 typedef EncodedJSValue (*J_DFGOperation_EI)(ExecState*, Identifier*);
55 typedef RegisterSizedBoolean (*Z_DFGOperation_EJ)(ExecState*, EncodedJSValue);
56 typedef RegisterSizedBoolean (*Z_DFGOperation_EJJ)(ExecState*, EncodedJSValue, EncodedJSValue);
57 typedef void (*V_DFGOperation_EJJJ)(ExecState*, EncodedJSValue, EncodedJSValue, EncodedJSValue);
58 typedef void (*V_DFGOperation_EJJP)(ExecState*, EncodedJSValue, EncodedJSValue, void*);
59 typedef void (*V_DFGOperation_EJJI)(ExecState*, EncodedJSValue, EncodedJSValue, Identifier*);
60 typedef double (*D_DFGOperation_DD)(double, double);
61 typedef void *(*P_DFGOperation_E)(ExecState*);
62
63 // These routines are provide callbacks out to C++ implementations of operations too complex to JIT.
64 EncodedJSValue operationConvertThis(ExecState*, EncodedJSValue encodedOp1);
65 EncodedJSValue operationCreateThis(ExecState*, EncodedJSValue encodedOp1);
66 EncodedJSValue operationNewObject(ExecState*);
67 EncodedJSValue operationValueAdd(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
68 EncodedJSValue operationValueAddNotNumber(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
69 EncodedJSValue operationArithAdd(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
70 EncodedJSValue operationArithSub(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
71 EncodedJSValue operationArithMul(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
72 EncodedJSValue operationArithDiv(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
73 EncodedJSValue operationArithMod(EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
74 EncodedJSValue operationGetByVal(ExecState*, EncodedJSValue encodedBase, EncodedJSValue encodedProperty);
75 EncodedJSValue operationGetById(ExecState*, EncodedJSValue encodedBase, Identifier*);
76 EncodedJSValue operationGetByIdBuildList(ExecState*, EncodedJSValue encodedBase, Identifier*);
77 EncodedJSValue operationGetByIdProtoBuildList(ExecState*, EncodedJSValue encodedBase, Identifier*);
78 EncodedJSValue operationGetByIdOptimize(ExecState*, EncodedJSValue encodedBase, Identifier*);
79 EncodedJSValue operationGetMethodOptimize(ExecState*, EncodedJSValue encodedBase, Identifier*);
80 EncodedJSValue operationInstanceOf(ExecState*, EncodedJSValue value, EncodedJSValue base, EncodedJSValue prototype);
81 EncodedJSValue operationResolve(ExecState*, Identifier*);
82 EncodedJSValue operationResolveBase(ExecState*, Identifier*);
83 EncodedJSValue operationResolveBaseStrictPut(ExecState*, Identifier*);
84 EncodedJSValue operationResolveGlobal(ExecState*, GlobalResolveInfo*, Identifier*);
85 EncodedJSValue operationToPrimitive(ExecState*, EncodedJSValue);
86 EncodedJSValue operationStrCat(ExecState*, void* start, size_t);
87 EncodedJSValue operationNewArray(ExecState*, void* start, size_t);
88 EncodedJSValue operationNewArrayBuffer(ExecState*, size_t, size_t);
89 EncodedJSValue operationNewRegexp(ExecState*, void*);
90 void operationThrowHasInstanceError(ExecState*, EncodedJSValue base);
91 void operationPutByValStrict(ExecState*, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue);
92 void operationPutByValNonStrict(ExecState*, EncodedJSValue encodedBase, EncodedJSValue encodedProperty, EncodedJSValue encodedValue);
93 void operationPutByValBeyondArrayBounds(ExecState*, JSArray*, int32_t index, EncodedJSValue encodedValue);
94 void operationPutByIdStrict(ExecState*, EncodedJSValue encodedValue, EncodedJSValue encodedBase, Identifier*);
95 void operationPutByIdNonStrict(ExecState*, EncodedJSValue encodedValue, EncodedJSValue encodedBase, Identifier*);
96 void operationPutByIdDirectStrict(ExecState*, EncodedJSValue encodedValue, EncodedJSValue encodedBase, Identifier*);
97 void operationPutByIdDirectNonStrict(ExecState*, EncodedJSValue encodedValue, EncodedJSValue encodedBase, Identifier*);
98 void operationPutByIdStrictOptimize(ExecState*, EncodedJSValue encodedValue, EncodedJSValue encodedBase, Identifier*);
99 void operationPutByIdNonStrictOptimize(ExecState*, EncodedJSValue encodedValue, EncodedJSValue encodedBase, Identifier*);
100 void operationPutByIdDirectStrictOptimize(ExecState*, EncodedJSValue encodedValue, EncodedJSValue encodedBase, Identifier*);
101 void operationPutByIdDirectNonStrictOptimize(ExecState*, EncodedJSValue encodedValue, EncodedJSValue encodedBase, Identifier*);
102 RegisterSizedBoolean operationCompareLess(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
103 RegisterSizedBoolean operationCompareLessEq(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
104 RegisterSizedBoolean operationCompareGreater(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
105 RegisterSizedBoolean operationCompareGreaterEq(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
106 RegisterSizedBoolean operationCompareEq(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
107 RegisterSizedBoolean operationCompareStrictEqCell(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
108 RegisterSizedBoolean operationCompareStrictEq(ExecState*, EncodedJSValue encodedOp1, EncodedJSValue encodedOp2);
109 void* operationVirtualCall(ExecState*);
110 void* operationLinkCall(ExecState*);
111 void* operationVirtualConstruct(ExecState*);
112 void* operationLinkConstruct(ExecState*);
113
114 // This method is used to lookup an exception hander, keyed by faultLocation, which is
115 // the return location from one of the calls out to one of the helper operations above.
116 struct DFGHandler {
117     DFGHandler(ExecState* exec, void* handler)
118         : exec(exec)
119         , handler(handler)
120     {
121     }
122
123     ExecState* exec;
124     void* handler;
125 };
126 DFGHandler lookupExceptionHandler(ExecState*, ReturnAddressPtr faultLocation);
127
128 // These operations implement the implicitly called ToInt32, ToNumber, and ToBoolean conversions from ES5.
129 double dfgConvertJSValueToNumber(ExecState*, EncodedJSValue);
130 int32_t dfgConvertJSValueToInt32(ExecState*, EncodedJSValue);
131 RegisterSizedBoolean dfgConvertJSValueToBoolean(ExecState*, EncodedJSValue);
132
133 #if ENABLE(DFG_VERBOSE_SPECULATION_FAILURE)
134 void debugOperationPrintSpeculationFailure(ExecState*, void*);
135 #endif
136
137 } // extern "C"
138 } } // namespace JSC::DFG
139
140 #endif
141 #endif