OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #include "src/builtins/builtins.h" | 5 #include "src/builtins/builtins.h" |
6 | 6 |
7 #include "src/api-arguments.h" | 7 #include "src/api-arguments.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/api.h" | 9 #include "src/api.h" |
10 #include "src/base/ieee754.h" | 10 #include "src/base/ieee754.h" |
(...skipping 6309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6320 | 6320 |
6321 } // namespace | 6321 } // namespace |
6322 | 6322 |
6323 Builtins::Builtins() : initialized_(false) { | 6323 Builtins::Builtins() : initialized_(false) { |
6324 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); | 6324 memset(builtins_, 0, sizeof(builtins_[0]) * builtin_count); |
6325 memset(names_, 0, sizeof(names_[0]) * builtin_count); | 6325 memset(names_, 0, sizeof(names_[0]) * builtin_count); |
6326 } | 6326 } |
6327 | 6327 |
6328 Builtins::~Builtins() {} | 6328 Builtins::~Builtins() {} |
6329 | 6329 |
6330 #define DEF_ENUM_C(name, ignore) FUNCTION_ADDR(Builtin_##name), | 6330 #define DEF_ENUM_C(name) FUNCTION_ADDR(Builtin_##name), |
6331 Address const Builtins::c_functions_[cfunction_count] = { | 6331 Address const Builtins::c_functions_[cfunction_count] = { |
6332 BUILTIN_LIST_C(DEF_ENUM_C)}; | 6332 BUILTIN_LIST_C(DEF_ENUM_C)}; |
6333 #undef DEF_ENUM_C | 6333 #undef DEF_ENUM_C |
6334 | 6334 |
6335 struct BuiltinDesc { | 6335 struct BuiltinDesc { |
6336 Handle<Code> (*builder)(Isolate*, struct BuiltinDesc const*); | 6336 Handle<Code> (*builder)(Isolate*, struct BuiltinDesc const*); |
6337 byte* generator; | 6337 byte* generator; |
6338 byte* c_code; | 6338 byte* c_code; |
6339 const char* s_name; // name is only used for generating log information. | 6339 const char* s_name; // name is only used for generating log information. |
6340 int name; | 6340 int name; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6443 BuiltinDesc* functions = builtin_function_table.functions_; | 6443 BuiltinDesc* functions = builtin_function_table.functions_; |
6444 functions[builtin_count].builder = nullptr; | 6444 functions[builtin_count].builder = nullptr; |
6445 functions[builtin_count].generator = nullptr; | 6445 functions[builtin_count].generator = nullptr; |
6446 functions[builtin_count].c_code = nullptr; | 6446 functions[builtin_count].c_code = nullptr; |
6447 functions[builtin_count].s_name = nullptr; | 6447 functions[builtin_count].s_name = nullptr; |
6448 functions[builtin_count].name = builtin_count; | 6448 functions[builtin_count].name = builtin_count; |
6449 functions[builtin_count].flags = static_cast<Code::Flags>(0); | 6449 functions[builtin_count].flags = static_cast<Code::Flags>(0); |
6450 functions[builtin_count].exit_frame_type = EXIT; | 6450 functions[builtin_count].exit_frame_type = EXIT; |
6451 functions[builtin_count].argc = 0; | 6451 functions[builtin_count].argc = 0; |
6452 | 6452 |
6453 #define DEF_FUNCTION_PTR_C(aname, aexit_frame_type) \ | 6453 #define DEF_CPP(Name) \ |
6454 functions->builder = &MacroAssemblerBuilder; \ | 6454 functions->builder = &MacroAssemblerBuilder; \ |
6455 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ | 6455 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ |
6456 functions->c_code = FUNCTION_ADDR(Builtin_##aname); \ | 6456 functions->c_code = FUNCTION_ADDR(Builtin_##Name); \ |
6457 functions->s_name = #aname; \ | 6457 functions->s_name = #Name; \ |
6458 functions->name = c_##aname; \ | 6458 functions->name = c_##Name; \ |
6459 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ | 6459 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
6460 functions->exit_frame_type = aexit_frame_type; \ | 6460 functions->exit_frame_type = BUILTIN_EXIT; \ |
6461 functions->argc = 0; \ | 6461 functions->argc = 0; \ |
6462 ++functions; | 6462 ++functions; |
6463 | 6463 |
6464 #define DEF_FUNCTION_PTR_A(aname, kind, extra) \ | 6464 #define DEF_API(Name) \ |
| 6465 functions->builder = &MacroAssemblerBuilder; \ |
| 6466 functions->generator = FUNCTION_ADDR(Generate_Adaptor); \ |
| 6467 functions->c_code = FUNCTION_ADDR(Builtin_##Name); \ |
| 6468 functions->s_name = #Name; \ |
| 6469 functions->name = c_##Name; \ |
| 6470 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
| 6471 functions->exit_frame_type = EXIT; \ |
| 6472 functions->argc = 0; \ |
| 6473 ++functions; |
| 6474 |
| 6475 #define DEF_TFJ(Name, Argc) \ |
| 6476 functions->builder = &CodeStubAssemblerBuilderJS; \ |
| 6477 functions->generator = FUNCTION_ADDR(Generate_##Name); \ |
| 6478 functions->c_code = NULL; \ |
| 6479 functions->s_name = #Name; \ |
| 6480 functions->name = k##Name; \ |
| 6481 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
| 6482 functions->exit_frame_type = EXIT; \ |
| 6483 functions->argc = Argc; \ |
| 6484 ++functions; |
| 6485 |
| 6486 #define DEF_TFS(Name, Kind, Extra, InterfaceDescriptor) \ |
| 6487 functions->builder = &CodeStubAssemblerBuilderCS; \ |
| 6488 functions->generator = FUNCTION_ADDR(Generate_##Name); \ |
| 6489 functions->c_code = NULL; \ |
| 6490 functions->s_name = #Name; \ |
| 6491 functions->name = k##Name; \ |
| 6492 functions->flags = Code::ComputeFlags(Code::Kind, Extra); \ |
| 6493 functions->exit_frame_type = EXIT; \ |
| 6494 functions->argc = CallDescriptors::InterfaceDescriptor; \ |
| 6495 ++functions; |
| 6496 |
| 6497 #define DEF_ASM(Name) \ |
| 6498 functions->builder = &MacroAssemblerBuilder; \ |
| 6499 functions->generator = FUNCTION_ADDR(Generate_##Name); \ |
| 6500 functions->c_code = NULL; \ |
| 6501 functions->s_name = #Name; \ |
| 6502 functions->name = k##Name; \ |
| 6503 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ |
| 6504 functions->exit_frame_type = EXIT; \ |
| 6505 functions->argc = 0; \ |
| 6506 ++functions; |
| 6507 |
| 6508 #define DEF_ASH(Name, Kind, Extra) \ |
6465 functions->builder = &MacroAssemblerBuilder; \ | 6509 functions->builder = &MacroAssemblerBuilder; \ |
6466 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 6510 functions->generator = FUNCTION_ADDR(Generate_##Name); \ |
6467 functions->c_code = NULL; \ | 6511 functions->c_code = NULL; \ |
6468 functions->s_name = #aname; \ | 6512 functions->s_name = #Name; \ |
6469 functions->name = k##aname; \ | 6513 functions->name = k##Name; \ |
6470 functions->flags = Code::ComputeFlags(Code::kind, extra); \ | 6514 functions->flags = Code::ComputeFlags(Code::Kind, Extra); \ |
6471 functions->exit_frame_type = EXIT; \ | 6515 functions->exit_frame_type = EXIT; \ |
6472 functions->argc = 0; \ | 6516 functions->argc = 0; \ |
6473 ++functions; | 6517 ++functions; |
6474 | 6518 |
6475 #define DEF_FUNCTION_PTR_T(aname, aargc) \ | 6519 BUILTIN_LIST(DEF_CPP, DEF_API, DEF_TFJ, DEF_TFS, DEF_ASM, DEF_ASH, DEF_ASM) |
6476 functions->builder = &CodeStubAssemblerBuilderJS; \ | |
6477 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | |
6478 functions->c_code = NULL; \ | |
6479 functions->s_name = #aname; \ | |
6480 functions->name = k##aname; \ | |
6481 functions->flags = Code::ComputeFlags(Code::BUILTIN); \ | |
6482 functions->exit_frame_type = EXIT; \ | |
6483 functions->argc = aargc; \ | |
6484 ++functions; | |
6485 | 6520 |
6486 #define DEF_FUNCTION_PTR_S(aname, kind, extra, interface_descriptor) \ | 6521 #undef DEF_CPP |
6487 functions->builder = &CodeStubAssemblerBuilderCS; \ | 6522 #undef DEF_API |
6488 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | 6523 #undef DEF_TFJ |
6489 functions->c_code = NULL; \ | 6524 #undef DEF_TFS |
6490 functions->s_name = #aname; \ | 6525 #undef DEF_ASM |
6491 functions->name = k##aname; \ | 6526 #undef DEF_ASH |
6492 functions->flags = Code::ComputeFlags(Code::kind, extra); \ | |
6493 functions->exit_frame_type = EXIT; \ | |
6494 functions->argc = CallDescriptors::interface_descriptor; \ | |
6495 ++functions; | |
6496 | |
6497 #define DEF_FUNCTION_PTR_H(aname, kind) \ | |
6498 functions->builder = &MacroAssemblerBuilder; \ | |
6499 functions->generator = FUNCTION_ADDR(Generate_##aname); \ | |
6500 functions->c_code = NULL; \ | |
6501 functions->s_name = #aname; \ | |
6502 functions->name = k##aname; \ | |
6503 functions->flags = Code::ComputeHandlerFlags(Code::kind); \ | |
6504 functions->exit_frame_type = EXIT; \ | |
6505 functions->argc = 0; \ | |
6506 ++functions; | |
6507 | |
6508 BUILTIN_LIST_C(DEF_FUNCTION_PTR_C) | |
6509 BUILTIN_LIST_A(DEF_FUNCTION_PTR_A) | |
6510 BUILTIN_LIST_T(DEF_FUNCTION_PTR_T) | |
6511 BUILTIN_LIST_S(DEF_FUNCTION_PTR_S) | |
6512 BUILTIN_LIST_H(DEF_FUNCTION_PTR_H) | |
6513 BUILTIN_LIST_DEBUG_A(DEF_FUNCTION_PTR_A) | |
6514 | |
6515 #undef DEF_FUNCTION_PTR_C | |
6516 #undef DEF_FUNCTION_PTR_A | |
6517 #undef DEF_FUNCTION_PTR_T | |
6518 #undef DEF_FUNCTION_PTR_S | |
6519 #undef DEF_FUNCTION_PTR_H | |
6520 } | 6527 } |
6521 | 6528 |
6522 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { | 6529 void Builtins::SetUp(Isolate* isolate, bool create_heap_objects) { |
6523 DCHECK(!initialized_); | 6530 DCHECK(!initialized_); |
6524 | 6531 |
6525 // Create a scope for the handles in the builtins. | 6532 // Create a scope for the handles in the builtins. |
6526 HandleScope scope(isolate); | 6533 HandleScope scope(isolate); |
6527 | 6534 |
6528 #define INITIALIZE_CALL_DESCRIPTOR(name, kind, extra, interface_descriptor) \ | 6535 #define INITIALIZE_CALL_DESCRIPTOR(name, kind, extra, interface_descriptor) \ |
6529 { interface_descriptor##Descriptor descriptor(isolate); } | 6536 { interface_descriptor##Descriptor descriptor(isolate); } |
6530 BUILTIN_LIST_S(INITIALIZE_CALL_DESCRIPTOR) | 6537 BUILTIN_LIST_TFS(INITIALIZE_CALL_DESCRIPTOR) |
6531 #undef INITIALIZE_CALL_DESCRIPTOR | 6538 #undef INITIALIZE_CALL_DESCRIPTOR |
6532 | 6539 |
6533 const BuiltinDesc* functions = builtin_function_table.functions(); | 6540 const BuiltinDesc* functions = builtin_function_table.functions(); |
6534 | 6541 |
6535 // Traverse the list of builtins and generate an adaptor in a | 6542 // Traverse the list of builtins and generate an adaptor in a |
6536 // separate code object for each one. | 6543 // separate code object for each one. |
6537 for (int i = 0; i < builtin_count; i++) { | 6544 for (int i = 0; i < builtin_count; i++) { |
6538 if (create_heap_objects) { | 6545 if (create_heap_objects) { |
6539 Handle<Code> code = (*functions[i].builder)(isolate, functions + i); | 6546 Handle<Code> code = (*functions[i].builder)(isolate, functions + i); |
6540 // Log the event and add the code to the builtins array. | 6547 // Log the event and add the code to the builtins array. |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6820 a->Bind(&u32); | 6827 a->Bind(&u32); |
6821 a->AtomicStore(MachineRepresentation::kWord32, backing_store, | 6828 a->AtomicStore(MachineRepresentation::kWord32, backing_store, |
6822 a->WordShl(index_word, 2), value_word32); | 6829 a->WordShl(index_word, 2), value_word32); |
6823 a->Return(value_integer); | 6830 a->Return(value_integer); |
6824 | 6831 |
6825 // This shouldn't happen, we've already validated the type. | 6832 // This shouldn't happen, we've already validated the type. |
6826 a->Bind(&other); | 6833 a->Bind(&other); |
6827 a->Return(a->Int32Constant(0)); | 6834 a->Return(a->Int32Constant(0)); |
6828 } | 6835 } |
6829 | 6836 |
6830 #define DEFINE_BUILTIN_ACCESSOR_C(name, ignore) \ | 6837 #define DEFINE_BUILTIN_ACCESSOR(Name, ...) \ |
6831 Handle<Code> Builtins::name() { \ | 6838 Handle<Code> Builtins::Name() { \ |
6832 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | 6839 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##Name)); \ |
6833 return Handle<Code>(code_address); \ | 6840 return Handle<Code>(code_address); \ |
6834 } | 6841 } |
6835 #define DEFINE_BUILTIN_ACCESSOR_A(name, kind, extra) \ | 6842 BUILTIN_LIST_ALL(DEFINE_BUILTIN_ACCESSOR) |
6836 Handle<Code> Builtins::name() { \ | 6843 #undef DEFINE_BUILTIN_ACCESSOR |
6837 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | |
6838 return Handle<Code>(code_address); \ | |
6839 } | |
6840 #define DEFINE_BUILTIN_ACCESSOR_T(name, argc) \ | |
6841 Handle<Code> Builtins::name() { \ | |
6842 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | |
6843 return Handle<Code>(code_address); \ | |
6844 } | |
6845 #define DEFINE_BUILTIN_ACCESSOR_S(name, kind, extra, interface_descriptor) \ | |
6846 Handle<Code> Builtins::name() { \ | |
6847 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | |
6848 return Handle<Code>(code_address); \ | |
6849 } | |
6850 #define DEFINE_BUILTIN_ACCESSOR_H(name, kind) \ | |
6851 Handle<Code> Builtins::name() { \ | |
6852 Code** code_address = reinterpret_cast<Code**>(builtin_address(k##name)); \ | |
6853 return Handle<Code>(code_address); \ | |
6854 } | |
6855 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | |
6856 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | |
6857 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) | |
6858 BUILTIN_LIST_S(DEFINE_BUILTIN_ACCESSOR_S) | |
6859 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | |
6860 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | |
6861 #undef DEFINE_BUILTIN_ACCESSOR_C | |
6862 #undef DEFINE_BUILTIN_ACCESSOR_A | |
6863 #undef DEFINE_BUILTIN_ACCESSOR_T | |
6864 #undef DEFINE_BUILTIN_ACCESSOR_S | |
6865 #undef DEFINE_BUILTIN_ACCESSOR_H | |
6866 | 6844 |
6867 } // namespace internal | 6845 } // namespace internal |
6868 } // namespace v8 | 6846 } // namespace v8 |
OLD | NEW |