1 // Copyright 2015 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ 6 #define V8_INTERPRETER_INTERPRETER_INTRINSICS_H_ 7 8 #include "src/allocation.h" 9 #include "src/builtins/builtins.h" 10 #include "src/frames.h" 11 #include "src/interpreter/bytecodes.h" 12 #include "src/interpreter/interpreter-assembler.h" 13 #include "src/runtime/runtime.h" 14 15 namespace v8 { 16 namespace internal { 17 18 namespace compiler { 19 class Node; 20 } // namespace compiler 21 22 namespace interpreter { 23 24 // List of supported intrisics, with upper case name, lower case name and 25 // expected number of arguments (-1 denoting argument count is variable). 26 #define INTRINSICS_LIST(V) \ 27 V(Call, call, -1) \ 28 V(ClassOf, class_of, 1) \ 29 V(CreateIterResultObject, create_iter_result_object, 2) \ 30 V(CreateAsyncFromSyncIterator, create_async_from_sync_iterator, 1) \ 31 V(HasProperty, has_property, 2) \ 32 V(IsArray, is_array, 1) \ 33 V(IsJSProxy, is_js_proxy, 1) \ 34 V(IsJSReceiver, is_js_receiver, 1) \ 35 V(IsSmi, is_smi, 1) \ 36 V(IsTypedArray, is_typed_array, 1) \ 37 V(SubString, sub_string, 3) \ 38 V(ToString, to_string, 1) \ 39 V(ToLength, to_length, 1) \ 40 V(ToInteger, to_integer, 1) \ 41 V(ToNumber, to_number, 1) \ 42 V(ToObject, to_object, 1) 43 44 class IntrinsicsHelper { 45 public: 46 enum class IntrinsicId { 47 #define DECLARE_INTRINSIC_ID(name, lower_case, count) k##name, 48 INTRINSICS_LIST(DECLARE_INTRINSIC_ID) 49 #undef DECLARE_INTRINSIC_ID 50 kIdCount 51 }; 52 STATIC_ASSERT(static_cast<uint32_t>(IntrinsicId::kIdCount) <= kMaxUInt8); 53 54 explicit IntrinsicsHelper(InterpreterAssembler* assembler); 55 56 compiler::Node* InvokeIntrinsic(compiler::Node* function_id, 57 compiler::Node* context, 58 compiler::Node* first_arg_reg, 59 compiler::Node* arg_count); 60 61 static bool IsSupported(Runtime::FunctionId function_id); 62 static IntrinsicId FromRuntimeId(Runtime::FunctionId function_id); 63 static Runtime::FunctionId ToRuntimeId(IntrinsicId intrinsic_id); 64 65 private: 66 enum InstanceTypeCompareMode { 67 kInstanceTypeEqual, 68 kInstanceTypeGreaterThanOrEqual 69 }; 70 71 compiler::Node* IsInstanceType(compiler::Node* input, int type); 72 compiler::Node* CompareInstanceType(compiler::Node* map, int type, 73 InstanceTypeCompareMode mode); 74 compiler::Node* IntrinsicAsStubCall(compiler::Node* input, 75 compiler::Node* context, 76 Callable const& callable); 77 void AbortIfArgCountMismatch(int expected, compiler::Node* actual); 78 79 #define DECLARE_INTRINSIC_HELPER(name, lower_case, count) \ 80 compiler::Node* name(compiler::Node* input, compiler::Node* arg_count, \ 81 compiler::Node* context); INTRINSICS_LIST(DECLARE_INTRINSIC_HELPER)82 INTRINSICS_LIST(DECLARE_INTRINSIC_HELPER) 83 #undef DECLARE_INTRINSIC_HELPER 84 85 Isolate* isolate() { return isolate_; } zone()86 Zone* zone() { return zone_; } 87 88 Isolate* isolate_; 89 Zone* zone_; 90 InterpreterAssembler* assembler_; 91 92 DISALLOW_COPY_AND_ASSIGN(IntrinsicsHelper); 93 }; 94 95 } // namespace interpreter 96 } // namespace internal 97 } // namespace v8 98 99 #endif 100