initial import
[vuplus_webkit] / Source / JavaScriptCore / dfg / DFGCapabilities.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 DFGCapabilities_h
27 #define DFGCapabilities_h
28
29 #include "Interpreter.h"
30 #include <wtf/Platform.h>
31
32 namespace JSC { namespace DFG {
33
34 #if ENABLE(DFG_JIT)
35 // Fast check functions; if they return true it is still necessary to
36 // check opcodes.
37 inline bool mightCompileEval(CodeBlock*) { return true; }
38 inline bool mightCompileProgram(CodeBlock*) { return true; }
39 inline bool mightCompileFunctionForCall(CodeBlock*) { return true; }
40 inline bool mightCompileFunctionForConstruct(CodeBlock*) { return false; }
41
42 // Opcode checking.
43 inline bool canCompileOpcode(OpcodeID opcodeID)
44 {
45     switch (opcodeID) {
46     case op_enter:
47     case op_convert_this:
48     case op_bitand:
49     case op_bitor:
50     case op_bitxor:
51     case op_rshift:
52     case op_lshift:
53     case op_urshift:
54     case op_pre_inc:
55     case op_post_inc:
56     case op_pre_dec:
57     case op_post_dec:
58     case op_add:
59     case op_sub:
60     case op_mul:
61     case op_mod:
62     case op_div:
63 #if ENABLE(DEBUG_WITH_BREAKPOINT)
64     case op_debug:
65 #endif
66     case op_mov:
67     case op_check_has_instance:
68     case op_instanceof:
69     case op_not:
70     case op_less:
71     case op_lesseq:
72     case op_greater:
73     case op_greatereq:
74     case op_eq:
75     case op_eq_null:
76     case op_stricteq:
77     case op_neq:
78     case op_neq_null:
79     case op_nstricteq:
80     case op_get_by_val:
81     case op_put_by_val:
82     case op_method_check:
83     case op_get_by_id:
84     case op_put_by_id:
85     case op_get_global_var:
86     case op_put_global_var:
87     case op_jmp:
88     case op_loop:
89     case op_jtrue:
90     case op_jfalse:
91     case op_loop_if_true:
92     case op_loop_if_false:
93     case op_jeq_null:
94     case op_jneq_null:
95     case op_jless:
96     case op_jlesseq:
97     case op_jgreater:
98     case op_jgreatereq:
99     case op_jnless:
100     case op_jnlesseq:
101     case op_jngreater:
102     case op_jngreatereq:
103     case op_loop_hint:
104     case op_loop_if_less:
105     case op_loop_if_lesseq:
106     case op_loop_if_greater:
107     case op_loop_if_greatereq:
108     case op_ret:
109     case op_end:
110     case op_call:
111     case op_construct:
112     case op_call_put_result:
113     case op_resolve:
114     case op_resolve_base:
115         return true;
116     default:
117         return false;
118     }
119 }
120
121 bool canCompileOpcodes(CodeBlock*);
122 #else // ENABLE(DFG_JIT)
123 inline bool mightCompileEval(CodeBlock*) { return false; }
124 inline bool mightCompileProgram(CodeBlock*) { return false; }
125 inline bool mightCompileFunctionForCall(CodeBlock*) { return false; }
126 inline bool mightCompileFunctionForConstruct(CodeBlock*) { return false; }
127 inline bool canCompileOpcode(OpcodeID) { return false; }
128 inline bool canCompileOpcodes(CodeBlock*) { return false; }
129 #endif // ENABLE(DFG_JIT)
130
131 inline bool canCompileEval(CodeBlock* codeBlock)
132 {
133     return mightCompileEval(codeBlock) && canCompileOpcodes(codeBlock);
134 }
135
136 inline bool canCompileProgram(CodeBlock* codeBlock)
137 {
138     return mightCompileProgram(codeBlock) && canCompileOpcodes(codeBlock);
139 }
140
141 inline bool canCompileFunctionForCall(CodeBlock* codeBlock)
142 {
143     return mightCompileFunctionForCall(codeBlock) && canCompileOpcodes(codeBlock);
144 }
145
146 inline bool canCompileFunctionForConstruct(CodeBlock* codeBlock)
147 {
148     return mightCompileFunctionForConstruct(codeBlock) && canCompileOpcodes(codeBlock);
149 }
150
151 } } // namespace JSC::DFG
152
153 #endif // DFGCapabilities_h
154