OLD | NEW |
---|---|
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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_CALL_INTERFACE_DESCRIPTOR_H_ | 5 #ifndef V8_CALL_INTERFACE_DESCRIPTOR_H_ |
6 #define V8_CALL_INTERFACE_DESCRIPTOR_H_ | 6 #define V8_CALL_INTERFACE_DESCRIPTOR_H_ |
7 | 7 |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 | 10 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 V(Compare) \ | 60 V(Compare) \ |
61 V(ToBoolean) \ | 61 V(ToBoolean) \ |
62 V(BinaryOp) \ | 62 V(BinaryOp) \ |
63 V(BinaryOpWithAllocationSite) \ | 63 V(BinaryOpWithAllocationSite) \ |
64 V(StringAdd) \ | 64 V(StringAdd) \ |
65 V(StringCompare) \ | 65 V(StringCompare) \ |
66 V(Keyed) \ | 66 V(Keyed) \ |
67 V(Named) \ | 67 V(Named) \ |
68 V(CallHandler) \ | 68 V(CallHandler) \ |
69 V(ArgumentAdaptor) \ | 69 V(ArgumentAdaptor) \ |
70 V(ApiFunction) \ | 70 V(ApiCallbackWith0Args) \ |
71 V(ApiAccessor) \ | 71 V(ApiCallbackWith1Args) \ |
72 V(ApiCallbackWith2Args) \ | |
73 V(ApiCallbackWith3Args) \ | |
74 V(ApiCallbackWith4Args) \ | |
75 V(ApiCallbackWith5Args) \ | |
76 V(ApiCallbackWith6Args) \ | |
77 V(ApiCallbackWith7Args) \ | |
72 V(ApiGetter) \ | 78 V(ApiGetter) \ |
73 V(LoadGlobalViaContext) \ | 79 V(LoadGlobalViaContext) \ |
74 V(StoreGlobalViaContext) \ | 80 V(StoreGlobalViaContext) \ |
75 V(MathPowTagged) \ | 81 V(MathPowTagged) \ |
76 V(MathPowInteger) \ | 82 V(MathPowInteger) \ |
77 V(ContextOnly) \ | 83 V(ContextOnly) \ |
78 V(GrowArrayElements) \ | 84 V(GrowArrayElements) \ |
79 V(InterpreterDispatch) \ | 85 V(InterpreterDispatch) \ |
80 V(InterpreterPushArgsAndCall) \ | 86 V(InterpreterPushArgsAndCall) \ |
81 V(InterpreterPushArgsAndConstruct) \ | 87 V(InterpreterPushArgsAndConstruct) \ |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 return BuildDefaultFunctionType(isolate, register_param_count); | 198 return BuildDefaultFunctionType(isolate, register_param_count); |
193 } | 199 } |
194 | 200 |
195 virtual void InitializePlatformSpecific(CallInterfaceDescriptorData* data) { | 201 virtual void InitializePlatformSpecific(CallInterfaceDescriptorData* data) { |
196 UNREACHABLE(); | 202 UNREACHABLE(); |
197 } | 203 } |
198 | 204 |
199 void Initialize(Isolate* isolate, CallDescriptors::Key key) { | 205 void Initialize(Isolate* isolate, CallDescriptors::Key key) { |
200 if (!data()->IsInitialized()) { | 206 if (!data()->IsInitialized()) { |
201 CallInterfaceDescriptorData* d = isolate->call_descriptor_data(key); | 207 CallInterfaceDescriptorData* d = isolate->call_descriptor_data(key); |
208 DCHECK(d == data()); // d should be a modifiable pointer to data(). | |
202 InitializePlatformSpecific(d); | 209 InitializePlatformSpecific(d); |
203 FunctionType* function_type = BuildCallInterfaceDescriptorFunctionType( | 210 FunctionType* function_type = BuildCallInterfaceDescriptorFunctionType( |
204 isolate, d->register_param_count()); | 211 isolate, d->register_param_count()); |
205 d->InitializePlatformIndependent(function_type); | 212 d->InitializePlatformIndependent(function_type); |
206 } | 213 } |
207 } | 214 } |
208 | 215 |
209 private: | 216 private: |
210 const CallInterfaceDescriptorData* data_; | 217 const CallInterfaceDescriptorData* data_; |
211 }; | 218 }; |
212 | 219 |
220 #define DECLARE_DESCRIPTOR_WITH_BASE(name, base) \ | |
221 public: \ | |
222 explicit name(Isolate* isolate) : base(isolate, key()) { \ | |
223 Initialize(isolate, key()); \ | |
224 } \ | |
225 static inline CallDescriptors::Key key(); | |
213 | 226 |
214 #define DECLARE_DESCRIPTOR(name, base) \ | 227 #define DECLARE_DESCRIPTOR(name, base) \ |
215 explicit name(Isolate* isolate) : base(isolate, key()) { \ | 228 DECLARE_DESCRIPTOR_WITH_BASE(name, base) \ |
216 Initialize(isolate, key()); \ | |
217 } \ | |
218 \ | |
219 protected: \ | 229 protected: \ |
220 void InitializePlatformSpecific(CallInterfaceDescriptorData* data) override; \ | 230 void InitializePlatformSpecific(CallInterfaceDescriptorData* data) override; \ |
221 name(Isolate* isolate, CallDescriptors::Key key) : base(isolate, key) {} \ | 231 name(Isolate* isolate, CallDescriptors::Key key) : base(isolate, key) {} \ |
222 \ | 232 \ |
223 public: \ | 233 public: |
224 static inline CallDescriptors::Key key(); | |
225 | 234 |
226 #define DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(name, base) \ | 235 #define DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(name, base) \ |
227 DECLARE_DESCRIPTOR(name, base) \ | 236 DECLARE_DESCRIPTOR(name, base) \ |
228 protected: \ | 237 protected: \ |
229 FunctionType* BuildCallInterfaceDescriptorFunctionType( \ | 238 FunctionType* BuildCallInterfaceDescriptorFunctionType( \ |
230 Isolate* isolate, int register_param_count) override; \ | 239 Isolate* isolate, int register_param_count) override; \ |
231 \ | 240 \ |
232 public: | 241 public: |
233 | 242 |
234 class VoidDescriptor : public CallInterfaceDescriptor { | 243 class VoidDescriptor : public CallInterfaceDescriptor { |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 DECLARE_DESCRIPTOR(CallHandlerDescriptor, CallInterfaceDescriptor) | 691 DECLARE_DESCRIPTOR(CallHandlerDescriptor, CallInterfaceDescriptor) |
683 }; | 692 }; |
684 | 693 |
685 | 694 |
686 class ArgumentAdaptorDescriptor : public CallInterfaceDescriptor { | 695 class ArgumentAdaptorDescriptor : public CallInterfaceDescriptor { |
687 public: | 696 public: |
688 DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(ArgumentAdaptorDescriptor, | 697 DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(ArgumentAdaptorDescriptor, |
689 CallInterfaceDescriptor) | 698 CallInterfaceDescriptor) |
690 }; | 699 }; |
691 | 700 |
701 // The ApiCallback*Descriptors have a lot of boilerplate. Because | |
702 // - the macros in this file assumes a class name ends in "Descriptor", | |
703 // - the platform-specific part is independent of the number of arguments, | |
704 // - several macros assume static dispatch, | |
705 // we have a regular 'base' class, plus a templated base class for a given | |
706 // number of arguments. | |
707 // | |
708 // Neither 'base' class is meant to be instantiated directly, and neither | |
709 // has public constructors to ensure this is so. | |
710 // | |
711 // The simplest usage for all the ApiCallback*Descriptors is probably | |
712 // ApiCallbackDescriptorBase::ForArgs(isolate, argc) | |
713 class ApiCallbackDescriptorBase : public CallInterfaceDescriptor { | |
714 public: | |
715 static CallInterfaceDescriptor ForArgs(Isolate* isolate, int argc); | |
692 | 716 |
693 class ApiFunctionDescriptor : public CallInterfaceDescriptor { | 717 protected: |
718 void InitializePlatformSpecific(CallInterfaceDescriptorData* data) override; | |
719 ApiCallbackDescriptorBase(Isolate* isolate, CallDescriptors::Key key) | |
720 : CallInterfaceDescriptor(isolate, key) {} | |
721 }; | |
722 | |
723 template <int argc> | |
danno
2016/03/04 18:07:43
Is this template magic really necessary? Can you n
vogelheim
2016/03/08 12:59:27
Removed, and replaced with DECLARE_DESCRIPTOR_WITH
| |
724 class ApiCallbackWithArgsBase : public ApiCallbackDescriptorBase { | |
725 protected: | |
726 ApiCallbackWithArgsBase(Isolate* isolate, CallDescriptors::Key key) | |
727 : ApiCallbackDescriptorBase(isolate, key) {} | |
728 FunctionType* BuildCallInterfaceDescriptorFunctionType( | |
729 Isolate* isolate, int register_param_count) override; | |
730 }; | |
731 | |
732 class ApiCallbackWith0ArgsDescriptor : public ApiCallbackWithArgsBase<0> { | |
694 public: | 733 public: |
695 DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(ApiFunctionDescriptor, | 734 DECLARE_DESCRIPTOR_WITH_BASE(ApiCallbackWith0ArgsDescriptor, |
696 CallInterfaceDescriptor) | 735 ApiCallbackWithArgsBase<0>) |
736 }; | |
737 | |
738 class ApiCallbackWith1ArgsDescriptor : public ApiCallbackWithArgsBase<1> { | |
739 public: | |
740 DECLARE_DESCRIPTOR_WITH_BASE(ApiCallbackWith1ArgsDescriptor, | |
741 ApiCallbackWithArgsBase<1>) | |
742 }; | |
743 | |
744 class ApiCallbackWith2ArgsDescriptor : public ApiCallbackWithArgsBase<2> { | |
745 public: | |
746 DECLARE_DESCRIPTOR_WITH_BASE(ApiCallbackWith2ArgsDescriptor, | |
747 ApiCallbackWithArgsBase<2>) | |
748 }; | |
749 | |
750 class ApiCallbackWith3ArgsDescriptor : public ApiCallbackWithArgsBase<3> { | |
751 public: | |
752 DECLARE_DESCRIPTOR_WITH_BASE(ApiCallbackWith3ArgsDescriptor, | |
753 ApiCallbackWithArgsBase<3>) | |
754 }; | |
755 | |
756 class ApiCallbackWith4ArgsDescriptor : public ApiCallbackWithArgsBase<4> { | |
757 public: | |
758 DECLARE_DESCRIPTOR_WITH_BASE(ApiCallbackWith4ArgsDescriptor, | |
759 ApiCallbackWithArgsBase<4>) | |
760 }; | |
761 | |
762 class ApiCallbackWith5ArgsDescriptor : public ApiCallbackWithArgsBase<5> { | |
763 public: | |
764 DECLARE_DESCRIPTOR_WITH_BASE(ApiCallbackWith5ArgsDescriptor, | |
765 ApiCallbackWithArgsBase<5>) | |
766 }; | |
767 | |
768 class ApiCallbackWith6ArgsDescriptor : public ApiCallbackWithArgsBase<6> { | |
769 public: | |
770 DECLARE_DESCRIPTOR_WITH_BASE(ApiCallbackWith6ArgsDescriptor, | |
771 ApiCallbackWithArgsBase<6>) | |
772 }; | |
773 | |
774 class ApiCallbackWith7ArgsDescriptor : public ApiCallbackWithArgsBase<7> { | |
775 public: | |
776 DECLARE_DESCRIPTOR_WITH_BASE(ApiCallbackWith7ArgsDescriptor, | |
777 ApiCallbackWithArgsBase<7>) | |
697 }; | 778 }; |
698 | 779 |
699 | 780 |
700 class ApiAccessorDescriptor : public CallInterfaceDescriptor { | |
701 public: | |
702 DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(ApiAccessorDescriptor, | |
703 CallInterfaceDescriptor) | |
704 }; | |
705 | |
706 | |
707 class ApiGetterDescriptor : public CallInterfaceDescriptor { | 781 class ApiGetterDescriptor : public CallInterfaceDescriptor { |
708 public: | 782 public: |
709 DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(ApiGetterDescriptor, | 783 DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(ApiGetterDescriptor, |
710 CallInterfaceDescriptor) | 784 CallInterfaceDescriptor) |
711 | 785 |
712 static const Register function_address(); | 786 static const Register function_address(); |
713 }; | 787 }; |
714 | 788 |
715 | 789 |
716 class MathPowTaggedDescriptor : public CallInterfaceDescriptor { | 790 class MathPowTaggedDescriptor : public CallInterfaceDescriptor { |
(...skipping 20 matching lines...) Expand all Loading... | |
737 | 811 |
738 class GrowArrayElementsDescriptor : public CallInterfaceDescriptor { | 812 class GrowArrayElementsDescriptor : public CallInterfaceDescriptor { |
739 public: | 813 public: |
740 DECLARE_DESCRIPTOR(GrowArrayElementsDescriptor, CallInterfaceDescriptor) | 814 DECLARE_DESCRIPTOR(GrowArrayElementsDescriptor, CallInterfaceDescriptor) |
741 | 815 |
742 enum RegisterInfo { kObjectIndex, kKeyIndex }; | 816 enum RegisterInfo { kObjectIndex, kKeyIndex }; |
743 static const Register ObjectRegister(); | 817 static const Register ObjectRegister(); |
744 static const Register KeyRegister(); | 818 static const Register KeyRegister(); |
745 }; | 819 }; |
746 | 820 |
747 class InterpreterDispatchDescriptor : public CallInterfaceDescriptor { | 821 class InterpreterDispatchDescriptor : public CallInterfaceDescriptor { |
748 public: | 822 public: |
749 DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(InterpreterDispatchDescriptor, | 823 DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(InterpreterDispatchDescriptor, |
750 CallInterfaceDescriptor) | 824 CallInterfaceDescriptor) |
751 | 825 |
752 static const int kAccumulatorParameter = 0; | 826 static const int kAccumulatorParameter = 0; |
753 static const int kRegisterFileParameter = 1; | 827 static const int kRegisterFileParameter = 1; |
754 static const int kBytecodeOffsetParameter = 2; | 828 static const int kBytecodeOffsetParameter = 2; |
755 static const int kBytecodeArrayParameter = 3; | 829 static const int kBytecodeArrayParameter = 3; |
756 static const int kDispatchTableParameter = 4; | 830 static const int kDispatchTableParameter = 4; |
757 static const int kContextParameter = 5; | 831 static const int kContextParameter = 5; |
(...skipping 12 matching lines...) Expand all Loading... | |
770 DECLARE_DESCRIPTOR(InterpreterPushArgsAndConstructDescriptor, | 844 DECLARE_DESCRIPTOR(InterpreterPushArgsAndConstructDescriptor, |
771 CallInterfaceDescriptor) | 845 CallInterfaceDescriptor) |
772 }; | 846 }; |
773 | 847 |
774 | 848 |
775 class InterpreterCEntryDescriptor : public CallInterfaceDescriptor { | 849 class InterpreterCEntryDescriptor : public CallInterfaceDescriptor { |
776 public: | 850 public: |
777 DECLARE_DESCRIPTOR(InterpreterCEntryDescriptor, CallInterfaceDescriptor) | 851 DECLARE_DESCRIPTOR(InterpreterCEntryDescriptor, CallInterfaceDescriptor) |
778 }; | 852 }; |
779 | 853 |
854 #undef DECLARE_DESCRIPTOR_WITH_BASE | |
780 #undef DECLARE_DESCRIPTOR | 855 #undef DECLARE_DESCRIPTOR |
781 | 856 #undef DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE |
782 | 857 |
783 // We define the association between CallDescriptors::Key and the specialized | 858 // We define the association between CallDescriptors::Key and the specialized |
784 // descriptor here to reduce boilerplate and mistakes. | 859 // descriptor here to reduce boilerplate and mistakes. |
785 #define DEF_KEY(name) \ | 860 #define DEF_KEY(name) \ |
786 CallDescriptors::Key name##Descriptor::key() { return CallDescriptors::name; } | 861 CallDescriptors::Key name##Descriptor::key() { return CallDescriptors::name; } |
787 INTERFACE_DESCRIPTOR_LIST(DEF_KEY) | 862 INTERFACE_DESCRIPTOR_LIST(DEF_KEY) |
788 #undef DEF_KEY | 863 #undef DEF_KEY |
789 } // namespace internal | 864 } // namespace internal |
790 } // namespace v8 | 865 } // namespace v8 |
791 | 866 |
792 | 867 |
793 #if V8_TARGET_ARCH_ARM64 | 868 #if V8_TARGET_ARCH_ARM64 |
794 #include "src/arm64/interface-descriptors-arm64.h" | 869 #include "src/arm64/interface-descriptors-arm64.h" |
795 #elif V8_TARGET_ARCH_ARM | 870 #elif V8_TARGET_ARCH_ARM |
796 #include "src/arm/interface-descriptors-arm.h" | 871 #include "src/arm/interface-descriptors-arm.h" |
797 #endif | 872 #endif |
798 | 873 |
799 #endif // V8_CALL_INTERFACE_DESCRIPTOR_H_ | 874 #endif // V8_CALL_INTERFACE_DESCRIPTOR_H_ |
OLD | NEW |