OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_BUILTINS_H_ | 5 #ifndef V8_BUILTINS_H_ |
6 #define V8_BUILTINS_H_ | 6 #define V8_BUILTINS_H_ |
7 | 7 |
8 #include "src/handles.h" | 8 #include "src/handles.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 V(LoadIC_Normal_Strong, LOAD_IC) \ | 142 V(LoadIC_Normal_Strong, LOAD_IC) \ |
143 V(StoreIC_Normal, STORE_IC) | 143 V(StoreIC_Normal, STORE_IC) |
144 | 144 |
145 // Define list of builtins used by the debugger implemented in assembly. | 145 // Define list of builtins used by the debugger implemented in assembly. |
146 #define BUILTIN_LIST_DEBUG_A(V) \ | 146 #define BUILTIN_LIST_DEBUG_A(V) \ |
147 V(Return_DebugBreak, BUILTIN, DEBUG_STUB, kNoExtraICState) \ | 147 V(Return_DebugBreak, BUILTIN, DEBUG_STUB, kNoExtraICState) \ |
148 V(Slot_DebugBreak, BUILTIN, DEBUG_STUB, kNoExtraICState) \ | 148 V(Slot_DebugBreak, BUILTIN, DEBUG_STUB, kNoExtraICState) \ |
149 V(PlainReturn_LiveEdit, BUILTIN, DEBUG_STUB, kNoExtraICState) \ | 149 V(PlainReturn_LiveEdit, BUILTIN, DEBUG_STUB, kNoExtraICState) \ |
150 V(FrameDropper_LiveEdit, BUILTIN, DEBUG_STUB, kNoExtraICState) | 150 V(FrameDropper_LiveEdit, BUILTIN, DEBUG_STUB, kNoExtraICState) |
151 | 151 |
152 // Define list of builtins implemented in JavaScript. | |
153 #define BUILTINS_LIST_JS(V) \ | |
154 V(EQUALS, 1) \ | |
155 V(COMPARE, 2) \ | |
156 V(COMPARE_STRONG, 2) \ | |
157 V(ADD, 1) \ | |
158 V(ADD_STRONG, 1) \ | |
159 V(SUB, 1) \ | |
160 V(SUB_STRONG, 1) \ | |
161 V(MUL, 1) \ | |
162 V(MUL_STRONG, 1) \ | |
163 V(DIV, 1) \ | |
164 V(DIV_STRONG, 1) \ | |
165 V(MOD, 1) \ | |
166 V(MOD_STRONG, 1) \ | |
167 V(BIT_OR, 1) \ | |
168 V(BIT_OR_STRONG, 1) \ | |
169 V(BIT_AND, 1) \ | |
170 V(BIT_AND_STRONG, 1) \ | |
171 V(BIT_XOR, 1) \ | |
172 V(BIT_XOR_STRONG, 1) \ | |
173 V(SHL, 1) \ | |
174 V(SHL_STRONG, 1) \ | |
175 V(SAR, 1) \ | |
176 V(SAR_STRONG, 1) \ | |
177 V(SHR, 1) \ | |
178 V(SHR_STRONG, 1) \ | |
179 V(IN, 1) \ | |
180 V(CALL_NON_FUNCTION, 0) \ | |
181 V(CALL_NON_FUNCTION_AS_CONSTRUCTOR, 0) \ | |
182 V(CALL_FUNCTION_PROXY, 1) \ | |
183 V(CALL_FUNCTION_PROXY_AS_CONSTRUCTOR, 1) \ | |
184 V(TO_NUMBER, 0) \ | |
185 V(TO_STRING, 0) \ | |
186 V(TO_NAME, 0) \ | |
187 V(STRING_ADD_LEFT, 1) \ | |
188 V(STRING_ADD_RIGHT, 1) \ | |
189 V(APPLY_PREPARE, 1) \ | |
190 V(REFLECT_APPLY_PREPARE, 1) \ | |
191 V(REFLECT_CONSTRUCT_PREPARE, 2) \ | |
192 V(CONCAT_ITERABLE_TO_ARRAY, 1) \ | |
193 V(STACK_OVERFLOW, 1) | |
194 | 152 |
195 class BuiltinFunctionTable; | 153 class BuiltinFunctionTable; |
196 class ObjectVisitor; | 154 class ObjectVisitor; |
197 | 155 |
198 | 156 |
199 class Builtins { | 157 class Builtins { |
200 public: | 158 public: |
201 ~Builtins(); | 159 ~Builtins(); |
202 | 160 |
203 // Generate all builtin code objects. Should be called once during | 161 // Generate all builtin code objects. Should be called once during |
(...skipping 20 matching lines...) Expand all Loading... |
224 builtin_count | 182 builtin_count |
225 }; | 183 }; |
226 | 184 |
227 enum CFunctionId { | 185 enum CFunctionId { |
228 #define DEF_ENUM_C(name, ignore) c_##name, | 186 #define DEF_ENUM_C(name, ignore) c_##name, |
229 BUILTIN_LIST_C(DEF_ENUM_C) | 187 BUILTIN_LIST_C(DEF_ENUM_C) |
230 #undef DEF_ENUM_C | 188 #undef DEF_ENUM_C |
231 cfunction_count | 189 cfunction_count |
232 }; | 190 }; |
233 | 191 |
234 enum JavaScript { | |
235 #define DEF_ENUM(name, ignore) name, | |
236 BUILTINS_LIST_JS(DEF_ENUM) | |
237 #undef DEF_ENUM | |
238 id_count | |
239 }; | |
240 | |
241 #define DECLARE_BUILTIN_ACCESSOR_C(name, ignore) Handle<Code> name(); | 192 #define DECLARE_BUILTIN_ACCESSOR_C(name, ignore) Handle<Code> name(); |
242 #define DECLARE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ | 193 #define DECLARE_BUILTIN_ACCESSOR_A(name, kind, state, extra) \ |
243 Handle<Code> name(); | 194 Handle<Code> name(); |
244 #define DECLARE_BUILTIN_ACCESSOR_H(name, kind) Handle<Code> name(); | 195 #define DECLARE_BUILTIN_ACCESSOR_H(name, kind) Handle<Code> name(); |
245 BUILTIN_LIST_C(DECLARE_BUILTIN_ACCESSOR_C) | 196 BUILTIN_LIST_C(DECLARE_BUILTIN_ACCESSOR_C) |
246 BUILTIN_LIST_A(DECLARE_BUILTIN_ACCESSOR_A) | 197 BUILTIN_LIST_A(DECLARE_BUILTIN_ACCESSOR_A) |
247 BUILTIN_LIST_H(DECLARE_BUILTIN_ACCESSOR_H) | 198 BUILTIN_LIST_H(DECLARE_BUILTIN_ACCESSOR_H) |
248 BUILTIN_LIST_DEBUG_A(DECLARE_BUILTIN_ACCESSOR_A) | 199 BUILTIN_LIST_DEBUG_A(DECLARE_BUILTIN_ACCESSOR_A) |
249 #undef DECLARE_BUILTIN_ACCESSOR_C | 200 #undef DECLARE_BUILTIN_ACCESSOR_C |
250 #undef DECLARE_BUILTIN_ACCESSOR_A | 201 #undef DECLARE_BUILTIN_ACCESSOR_A |
251 | 202 |
252 Code* builtin(Name name) { | 203 Code* builtin(Name name) { |
253 // Code::cast cannot be used here since we access builtins | 204 // Code::cast cannot be used here since we access builtins |
254 // during the marking phase of mark sweep. See IC::Clear. | 205 // during the marking phase of mark sweep. See IC::Clear. |
255 return reinterpret_cast<Code*>(builtins_[name]); | 206 return reinterpret_cast<Code*>(builtins_[name]); |
256 } | 207 } |
257 | 208 |
258 Address builtin_address(Name name) { | 209 Address builtin_address(Name name) { |
259 return reinterpret_cast<Address>(&builtins_[name]); | 210 return reinterpret_cast<Address>(&builtins_[name]); |
260 } | 211 } |
261 | 212 |
262 static Address c_function_address(CFunctionId id) { | 213 static Address c_function_address(CFunctionId id) { |
263 return c_functions_[id]; | 214 return c_functions_[id]; |
264 } | 215 } |
265 | 216 |
266 static const char* GetName(JavaScript id) { return javascript_names_[id]; } | |
267 const char* name(int index) { | 217 const char* name(int index) { |
268 DCHECK(index >= 0); | 218 DCHECK(index >= 0); |
269 DCHECK(index < builtin_count); | 219 DCHECK(index < builtin_count); |
270 return names_[index]; | 220 return names_[index]; |
271 } | 221 } |
272 static int GetArgumentsCount(JavaScript id) { return javascript_argc_[id]; } | |
273 static int NumberOfJavaScriptBuiltins() { return id_count; } | |
274 | 222 |
275 bool is_initialized() const { return initialized_; } | 223 bool is_initialized() const { return initialized_; } |
276 | 224 |
277 MUST_USE_RESULT static MaybeHandle<Object> InvokeApiFunction( | 225 MUST_USE_RESULT static MaybeHandle<Object> InvokeApiFunction( |
278 Handle<JSFunction> function, Handle<Object> receiver, int argc, | 226 Handle<JSFunction> function, Handle<Object> receiver, int argc, |
279 Handle<Object> args[]); | 227 Handle<Object> args[]); |
280 | 228 |
281 private: | 229 private: |
282 Builtins(); | 230 Builtins(); |
283 | 231 |
284 // The external C++ functions called from the code. | 232 // The external C++ functions called from the code. |
285 static Address const c_functions_[cfunction_count]; | 233 static Address const c_functions_[cfunction_count]; |
286 | 234 |
287 // Note: These are always Code objects, but to conform with | 235 // Note: These are always Code objects, but to conform with |
288 // IterateBuiltins() above which assumes Object**'s for the callback | 236 // IterateBuiltins() above which assumes Object**'s for the callback |
289 // function f, we use an Object* array here. | 237 // function f, we use an Object* array here. |
290 Object* builtins_[builtin_count]; | 238 Object* builtins_[builtin_count]; |
291 const char* names_[builtin_count]; | 239 const char* names_[builtin_count]; |
292 static const char* const javascript_names_[id_count]; | |
293 static int const javascript_argc_[id_count]; | |
294 | 240 |
295 static void Generate_Adaptor(MacroAssembler* masm, | 241 static void Generate_Adaptor(MacroAssembler* masm, |
296 CFunctionId id, | 242 CFunctionId id, |
297 BuiltinExtraArguments extra_args); | 243 BuiltinExtraArguments extra_args); |
298 static void Generate_CompileLazy(MacroAssembler* masm); | 244 static void Generate_CompileLazy(MacroAssembler* masm); |
299 static void Generate_InOptimizationQueue(MacroAssembler* masm); | 245 static void Generate_InOptimizationQueue(MacroAssembler* masm); |
300 static void Generate_CompileOptimized(MacroAssembler* masm); | 246 static void Generate_CompileOptimized(MacroAssembler* masm); |
301 static void Generate_CompileOptimizedConcurrent(MacroAssembler* masm); | 247 static void Generate_CompileOptimizedConcurrent(MacroAssembler* masm); |
302 static void Generate_JSConstructStubGeneric(MacroAssembler* masm); | 248 static void Generate_JSConstructStubGeneric(MacroAssembler* masm); |
303 static void Generate_JSConstructStubForDerived(MacroAssembler* masm); | 249 static void Generate_JSConstructStubForDerived(MacroAssembler* masm); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 | 291 |
346 friend class BuiltinFunctionTable; | 292 friend class BuiltinFunctionTable; |
347 friend class Isolate; | 293 friend class Isolate; |
348 | 294 |
349 DISALLOW_COPY_AND_ASSIGN(Builtins); | 295 DISALLOW_COPY_AND_ASSIGN(Builtins); |
350 }; | 296 }; |
351 | 297 |
352 } } // namespace v8::internal | 298 } } // namespace v8::internal |
353 | 299 |
354 #endif // V8_BUILTINS_H_ | 300 #endif // V8_BUILTINS_H_ |
OLD | NEW |